LCOV - code coverage report
Current view: top level - eps/tests - test14.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 93 93 100.0 %
Date: 2024-05-04 00:30:31 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 EPS interface functions.\n\n";
      12             : 
      13             : #include <slepceps.h>
      14             : 
      15           1 : int main(int argc,char **argv)
      16             : {
      17           1 :   Mat                A,B;         /* problem matrix */
      18           1 :   EPS                eps;         /* eigenproblem solver context */
      19           1 :   ST                 st;
      20           1 :   KSP                ksp;
      21           1 :   DS                 ds;
      22           1 :   PetscReal          cut,tol;
      23           1 :   PetscScalar        target;
      24           1 :   PetscInt           n=20,i,its,nev,ncv,mpd,Istart,Iend;
      25           1 :   PetscBool          flg,pur,track;
      26           1 :   EPSConvergedReason reason;
      27           1 :   EPSType            type;
      28           1 :   EPSExtraction      extr;
      29           1 :   EPSBalance         bal;
      30           1 :   EPSWhich           which;
      31           1 :   EPSConv            conv;
      32           1 :   EPSStop            stop;
      33           1 :   EPSProblemType     ptype;
      34           1 :   PetscViewerAndFormat *vf;
      35             : 
      36           1 :   PetscFunctionBeginUser;
      37           1 :   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
      38           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%" PetscInt_FMT "\n\n",n));
      39             : 
      40           1 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      41           1 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
      42           1 :   PetscCall(MatSetFromOptions(A));
      43           1 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      44          21 :   for (i=Istart;i<Iend;i++) PetscCall(MatSetValue(A,i,i,i+1,INSERT_VALUES));
      45           1 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      46           1 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      47             : 
      48             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      49             :              Create eigensolver and test interface functions
      50             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      51           1 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      52           1 :   PetscCall(EPSSetOperators(eps,A,NULL));
      53           1 :   PetscCall(EPSGetOperators(eps,&B,NULL));
      54           1 :   PetscCall(MatView(B,NULL));
      55             : 
      56           1 :   PetscCall(EPSSetType(eps,EPSKRYLOVSCHUR));
      57           1 :   PetscCall(EPSGetType(eps,&type));
      58           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Type set to %s\n",type));
      59             : 
      60           1 :   PetscCall(EPSGetProblemType(eps,&ptype));
      61           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Problem type before changing = %d",(int)ptype));
      62           1 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      63           1 :   PetscCall(EPSGetProblemType(eps,&ptype));
      64           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %d.",(int)ptype));
      65           1 :   PetscCall(EPSIsGeneralized(eps,&flg));
      66           1 :   if (flg) PetscCall(PetscPrintf(PETSC_COMM_WORLD," generalized"));
      67           1 :   PetscCall(EPSIsHermitian(eps,&flg));
      68           1 :   if (flg) PetscCall(PetscPrintf(PETSC_COMM_WORLD," hermitian"));
      69           1 :   PetscCall(EPSIsPositive(eps,&flg));
      70           1 :   if (flg) PetscCall(PetscPrintf(PETSC_COMM_WORLD," positive"));
      71             : 
      72           1 :   PetscCall(EPSGetExtraction(eps,&extr));
      73           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n Extraction before changing = %d",(int)extr));
      74           1 :   PetscCall(EPSSetExtraction(eps,EPS_HARMONIC));
      75           1 :   PetscCall(EPSGetExtraction(eps,&extr));
      76           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ... changed to %d\n",(int)extr));
      77             : 
      78           1 :   PetscCall(EPSSetBalance(eps,EPS_BALANCE_ONESIDE,8,1e-6));
      79           1 :   PetscCall(EPSGetBalance(eps,&bal,&its,&cut));
      80           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Balance: %s, its=%" PetscInt_FMT ", cutoff=%g\n",EPSBalanceTypes[bal],its,(double)cut));
      81             : 
      82           1 :   PetscCall(EPSSetPurify(eps,PETSC_FALSE));
      83           1 :   PetscCall(EPSGetPurify(eps,&pur));
      84           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Eigenvector purification: %s\n",pur?"on":"off"));
      85           1 :   PetscCall(EPSGetTrackAll(eps,&track));
      86             : 
      87           1 :   PetscCall(EPSSetTarget(eps,4.8));
      88           1 :   PetscCall(EPSGetTarget(eps,&target));
      89           1 :   PetscCall(EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE));
      90           1 :   PetscCall(EPSGetWhichEigenpairs(eps,&which));
      91           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Which = %d, target = %g\n",(int)which,(double)PetscRealPart(target)));
      92             : 
      93           1 :   PetscCall(EPSSetDimensions(eps,4,PETSC_DEFAULT,PETSC_DEFAULT));
      94           1 :   PetscCall(EPSGetDimensions(eps,&nev,&ncv,&mpd));
      95           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Dimensions: nev=%" PetscInt_FMT ", ncv=%" PetscInt_FMT ", mpd=%" PetscInt_FMT "\n",nev,ncv,mpd));
      96             : 
      97           1 :   PetscCall(EPSSetTolerances(eps,2.2e-4,200));
      98           1 :   PetscCall(EPSGetTolerances(eps,&tol,&its));
      99           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Tolerance = %.5f, max_its = %" PetscInt_FMT "\n",(double)tol,its));
     100             : 
     101           1 :   PetscCall(EPSSetConvergenceTest(eps,EPS_CONV_ABS));
     102           1 :   PetscCall(EPSGetConvergenceTest(eps,&conv));
     103           1 :   PetscCall(EPSSetStoppingTest(eps,EPS_STOP_BASIC));
     104           1 :   PetscCall(EPSGetStoppingTest(eps,&stop));
     105           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Convergence test = %d, stopping test = %d\n",(int)conv,(int)stop));
     106             : 
     107           1 :   PetscCall(PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_DEFAULT,&vf));
     108           1 :   PetscCall(EPSMonitorSet(eps,(PetscErrorCode (*)(EPS,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,void*))EPSMonitorFirst,vf,(PetscErrorCode (*)(void**))PetscViewerAndFormatDestroy));
     109           1 :   PetscCall(EPSMonitorCancel(eps));
     110             : 
     111           1 :   PetscCall(EPSGetST(eps,&st));
     112           1 :   PetscCall(STGetKSP(st,&ksp));
     113           1 :   PetscCall(KSPSetTolerances(ksp,1e-8,1e-35,PETSC_DEFAULT,PETSC_DEFAULT));
     114           1 :   PetscCall(STView(st,NULL));
     115           1 :   PetscCall(EPSGetDS(eps,&ds));
     116           1 :   PetscCall(DSView(ds,NULL));
     117             : 
     118           1 :   PetscCall(EPSSetFromOptions(eps));
     119           1 :   PetscCall(EPSSolve(eps));
     120           1 :   PetscCall(EPSGetConvergedReason(eps,&reason));
     121           1 :   PetscCall(EPSGetIterationNumber(eps,&its));
     122           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Finished - converged reason = %d, its=%" PetscInt_FMT "\n",(int)reason,its));
     123             : 
     124             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     125             :                     Display solution and clean up
     126             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     127           1 :   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
     128           1 :   PetscCall(EPSDestroy(&eps));
     129           1 :   PetscCall(MatDestroy(&A));
     130           1 :   PetscCall(SlepcFinalize());
     131             :   return 0;
     132             : }
     133             : 
     134             : /*TEST
     135             : 
     136             :    test:
     137             :       suffix: 1
     138             :       args: -eps_ncv 14
     139             :       filter: sed -e "s/00001/00000/" | sed -e "s/4.99999/5.00000/" | sed -e "s/5.99999/6.00000/"
     140             : 
     141             : TEST*/

Generated by: LCOV version 1.14