LCOV - code coverage report
Current view: top level - eps/tests - test4.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 48 48 100.0 %
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[] = "Test the solution of a HEP without calling EPSSetFromOptions (based on ex1.c).\n\n"
      12             :   "The command line options are:\n"
      13             :   "  -n <n>, where <n> = number of grid subdivisions = matrix dimension.\n"
      14             :   "  -type <eps_type> = eps type to test.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18          13 : int main(int argc,char **argv)
      19             : {
      20          13 :   Mat            A;           /* problem matrix */
      21          13 :   EPS            eps;         /* eigenproblem solver context */
      22          13 :   PetscReal      tol=1000*PETSC_MACHINE_EPSILON;
      23          13 :   PetscInt       n=30,i,Istart,Iend,nev;
      24          13 :   PetscBool      flg,gd2;
      25          13 :   char           epstype[30] = "krylovschur";
      26             : 
      27          13 :   PetscFunctionBeginUser;
      28          13 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      29             : 
      30          13 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      31          13 :   PetscCall(PetscOptionsGetString(NULL,NULL,"-type",epstype,sizeof(epstype),NULL));
      32          13 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%" PetscInt_FMT "\n\n",n));
      33             : 
      34             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      35             :      Compute the operator matrix that defines the eigensystem, Ax=kx
      36             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      37             : 
      38          13 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      39          13 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
      40          13 :   PetscCall(MatSetFromOptions(A));
      41             : 
      42          13 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      43         403 :   for (i=Istart;i<Iend;i++) {
      44         390 :     if (i>0) PetscCall(MatSetValue(A,i,i-1,-1.0,INSERT_VALUES));
      45         390 :     if (i<n-1) PetscCall(MatSetValue(A,i,i+1,-1.0,INSERT_VALUES));
      46         390 :     PetscCall(MatSetValue(A,i,i,2.0,INSERT_VALUES));
      47             :   }
      48          13 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      49          13 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      50             : 
      51             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      52             :                 Create the eigensolver and set various options
      53             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      54             :   /*
      55             :      Create eigensolver context
      56             :   */
      57          13 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      58             : 
      59             :   /*
      60             :      Set operators. In this case, it is a standard eigenvalue problem
      61             :   */
      62          13 :   PetscCall(EPSSetOperators(eps,A,NULL));
      63          13 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      64          13 :   PetscCall(EPSSetDimensions(eps,4,PETSC_DETERMINE,PETSC_DETERMINE));
      65          13 :   PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
      66             : 
      67             :   /*
      68             :      Set solver parameters at runtime
      69             :   */
      70          13 :   PetscCall(PetscStrcmp(epstype,"gd2",&flg));
      71          13 :   if (flg) {
      72           1 :     PetscCall(EPSSetType(eps,EPSGD));
      73           1 :     PetscCall(EPSGDSetDoubleExpansion(eps,PETSC_TRUE));
      74           1 :     PetscCall(EPSGDGetDoubleExpansion(eps,&gd2));  /* not used */
      75          12 :   } else PetscCall(EPSSetType(eps,epstype));
      76          13 :   PetscCall(PetscStrcmp(epstype,"jd",&flg));
      77          13 :   if (flg) {
      78           1 :     PetscCall(EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE));
      79           1 :     PetscCall(EPSSetTarget(eps,4.0));
      80             :   }
      81          13 :   PetscCall(PetscStrcmp(epstype,"lanczos",&flg));
      82          13 :   if (flg) PetscCall(EPSLanczosSetReorthog(eps,EPS_LANCZOS_REORTHOG_LOCAL));
      83          13 :   PetscCall(PetscObjectTypeCompareAny((PetscObject)eps,&flg,EPSRQCG,EPSLOBPCG,""));
      84          13 :   if (flg) PetscCall(EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL));
      85             : 
      86             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      87             :                       Solve the eigensystem
      88             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      89             : 
      90          13 :   PetscCall(EPSSolve(eps));
      91          13 :   PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
      92          13 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
      93             : 
      94             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      95             :                     Display solution and clean up
      96             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      97             : 
      98          13 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      99          13 :   PetscCall(EPSDestroy(&eps));
     100          13 :   PetscCall(MatDestroy(&A));
     101          13 :   PetscCall(SlepcFinalize());
     102             :   return 0;
     103             : }
     104             : 
     105             : /*TEST
     106             : 
     107             :    testset:
     108             :       filter: sed -e "s/3.95905/3.95906/"
     109             :       output_file: output/test4_1.out
     110             :       test:
     111             :          suffix: 1
     112             :          args: -type {{krylovschur subspace arnoldi lanczos gd jd gd2 lapack}}
     113             :       test:
     114             :          suffix: 1_arpack
     115             :          args: -type arpack
     116             :          requires: arpack
     117             :       test:
     118             :          suffix: 1_primme
     119             :          args: -type primme
     120             :          requires: primme
     121             :       test:
     122             :          suffix: 1_trlan
     123             :          args: -type trlan
     124             :          requires: trlan
     125             : 
     126             :    test:
     127             :       suffix: 2
     128             :       args: -type {{rqcg lobpcg}}
     129             : 
     130             : TEST*/

Generated by: LCOV version 1.14