LCOV - code coverage report
Current view: top level - eps/tutorials - ex4.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 37 41 90.2 %
Date: 2024-12-18 00:51:33 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[] = "Solves a standard eigensystem Ax=kx with the matrix loaded from a file.\n"
      12             :   "This example works for both real and complex numbers.\n\n"
      13             :   "The command line options are:\n"
      14             :   "  -file <filename>, where <filename> = matrix file in PETSc binary form.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18           2 : int main(int argc,char **argv)
      19             : {
      20           2 :   Mat            A;               /* operator matrix */
      21           2 :   EPS            eps;             /* eigenproblem solver context */
      22           2 :   EPSType        type;
      23           2 :   PetscReal      tol;
      24           2 :   PetscInt       nev,maxit,its;
      25           2 :   char           filename[PETSC_MAX_PATH_LEN];
      26           2 :   PetscViewer    viewer;
      27           2 :   PetscBool      flg,terse;
      28             : 
      29           2 :   PetscFunctionBeginUser;
      30           2 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      31             : 
      32             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      33             :         Load the operator matrix that defines the eigensystem, Ax=kx
      34             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      35             : 
      36           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nEigenproblem stored in file.\n\n"));
      37           2 :   PetscCall(PetscOptionsGetString(NULL,NULL,"-file",filename,sizeof(filename),&flg));
      38           2 :   PetscCheck(flg,PETSC_COMM_WORLD,PETSC_ERR_USER_INPUT,"Must indicate a file name with the -file option");
      39             : 
      40             : #if defined(PETSC_USE_COMPLEX)
      41           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrix from a binary file...\n"));
      42             : #else
      43             :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrix from a binary file...\n"));
      44             : #endif
      45           2 :   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
      46           2 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      47           2 :   PetscCall(MatSetFromOptions(A));
      48           2 :   PetscCall(MatLoad(A,viewer));
      49           2 :   PetscCall(PetscViewerDestroy(&viewer));
      50             : 
      51             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      52             :                 Create the eigensolver and set various options
      53             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      54             : 
      55             :   /*
      56             :      Create eigensolver context
      57             :   */
      58           2 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      59             : 
      60             :   /*
      61             :      Set operators. In this case, it is a standard eigenvalue problem
      62             :   */
      63           2 :   PetscCall(EPSSetOperators(eps,A,NULL));
      64             : 
      65             :   /*
      66             :      Set solver parameters at runtime
      67             :   */
      68           2 :   PetscCall(EPSSetFromOptions(eps));
      69             : 
      70             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      71             :                       Solve the eigensystem
      72             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      73             : 
      74           2 :   PetscCall(EPSSolve(eps));
      75           2 :   PetscCall(EPSGetIterationNumber(eps,&its));
      76           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of iterations of the method: %" PetscInt_FMT "\n",its));
      77             : 
      78             :   /*
      79             :      Optional: Get some information from the solver and display it
      80             :   */
      81           2 :   PetscCall(EPSGetType(eps,&type));
      82           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type));
      83           2 :   PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
      84           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
      85           2 :   PetscCall(EPSGetTolerances(eps,&tol,&maxit));
      86           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Stopping condition: tol=%.4g, maxit=%" PetscInt_FMT "\n",(double)tol,maxit));
      87             : 
      88             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      89             :                     Display solution and clean up
      90             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      91             : 
      92             :   /* show detailed info unless -terse option is given by user */
      93           2 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
      94           2 :   if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
      95             :   else {
      96           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
      97           0 :     PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
      98           0 :     PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
      99           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
     100             :   }
     101           2 :   PetscCall(EPSDestroy(&eps));
     102           2 :   PetscCall(MatDestroy(&A));
     103           2 :   PetscCall(SlepcFinalize());
     104             :   return 0;
     105             : }
     106             : 
     107             : /*TEST
     108             : 
     109             :    test:
     110             :       suffix: 1
     111             :       args: -file ${SLEPC_DIR}/share/slepc/datafiles/matrices/rdb200.petsc -eps_nev 4 -terse
     112             :       requires: double !complex !defined(PETSC_USE_64BIT_INDICES)
     113             : 
     114             :    testset:
     115             :       args: -file ${DATAFILESPATH}/matrices/complex/qc324.petsc -eps_type ciss -terse
     116             :       requires: double complex datafilespath !defined(PETSC_USE_64BIT_INDICES)
     117             :       test:
     118             :          suffix: ciss_1
     119             :          args: -rg_type ellipse -rg_ellipse_center -.012-.08i -rg_ellipse_radius .05
     120             :       test:
     121             :          suffix: ciss_2
     122             :          args: -rg_type interval -rg_interval_endpoints -0.062,.038,-.13,-.03 -eps_max_it 1
     123             : 
     124             : TEST*/

Generated by: LCOV version 1.14