LCOV - code coverage report
Current view: top level - eps/tests - test28.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 57 65 87.7 %
Date: 2024-11-21 00:34:55 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : 
      11             : static char help[] = "Tests multiple calls to EPSSolve with different matrix of different size.\n\n"
      12             :   "The command line options are:\n"
      13             :   "  -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
      14             :   "  -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18          14 : int main(int argc,char **argv)
      19             : {
      20          14 :   Mat            A,B;
      21          14 :   EPS            eps;
      22          14 :   PetscInt       N,n=10,m=11,Istart,Iend,II,nev=3,i,j;
      23          14 :   PetscBool      flag,terse;
      24             : 
      25          14 :   PetscFunctionBeginUser;
      26          14 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      27          14 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      28          14 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
      29          14 :   N = n*m;
      30          14 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
      31             : 
      32             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      33             :                 Create the 2-D Laplacian with coarse mesh
      34             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      35             : 
      36          14 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      37          14 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
      38          14 :   PetscCall(MatSetFromOptions(A));
      39          14 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      40        1444 :   for (II=Istart;II<Iend;II++) {
      41        1430 :     i = II/n; j = II-i*n;
      42        1430 :     if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
      43        1430 :     if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
      44        1430 :     if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
      45        1430 :     if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
      46        1430 :     PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
      47             :   }
      48          14 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      49          14 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      50             : 
      51             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      52             :         Create the eigensolver, set options and solve the eigensystem
      53             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      54             : 
      55          14 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      56          14 :   PetscCall(EPSSetOperators(eps,A,NULL));
      57          14 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      58          14 :   PetscCall(EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL));
      59          14 :   PetscCall(EPSSetDimensions(eps,nev,PETSC_DETERMINE,PETSC_DETERMINE));
      60          14 :   PetscCall(EPSSetFromOptions(eps));
      61             : 
      62          14 :   PetscCall(EPSSolve(eps));
      63             : 
      64             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      65             :                     Display solution of first solve
      66             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      67             : 
      68          14 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
      69          14 :   if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      70             :   else {
      71           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
      72           0 :     PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
      73           0 :     PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
      74           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
      75             :   }
      76             : 
      77             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      78             :                Create the 2-D Laplacian with finer mesh
      79             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      80             : 
      81          14 :   n *= 2;
      82          14 :   m *= 2;
      83          14 :   N = n*m;
      84          14 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
      85             : 
      86          14 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
      87          14 :   PetscCall(MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N));
      88          14 :   PetscCall(MatSetFromOptions(B));
      89          14 :   PetscCall(MatGetOwnershipRange(B,&Istart,&Iend));
      90        5734 :   for (II=Istart;II<Iend;II++) {
      91        5720 :     i = II/n; j = II-i*n;
      92        5720 :     if (i>0) PetscCall(MatSetValue(B,II,II-n,-1.0,INSERT_VALUES));
      93        5720 :     if (i<m-1) PetscCall(MatSetValue(B,II,II+n,-1.0,INSERT_VALUES));
      94        5720 :     if (j>0) PetscCall(MatSetValue(B,II,II-1,-1.0,INSERT_VALUES));
      95        5720 :     if (j<n-1) PetscCall(MatSetValue(B,II,II+1,-1.0,INSERT_VALUES));
      96        5720 :     PetscCall(MatSetValue(B,II,II,4.0,INSERT_VALUES));
      97             :   }
      98          14 :   PetscCall(MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY));
      99          14 :   PetscCall(MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY));
     100             : 
     101             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     102             :        Solve again, calling EPSReset() since matrix size has changed
     103             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     104             : 
     105             :   /* PetscCall(EPSReset(eps)); */  /* not required, will be called in EPSSetOperators() */
     106          14 :   PetscCall(EPSSetOperators(eps,B,NULL));
     107          14 :   PetscCall(EPSSolve(eps));
     108             : 
     109          14 :   if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
     110             :   else {
     111           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
     112           0 :     PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
     113           0 :     PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
     114           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
     115             :   }
     116             : 
     117          14 :   PetscCall(EPSDestroy(&eps));
     118          14 :   PetscCall(MatDestroy(&A));
     119          14 :   PetscCall(MatDestroy(&B));
     120          14 :   PetscCall(SlepcFinalize());
     121             :   return 0;
     122             : }
     123             : 
     124             : /*TEST
     125             : 
     126             :    testset:
     127             :       requires: !single
     128             :       output_file: output/test28_1.out
     129             :       test:
     130             :          suffix: 1
     131             :          args: -eps_type {{krylovschur arnoldi gd rqcg lobpcg lapack}} -terse
     132             :       test:
     133             :          suffix: 1_jd
     134             :          args: -eps_type jd -vec_mdot_use_gemv 0 -terse
     135             :       test:
     136             :          suffix: 1_lanczos
     137             :          args: -eps_type lanczos -eps_lanczos_reorthog local -terse
     138             : 
     139             :    test:
     140             :       suffix: 2
     141             :       args: -eps_type {{power subspace}} -eps_target 8 -st_type sinvert -terse
     142             : 
     143             :    testset:
     144             :       args: -eps_interval 0.5,0.67 -terse
     145             :       output_file: output/test28_3.out
     146             :       test:
     147             :          suffix: 3
     148             :          args: -st_type sinvert -st_pc_type cholesky
     149             :          requires: !single
     150             :       test:
     151             :          suffix: 3_evsl
     152             :          nsize: {{1 2}}
     153             :          args: -eps_type evsl -eps_evsl_dos_method lanczos
     154             :          requires: evsl
     155             : 
     156             : TEST*/

Generated by: LCOV version 1.14