Actual source code: test14.c

slepc-3.17.1 2022-04-11
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

  6:    This file is part of SLEPc.
  7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
  8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9: */

 11: static char help[] = "Test EPS interface functions.\n\n";

 13: #include <slepceps.h>

 15: int main(int argc,char **argv)
 16: {
 17:   Mat                A,B;         /* problem matrix */
 18:   EPS                eps;         /* eigenproblem solver context */
 19:   ST                 st;
 20:   KSP                ksp;
 21:   DS                 ds;
 22:   PetscReal          cut,tol;
 23:   PetscScalar        target;
 24:   PetscInt           n=20,i,its,nev,ncv,mpd,Istart,Iend;
 25:   PetscBool          flg,pur,track;
 26:   EPSConvergedReason reason;
 27:   EPSType            type;
 28:   EPSExtraction      extr;
 29:   EPSBalance         bal;
 30:   EPSWhich           which;
 31:   EPSConv            conv;
 32:   EPSStop            stop;
 33:   EPSProblemType     ptype;
 34:   PetscViewerAndFormat *vf;

 36:   SlepcInitialize(&argc,&argv,(char*)0,help);
 37:   PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%" PetscInt_FMT "\n\n",n);

 39:   MatCreate(PETSC_COMM_WORLD,&A);
 40:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
 41:   MatSetFromOptions(A);
 42:   MatSetUp(A);
 43:   MatGetOwnershipRange(A,&Istart,&Iend);
 44:   for (i=Istart;i<Iend;i++) MatSetValue(A,i,i,i+1,INSERT_VALUES);
 45:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 46:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 48:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 49:              Create eigensolver and test interface functions
 50:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 51:   EPSCreate(PETSC_COMM_WORLD,&eps);
 52:   EPSSetOperators(eps,A,NULL);
 53:   EPSGetOperators(eps,&B,NULL);
 54:   MatView(B,NULL);

 56:   EPSSetType(eps,EPSKRYLOVSCHUR);
 57:   EPSGetType(eps,&type);
 58:   PetscPrintf(PETSC_COMM_WORLD," Type set to %s\n",type);

 60:   EPSGetProblemType(eps,&ptype);
 61:   PetscPrintf(PETSC_COMM_WORLD," Problem type before changing = %d",(int)ptype);
 62:   EPSSetProblemType(eps,EPS_HEP);
 63:   EPSGetProblemType(eps,&ptype);
 64:   PetscPrintf(PETSC_COMM_WORLD," ... changed to %d.",(int)ptype);
 65:   EPSIsGeneralized(eps,&flg);
 66:   if (flg) PetscPrintf(PETSC_COMM_WORLD," generalized");
 67:   EPSIsHermitian(eps,&flg);
 68:   if (flg) PetscPrintf(PETSC_COMM_WORLD," hermitian");
 69:   EPSIsPositive(eps,&flg);
 70:   if (flg) PetscPrintf(PETSC_COMM_WORLD," positive");

 72:   EPSGetExtraction(eps,&extr);
 73:   PetscPrintf(PETSC_COMM_WORLD,"\n Extraction before changing = %d",(int)extr);
 74:   EPSSetExtraction(eps,EPS_HARMONIC);
 75:   EPSGetExtraction(eps,&extr);
 76:   PetscPrintf(PETSC_COMM_WORLD," ... changed to %d\n",(int)extr);

 78:   EPSSetBalance(eps,EPS_BALANCE_ONESIDE,8,1e-6);
 79:   EPSGetBalance(eps,&bal,&its,&cut);
 80:   PetscPrintf(PETSC_COMM_WORLD," Balance: %s, its=%" PetscInt_FMT ", cutoff=%g\n",EPSBalanceTypes[bal],its,(double)cut);

 82:   EPSSetPurify(eps,PETSC_FALSE);
 83:   EPSGetPurify(eps,&pur);
 84:   PetscPrintf(PETSC_COMM_WORLD," Eigenvector purification: %s\n",pur?"on":"off");
 85:   EPSGetTrackAll(eps,&track);

 87:   EPSSetTarget(eps,4.8);
 88:   EPSGetTarget(eps,&target);
 89:   EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE);
 90:   EPSGetWhichEigenpairs(eps,&which);
 91:   PetscPrintf(PETSC_COMM_WORLD," Which = %d, target = %g\n",(int)which,(double)PetscRealPart(target));

 93:   EPSSetDimensions(eps,4,PETSC_DEFAULT,PETSC_DEFAULT);
 94:   EPSGetDimensions(eps,&nev,&ncv,&mpd);
 95:   PetscPrintf(PETSC_COMM_WORLD," Dimensions: nev=%" PetscInt_FMT ", ncv=%" PetscInt_FMT ", mpd=%" PetscInt_FMT "\n",nev,ncv,mpd);

 97:   EPSSetTolerances(eps,2.2e-4,200);
 98:   EPSGetTolerances(eps,&tol,&its);
 99:   PetscPrintf(PETSC_COMM_WORLD," Tolerance = %.5f, max_its = %" PetscInt_FMT "\n",(double)tol,its);

101:   EPSSetConvergenceTest(eps,EPS_CONV_ABS);
102:   EPSGetConvergenceTest(eps,&conv);
103:   EPSSetStoppingTest(eps,EPS_STOP_BASIC);
104:   EPSGetStoppingTest(eps,&stop);
105:   PetscPrintf(PETSC_COMM_WORLD," Convergence test = %d, stopping test = %d\n",(int)conv,(int)stop);

107:   PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_DEFAULT,&vf);
108:   EPSMonitorSet(eps,(PetscErrorCode (*)(EPS,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,void*))EPSMonitorFirst,vf,(PetscErrorCode (*)(void**))PetscViewerAndFormatDestroy);
109:   EPSMonitorCancel(eps);

111:   EPSGetST(eps,&st);
112:   STGetKSP(st,&ksp);
113:   KSPSetTolerances(ksp,1e-8,1e-35,PETSC_DEFAULT,PETSC_DEFAULT);
114:   STView(st,NULL);
115:   EPSGetDS(eps,&ds);
116:   DSView(ds,NULL);

118:   EPSSetFromOptions(eps);
119:   EPSSolve(eps);
120:   EPSGetConvergedReason(eps,&reason);
121:   EPSGetIterationNumber(eps,&its);
122:   PetscPrintf(PETSC_COMM_WORLD," Finished - converged reason = %d, its=%" PetscInt_FMT "\n",(int)reason,its);

124:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125:                     Display solution and clean up
126:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
127:   EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
128:   EPSDestroy(&eps);
129:   MatDestroy(&A);
130:   SlepcFinalize();
131:   return 0;
132: }

134: /*TEST

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/"

141: TEST*/