LCOV - code coverage report
Current view: top level - eps/tests - test26.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 40 42 95.2 %
Date: 2024-12-18 00:42:09 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[] = "Illustrates the PGNHEP problem type. "
      12             :   "Based on ex7.\n"
      13             :   "The command line options are:\n"
      14             :   "  -f1 <filename> -f2 <filename>, PETSc binary files containing A and B.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18           3 : int main(int argc,char **argv)
      19             : {
      20           3 :   EPS               eps;
      21           3 :   Mat               A,B;
      22           3 :   PetscBool         flg;
      23           3 :   PetscReal         tol=1000*PETSC_MACHINE_EPSILON;
      24           3 :   char              filename[PETSC_MAX_PATH_LEN];
      25           3 :   PetscViewer       viewer;
      26             : 
      27           3 :   PetscFunctionBeginUser;
      28           3 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      29           3 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nPGNHEP problem loaded from file\n\n"));
      30             : 
      31             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      32             :         Load the matrices that define the eigensystem, Ax=kBx
      33             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      34             : 
      35           3 :   PetscCall(PetscOptionsGetString(NULL,NULL,"-f1",filename,sizeof(filename),&flg));
      36           3 :   PetscCheck(flg,PETSC_COMM_WORLD,PETSC_ERR_USER_INPUT,"Must indicate a file name for matrix A with the -f1 option");
      37             : 
      38             : #if defined(PETSC_USE_COMPLEX)
      39             :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrices from binary files...\n"));
      40             : #else
      41           3 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrices from binary files...\n"));
      42             : #endif
      43           3 :   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
      44           3 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      45           3 :   PetscCall(MatSetFromOptions(A));
      46           3 :   PetscCall(MatLoad(A,viewer));
      47           3 :   PetscCall(PetscViewerDestroy(&viewer));
      48             : 
      49           3 :   PetscCall(PetscOptionsGetString(NULL,NULL,"-f2",filename,sizeof(filename),&flg));
      50           3 :   if (flg) {
      51           3 :     PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
      52           3 :     PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
      53           3 :     PetscCall(MatSetFromOptions(B));
      54           3 :     PetscCall(MatLoad(B,viewer));
      55           3 :     PetscCall(PetscViewerDestroy(&viewer));
      56             :   } else {
      57           0 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD," Matrix B was not provided, setting B=I\n\n"));
      58           0 :     B = NULL;
      59             :   }
      60             : 
      61             :   /* This example is intended for a matrix pair (A,B) where B is symmetric positive definite;
      62             :      If we load matrices bfw62a/bfw62b, scale both of them because bfw62b is negative definite */
      63           3 :   PetscCall(PetscStrendswith(filename,"bfw62b.petsc",&flg));
      64           3 :   if (flg) {
      65           3 :     PetscCall(MatScale(A,-1.0));
      66           3 :     PetscCall(MatScale(B,-1.0));
      67             :   }
      68             : 
      69             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      70             :                 Create the eigensolver and solve the problem
      71             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      72             : 
      73           3 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      74           3 :   PetscCall(EPSSetOperators(eps,A,B));
      75           3 :   PetscCall(EPSSetProblemType(eps,EPS_PGNHEP));
      76           3 :   PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
      77           3 :   PetscCall(EPSSetFromOptions(eps));
      78           3 :   PetscCall(EPSSolve(eps));
      79             : 
      80             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      81             :                     Display solution and clean up
      82             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      83             : 
      84           3 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      85           3 :   PetscCall(EPSDestroy(&eps));
      86           3 :   PetscCall(MatDestroy(&A));
      87           3 :   PetscCall(MatDestroy(&B));
      88           3 :   PetscCall(SlepcFinalize());
      89             :   return 0;
      90             : }
      91             : 
      92             : /*TEST
      93             : 
      94             :    testset:
      95             :       args: -f1 ${SLEPC_DIR}/share/slepc/datafiles/matrices/bfw62a.petsc -f2 ${SLEPC_DIR}/share/slepc/datafiles/matrices/bfw62b.petsc -eps_largest_real -eps_nev 4
      96             :       requires: double !complex !defined(PETSC_USE_64BIT_INDICES)
      97             :       output_file: output/test26_1.out
      98             :       test:
      99             :          args: -eps_true_residual {{0 1}}
     100             :          suffix: 1
     101             :       test:
     102             :          args: -eps_type arpack
     103             :          suffix: 1_arpack
     104             :          requires: arpack
     105             : 
     106             :    testset:
     107             :       args: -f1 ${DATAFILESPATH}/matrices/complex/mhd1280a.petsc -f2 ${DATAFILESPATH}/matrices/complex/mhd1280b.petsc -eps_smallest_real -eps_nev 4
     108             :       requires: double complex datafilespath !defined(PETSC_USE_64BIT_INDICES)
     109             :       output_file: output/test26_2.out
     110             :       test:
     111             :          suffix: 2
     112             :       test:
     113             :          args: -eps_type arpack
     114             :          suffix: 2_arpack
     115             :          requires: arpack
     116             : 
     117             : TEST*/

Generated by: LCOV version 1.14