LCOV - code coverage report
Current view: top level - pep/tests - test8.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 82 82 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 interface functions of polynomial JD.\n\n"
      12             :   "This is based on ex16.c. 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 <slepcpep.h>
      17             : 
      18           1 : int main(int argc,char **argv)
      19             : {
      20           1 :   Mat             M,C,K,A[3];      /* problem matrices */
      21           1 :   PEP             pep;             /* polynomial eigenproblem solver context */
      22           1 :   PetscInt        N,n=10,m,Istart,Iend,II,i,j,midx;
      23           1 :   PetscReal       restart,fix;
      24           1 :   PetscBool       flag,reuse;
      25           1 :   PEPJDProjection proj;
      26             : 
      27           1 :   PetscFunctionBeginUser;
      28           1 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      29             : 
      30           1 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      31           1 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
      32           1 :   if (!flag) m=n;
      33           1 :   N = n*m;
      34           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nQuadratic Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
      35             : 
      36             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      37             :      Compute the matrices that define the eigensystem, (k^2*M+k*C+K)x=0
      38             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      39             : 
      40             :   /* K is the 2-D Laplacian */
      41           1 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&K));
      42           1 :   PetscCall(MatSetSizes(K,PETSC_DECIDE,PETSC_DECIDE,N,N));
      43           1 :   PetscCall(MatSetFromOptions(K));
      44           1 :   PetscCall(MatGetOwnershipRange(K,&Istart,&Iend));
      45         145 :   for (II=Istart;II<Iend;II++) {
      46         144 :     i = II/n; j = II-i*n;
      47         144 :     if (i>0) PetscCall(MatSetValue(K,II,II-n,-1.0,INSERT_VALUES));
      48         144 :     if (i<m-1) PetscCall(MatSetValue(K,II,II+n,-1.0,INSERT_VALUES));
      49         144 :     if (j>0) PetscCall(MatSetValue(K,II,II-1,-1.0,INSERT_VALUES));
      50         144 :     if (j<n-1) PetscCall(MatSetValue(K,II,II+1,-1.0,INSERT_VALUES));
      51         144 :     PetscCall(MatSetValue(K,II,II,4.0,INSERT_VALUES));
      52             :   }
      53           1 :   PetscCall(MatAssemblyBegin(K,MAT_FINAL_ASSEMBLY));
      54           1 :   PetscCall(MatAssemblyEnd(K,MAT_FINAL_ASSEMBLY));
      55             : 
      56             :   /* C is the 1-D Laplacian on horizontal lines */
      57           1 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&C));
      58           1 :   PetscCall(MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,N,N));
      59           1 :   PetscCall(MatSetFromOptions(C));
      60           1 :   PetscCall(MatGetOwnershipRange(C,&Istart,&Iend));
      61         145 :   for (II=Istart;II<Iend;II++) {
      62         144 :     i = II/n; j = II-i*n;
      63         144 :     if (j>0) PetscCall(MatSetValue(C,II,II-1,-1.0,INSERT_VALUES));
      64         144 :     if (j<n-1) PetscCall(MatSetValue(C,II,II+1,-1.0,INSERT_VALUES));
      65         144 :     PetscCall(MatSetValue(C,II,II,2.0,INSERT_VALUES));
      66             :   }
      67           1 :   PetscCall(MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY));
      68           1 :   PetscCall(MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY));
      69             : 
      70             :   /* M is a diagonal matrix */
      71           1 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&M));
      72           1 :   PetscCall(MatSetSizes(M,PETSC_DECIDE,PETSC_DECIDE,N,N));
      73           1 :   PetscCall(MatSetFromOptions(M));
      74           1 :   PetscCall(MatGetOwnershipRange(M,&Istart,&Iend));
      75         145 :   for (II=Istart;II<Iend;II++) PetscCall(MatSetValue(M,II,II,(PetscReal)(II+1),INSERT_VALUES));
      76           1 :   PetscCall(MatAssemblyBegin(M,MAT_FINAL_ASSEMBLY));
      77           1 :   PetscCall(MatAssemblyEnd(M,MAT_FINAL_ASSEMBLY));
      78             : 
      79             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      80             :                 Create the eigensolver and set various options
      81             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      82             : 
      83           1 :   PetscCall(PEPCreate(PETSC_COMM_WORLD,&pep));
      84           1 :   A[0] = K; A[1] = C; A[2] = M;
      85           1 :   PetscCall(PEPSetOperators(pep,3,A));
      86           1 :   PetscCall(PEPSetType(pep,PEPJD));
      87             : 
      88             :   /*
      89             :      Test interface functions of JD solver
      90             :   */
      91           1 :   PetscCall(PEPJDGetRestart(pep,&restart));
      92           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Restart parameter before changing = %g",(double)restart));
      93           1 :   PetscCall(PEPJDSetRestart(pep,0.3));
      94           1 :   PetscCall(PEPJDGetRestart(pep,&restart));
      95           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %g\n",(double)restart));
      96             : 
      97           1 :   PetscCall(PEPJDGetFix(pep,&fix));
      98           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Fix parameter before changing = %g",(double)fix));
      99           1 :   PetscCall(PEPJDSetFix(pep,0.001));
     100           1 :   PetscCall(PEPJDGetFix(pep,&fix));
     101           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %g\n",(double)fix));
     102             : 
     103           1 :   PetscCall(PEPJDGetReusePreconditioner(pep,&reuse));
     104           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reuse preconditioner flag before changing = %d",(int)reuse));
     105           1 :   PetscCall(PEPJDSetReusePreconditioner(pep,PETSC_TRUE));
     106           1 :   PetscCall(PEPJDGetReusePreconditioner(pep,&reuse));
     107           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %d\n",(int)reuse));
     108             : 
     109           1 :   PetscCall(PEPJDGetProjection(pep,&proj));
     110           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Projection type before changing = %d",(int)proj));
     111           1 :   PetscCall(PEPJDSetProjection(pep,PEP_JD_PROJECTION_ORTHOGONAL));
     112           1 :   PetscCall(PEPJDGetProjection(pep,&proj));
     113           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %d\n",(int)proj));
     114             : 
     115           1 :   PetscCall(PEPJDGetMinimalityIndex(pep,&midx));
     116           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Minimality index before changing = %" PetscInt_FMT,midx));
     117           1 :   PetscCall(PEPJDSetMinimalityIndex(pep,2));
     118           1 :   PetscCall(PEPJDGetMinimalityIndex(pep,&midx));
     119           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %" PetscInt_FMT "\n",midx));
     120             : 
     121           1 :   PetscCall(PEPSetFromOptions(pep));
     122             : 
     123             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     124             :                       Solve the eigensystem
     125             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     126             : 
     127           1 :   PetscCall(PEPSolve(pep));
     128           1 :   PetscCall(PEPErrorView(pep,PEP_ERROR_BACKWARD,NULL));
     129           1 :   PetscCall(PEPDestroy(&pep));
     130           1 :   PetscCall(MatDestroy(&M));
     131           1 :   PetscCall(MatDestroy(&C));
     132           1 :   PetscCall(MatDestroy(&K));
     133           1 :   PetscCall(SlepcFinalize());
     134             :   return 0;
     135             : }
     136             : 
     137             : /*TEST
     138             : 
     139             :    test:
     140             :       args: -n 12 -pep_nev 2 -pep_ncv 21 -pep_conv_abs
     141             : 
     142             : TEST*/

Generated by: LCOV version 1.14