Actual source code: test14.c
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2013, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
8: SLEPc is free software: you can redistribute it and/or modify it under the
9: terms of version 3 of the GNU Lesser General Public License as published by
10: the Free Software Foundation.
12: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
13: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15: more details.
17: You should have received a copy of the GNU Lesser General Public License
18: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20: */
22: static char help[] = "Test EPS interface functions.\n\n";
24: #include <slepceps.h>
28: int main(int argc,char **argv)
29: {
30: Mat A,B; /* problem matrix */
31: EPS eps; /* eigenproblem solver context */
32: ST st;
33: IP ip;
34: DS ds;
35: PetscReal cut,tol;
36: PetscScalar target;
37: PetscInt n=20,i,its,nev,ncv,mpd,Istart,Iend;
38: PetscBool flg;
39: EPSConvergedReason reason;
40: EPSType type;
41: EPSExtraction extr;
42: EPSBalance bal;
43: EPSWhich which;
44: EPSConv conv;
45: EPSProblemType ptype;
46: PetscErrorCode ierr;
48: SlepcInitialize(&argc,&argv,(char*)0,help);
49: PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%D\n\n",n);
51: MatCreate(PETSC_COMM_WORLD,&A);
52: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
53: MatSetFromOptions(A);
54: MatSetUp(A);
55: MatGetOwnershipRange(A,&Istart,&Iend);
56: for (i=Istart;i<Iend;i++) {
57: MatSetValue(A,i,i,i+1,INSERT_VALUES);
58: }
59: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
60: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
62: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63: Create eigensolver and test interface functions
64: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
65: EPSCreate(PETSC_COMM_WORLD,&eps);
66: EPSSetOperators(eps,A,NULL);
67: EPSGetOperators(eps,&B,NULL);
68: MatView(B,NULL);
70: EPSSetType(eps,EPSKRYLOVSCHUR);
71: EPSGetType(eps,&type);
72: PetscPrintf(PETSC_COMM_WORLD," Type set to %s\n",type);
74: EPSGetProblemType(eps,&ptype);
75: PetscPrintf(PETSC_COMM_WORLD," Problem type before changing = %D",ptype);
76: EPSSetProblemType(eps,EPS_HEP);
77: EPSGetProblemType(eps,&ptype);
78: PetscPrintf(PETSC_COMM_WORLD," ... changed to %D.",ptype);
79: EPSIsGeneralized(eps,&flg);
80: if (flg) { PetscPrintf(PETSC_COMM_WORLD," generalized"); }
81: EPSIsHermitian(eps,&flg);
82: if (flg) { PetscPrintf(PETSC_COMM_WORLD," hermitian"); }
83: EPSIsPositive(eps,&flg);
84: if (flg) { PetscPrintf(PETSC_COMM_WORLD," positive"); }
86: EPSGetExtraction(eps,&extr);
87: PetscPrintf(PETSC_COMM_WORLD,"\n Extraction before changing = %D",extr);
88: EPSSetExtraction(eps,EPS_HARMONIC);
89: EPSGetExtraction(eps,&extr);
90: PetscPrintf(PETSC_COMM_WORLD," ... changed to %D\n",extr);
92: EPSSetBalance(eps,EPS_BALANCE_ONESIDE,8,1e-6);
93: EPSGetBalance(eps,&bal,&its,&cut);
94: PetscPrintf(PETSC_COMM_WORLD," Balance: %D, its=%D, cutoff=%G\n",bal,its,cut);
96: EPSSetTarget(eps,4.8);
97: EPSGetTarget(eps,&target);
98: EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE);
99: EPSGetWhichEigenpairs(eps,&which);
100: PetscPrintf(PETSC_COMM_WORLD," Which = %D, target = %G\n",which,PetscRealPart(target));
102: EPSSetDimensions(eps,4,PETSC_DEFAULT,PETSC_DEFAULT);
103: EPSGetDimensions(eps,&nev,&ncv,&mpd);
104: PetscPrintf(PETSC_COMM_WORLD," Dimensions: nev=%D, ncv=%D, mpd=%D\n",nev,ncv,mpd);
106: EPSSetTolerances(eps,0,200);
107: EPSSetTolerances(eps,2.2e-4,0);
108: EPSGetTolerances(eps,&tol,&its);
109: PetscPrintf(PETSC_COMM_WORLD," Tolerance = %.5F, max_its = %D\n",tol,its);
111: EPSSetConvergenceTest(eps,EPS_CONV_ABS);
112: EPSGetConvergenceTest(eps,&conv);
113: PetscPrintf(PETSC_COMM_WORLD," Convergence test = %D\n",conv);
115: EPSMonitorSet(eps,EPSMonitorFirst,NULL,NULL);
116: EPSMonitorCancel(eps);
118: EPSGetST(eps,&st);
119: STView(st,NULL);
120: EPSGetIP(eps,&ip);
121: IPView(ip,NULL);
122: EPSGetDS(eps,&ds);
123: DSView(ds,NULL);
125: EPSSetFromOptions(eps);
126: EPSSolve(eps);
127: EPSGetConvergedReason(eps,&reason);
128: EPSGetIterationNumber(eps,&its);
129: PetscPrintf(PETSC_COMM_WORLD," Finished - converged reason = %D, its=%D\n",reason,its);
131: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132: Display solution and clean up
133: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
134: EPSPrintSolution(eps,NULL);
135: EPSDestroy(&eps);
136: MatDestroy(&A);
137: SlepcFinalize();
138: return 0;
139: }