LCOV - code coverage report
Current view: top level - eps/tests - test38.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 43 47 91.5 %
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 EPSLYAPII interface functions.\n\n"
      12             :   "Based on ex2.\n"
      13             :   "The command line options are:\n"
      14             :   "  -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
      15             :   "  -m <m>, where <m> = number of grid subdivisions in y dimension.\n"
      16             :   "  -shift <sigma>, where <sigma> = shift of origin.\n\n";
      17             : 
      18             : #include <slepceps.h>
      19             : 
      20           1 : int main(int argc,char **argv)
      21             : {
      22           1 :   Mat            A;
      23           1 :   EPS            eps;
      24           1 :   PetscInt       N,n=10,m,Istart,Iend,II,i,j,rkl,rkc;
      25           1 :   PetscBool      flag,terse;
      26           1 :   PetscReal      sigma=8.0;
      27             : 
      28           1 :   PetscFunctionBeginUser;
      29           1 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      30           1 :   PetscCall(PetscOptionsGetReal(NULL,NULL,"-shift",&sigma,NULL));
      31           1 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      32           1 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
      33           1 :   if (!flag) m=n;
      34           1 :   N = n*m;
      35           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nShifted 2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid) sigma=%.1f\n\n",N,n,m,(double)sigma));
      36             : 
      37             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      38             :                     Create the 2-D Laplacian
      39             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      40             : 
      41           1 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      42           1 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
      43           1 :   PetscCall(MatSetFromOptions(A));
      44           1 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      45         101 :   for (II=Istart;II<Iend;II++) {
      46         100 :     i = II/n; j = II-i*n;
      47         100 :     if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
      48         100 :     if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
      49         100 :     if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
      50         100 :     if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
      51         100 :     PetscCall(MatSetValue(A,II,II,4.0-sigma,INSERT_VALUES));
      52             :   }
      53           1 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      54           1 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      55             : 
      56             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      57             :                 Create the eigensolver and set various options
      58             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      59             : 
      60           1 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      61           1 :   PetscCall(EPSSetOperators(eps,A,NULL));
      62           1 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      63           1 :   PetscCall(EPSSetWhichEigenpairs(eps,EPS_LARGEST_REAL));
      64           1 :   PetscCall(EPSSetType(eps,EPSLYAPII));
      65           1 :   PetscCall(EPSSetFromOptions(eps));
      66             : 
      67             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      68             :                 Solve the problem and display the solution
      69             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      70             : 
      71           1 :   PetscCall(EPSSolve(eps));
      72             : 
      73             :   /* print solver information */
      74           1 :   PetscCall(PetscObjectTypeCompare((PetscObject)eps,EPSLYAPII,&flag));
      75           1 :   if (flag) {
      76           1 :     PetscCall(EPSLyapIIGetRanks(eps,&rkc,&rkl));
      77           1 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD," EPSLYAPII ranks: for Lyapunov solver=%" PetscInt_FMT ", after compression=%" PetscInt_FMT "\n\n",rkl,rkc));
      78             :   }
      79             : 
      80           1 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
      81           1 :   if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      82             :   else {
      83           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
      84           0 :     PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
      85           0 :     PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
      86           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
      87             :   }
      88             : 
      89           1 :   PetscCall(EPSDestroy(&eps));
      90           1 :   PetscCall(MatDestroy(&A));
      91           1 :   PetscCall(SlepcFinalize());
      92             :   return 0;
      93             : }
      94             : 
      95             : /*TEST
      96             : 
      97             :    test:
      98             :       args: -eps_view -terse
      99             :       filter: grep -v tolerance | sed -e "s/symmetric/hermitian/"
     100             : 
     101             : TEST*/

Generated by: LCOV version 1.14