Actual source code: test31.c
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 STFILTER interface functions.\n\n"
12: "Based on ex2.\n"
13: "The command line options are:\n"
14: " -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
15: " -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";
17: #include <slepceps.h>
19: int main(int argc,char **argv)
20: {
21: Mat A;
22: EPS eps;
23: ST st;
24: PetscInt N,n=10,m,Istart,Iend,II,i,j,degree;
25: PetscBool flag,modify=PETSC_FALSE,chinterval=PETSC_FALSE,terse;
26: PetscReal inta,intb,rleft,rright;
27: STFilterType ftype;
28: STFilterDamping damp;
30: PetscFunctionBeginUser;
31: PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
32: PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
33: PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
34: if (!flag) m=n;
35: N = n*m;
36: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
37: PetscCall(PetscOptionsGetBool(NULL,NULL,"-modify",&modify,&flag));
38: PetscCall(PetscOptionsGetBool(NULL,NULL,"-chinterval",&chinterval,&flag));
40: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41: Create the 2-D Laplacian
42: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
44: PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
45: PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
46: PetscCall(MatSetFromOptions(A));
47: PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
48: for (II=Istart;II<Iend;II++) {
49: i = II/n; j = II-i*n;
50: if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
51: if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
52: if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
53: if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
54: PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
55: }
56: PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
57: PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
59: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60: Create the eigensolver and set various options
61: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
63: PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
64: PetscCall(EPSSetOperators(eps,A,NULL));
65: PetscCall(EPSSetProblemType(eps,EPS_HEP));
66: PetscCall(EPSSetType(eps,EPSKRYLOVSCHUR));
67: PetscCall(EPSSetWhichEigenpairs(eps,EPS_ALL));
68: PetscCall(EPSSetInterval(eps,0.5,1.3));
69: PetscCall(EPSGetST(eps,&st));
70: PetscCall(STSetType(st,STFILTER));
71: PetscCall(EPSSetFromOptions(eps));
73: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74: Solve the problem and display the solution
75: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
77: PetscCall(EPSSolve(eps));
79: /* print filter information */
80: PetscCall(PetscObjectTypeCompare((PetscObject)st,STFILTER,&flag));
81: if (flag) {
82: PetscCall(STFilterGetType(st,&ftype));
83: PetscCall(STFilterGetDegree(st,°ree));
84: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Filter type: %s, degree: %" PetscInt_FMT "\n",STFilterTypes[ftype],degree));
85: if (ftype==ST_FILTER_CHEBYSHEV) {
86: PetscCall(STFilterGetDamping(st,&damp));
87: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Damping: %s\n",STFilterDampings[damp]));
88: }
89: PetscCall(STFilterGetInterval(st,&inta,&intb));
90: PetscCall(STFilterGetRange(st,&rleft,&rright));
91: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Requested interval: [%g,%g], range: [%g,%g]\n\n",(double)inta,(double)intb,(double)rleft,(double)rright));
92: }
94: PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
95: if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
96: else {
97: PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
98: PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
99: PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
100: PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
101: }
103: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104: Solve the problem again after changing the matrix
105: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
106: if (modify) {
107: PetscCall(MatSetValue(A,0,0,0.3,INSERT_VALUES));
108: PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
109: PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
110: PetscCall(EPSSetOperators(eps,A,NULL));
111: PetscCall(EPSSolve(eps));
112: PetscCall(STFilterGetInterval(st,&inta,&intb));
113: PetscCall(STFilterGetRange(st,&rleft,&rright));
114: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Requested interval: [%g,%g], range: [%g,%g]\n\n",(double)inta,(double)intb,(double)rleft,(double)rright));
115: PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
116: if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
117: else {
118: PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
119: PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
120: PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
121: PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
122: }
123: }
125: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126: Solve the problem again after changing the interval
127: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
128: if (chinterval) {
129: PetscCall(EPSSetInterval(eps,0.7,1.2));
130: PetscCall(EPSSolve(eps));
131: PetscCall(STFilterGetInterval(st,&inta,&intb));
132: PetscCall(STFilterGetRange(st,&rleft,&rright));
133: PetscCall(PetscPrintf(PETSC_COMM_WORLD," Requested interval: [%g,%g], range: [%g,%g]\n\n",(double)inta,(double)intb,(double)rleft,(double)rright));
134: PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
135: if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
136: else {
137: PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
138: PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
139: PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
140: PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
141: }
142: }
144: PetscCall(EPSDestroy(&eps));
145: PetscCall(MatDestroy(&A));
146: PetscCall(SlepcFinalize());
147: return 0;
148: }
150: /*TEST
152: test:
153: suffix: 1
154: args: -terse
155: filter: sed -e "s/0.161982,7.83797/0.162007,7.83897/"
156: requires: !single
158: test:
159: suffix: 2
160: args: -modify -st_filter_range -0.3,8 -terse
161: requires: !single
163: test:
164: suffix: 3
165: args: -modify -terse
166: filter: sed -e "s%0\.161[0-9]*%0.162%" | sed -e "s%0\.162[0-9]*%0.162%" | sed -e "s%7\.83[0-9]*%7.83%" | sed -e "s%-0.29[0-9]*%-0.29%"
167: requires: !single
169: test:
170: suffix: 4
171: args: -terse -eps_ncv 18 -st_filter_type chebyshev -st_filter_damping {{fejer jackson}}
172: filter: sed -e "s/0.161982,7.83797/0.162007,7.83897/" | sed -e "s/CHEBYSHEV/FILTLAN/" | grep -v Damping
173: output_file: output/test31_1.out
174: requires: !single
176: test:
177: suffix: 5
178: args: -modify -terse -st_filter_range -0.3,8 -st_filter_type chebyshev -st_filter_damping {{lanczos none}}
179: filter: sed -e "s/CHEBYSHEV/FILTLAN/" | grep -v Damping
180: output_file: output/test31_2.out
181: requires: !single
183: test:
184: suffix: 6
185: args: -chinterval -eps_type {{krylovschur subspace}} -st_filter_type chebyshev -terse
186: filter: sed -e "s/CHEBYSHEV/FILTLAN/" | grep -v Damping | sed -e "s%0\.161[0-9]*%0.162%" | sed -e "s%0\.162[0-9]*%0.162%" | sed -e "s%7\.83[0-9]*%7.83%"
187: requires: double
189: TEST*/