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[] = "Tests multiple calls to EPSSolve with different matrix of different size.\n\n"
12 : "The command line options are:\n"
13 : " -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
14 : " -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";
15 :
16 : #include <slepceps.h>
17 :
18 11 : int main(int argc,char **argv)
19 : {
20 11 : Mat A,B;
21 11 : EPS eps;
22 11 : PetscInt N,n=10,m=11,Istart,Iend,II,nev=3,i,j;
23 11 : PetscBool flag,terse;
24 :
25 11 : PetscFunctionBeginUser;
26 11 : PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
27 11 : PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
28 11 : PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
29 11 : N = n*m;
30 11 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
31 :
32 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 : Create the 2-D Laplacian with coarse mesh
34 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
35 :
36 11 : PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
37 11 : PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
38 11 : PetscCall(MatSetFromOptions(A));
39 11 : PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
40 1221 : for (II=Istart;II<Iend;II++) {
41 1210 : i = II/n; j = II-i*n;
42 1210 : if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
43 1210 : if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
44 1210 : if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
45 1210 : if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
46 1210 : PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
47 : }
48 11 : PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
49 11 : PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
50 :
51 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 : Create the eigensolver, set options and solve the eigensystem
53 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
54 :
55 11 : PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
56 11 : PetscCall(EPSSetOperators(eps,A,NULL));
57 11 : PetscCall(EPSSetProblemType(eps,EPS_HEP));
58 11 : PetscCall(EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL));
59 11 : PetscCall(EPSSetDimensions(eps,nev,PETSC_DETERMINE,PETSC_DETERMINE));
60 11 : PetscCall(EPSSetFromOptions(eps));
61 :
62 11 : PetscCall(EPSSolve(eps));
63 :
64 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65 : Display solution of first solve
66 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
67 :
68 11 : PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
69 11 : if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
70 : else {
71 0 : PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
72 0 : PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
73 0 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
74 0 : PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
75 : }
76 :
77 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 : Create the 2-D Laplacian with finer mesh
79 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
80 :
81 11 : n *= 2;
82 11 : m *= 2;
83 11 : N = n*m;
84 11 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
85 :
86 11 : PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
87 11 : PetscCall(MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N));
88 11 : PetscCall(MatSetFromOptions(B));
89 11 : PetscCall(MatGetOwnershipRange(B,&Istart,&Iend));
90 4851 : for (II=Istart;II<Iend;II++) {
91 4840 : i = II/n; j = II-i*n;
92 4840 : if (i>0) PetscCall(MatSetValue(B,II,II-n,-1.0,INSERT_VALUES));
93 4840 : if (i<m-1) PetscCall(MatSetValue(B,II,II+n,-1.0,INSERT_VALUES));
94 4840 : if (j>0) PetscCall(MatSetValue(B,II,II-1,-1.0,INSERT_VALUES));
95 4840 : if (j<n-1) PetscCall(MatSetValue(B,II,II+1,-1.0,INSERT_VALUES));
96 4840 : PetscCall(MatSetValue(B,II,II,4.0,INSERT_VALUES));
97 : }
98 11 : PetscCall(MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY));
99 11 : PetscCall(MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY));
100 :
101 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102 : Solve again, calling EPSReset() since matrix size has changed
103 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
104 :
105 : /* PetscCall(EPSReset(eps)); */ /* not required, will be called in EPSSetOperators() */
106 11 : PetscCall(EPSSetOperators(eps,B,NULL));
107 11 : PetscCall(EPSSolve(eps));
108 :
109 11 : if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
110 : else {
111 0 : PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
112 0 : PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
113 0 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
114 0 : PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
115 : }
116 :
117 11 : PetscCall(EPSDestroy(&eps));
118 11 : PetscCall(MatDestroy(&A));
119 11 : PetscCall(MatDestroy(&B));
120 11 : PetscCall(SlepcFinalize());
121 : return 0;
122 : }
123 :
124 : /*TEST
125 :
126 : testset:
127 : requires: !single
128 : output_file: output/test28_1.out
129 : test:
130 : suffix: 1
131 : args: -eps_type {{krylovschur arnoldi gd rqcg lobpcg lapack}} -terse
132 : test:
133 : suffix: 1_jd
134 : args: -eps_type jd -vec_mdot_use_gemv 0 -terse
135 : test:
136 : suffix: 1_lanczos
137 : args: -eps_type lanczos -eps_lanczos_reorthog local -terse
138 :
139 : test:
140 : suffix: 2
141 : args: -eps_type {{power subspace}} -eps_target 8 -st_type sinvert -terse
142 :
143 : testset:
144 : args: -eps_interval 0.5,0.67 -terse
145 : output_file: output/test28_3.out
146 : test:
147 : suffix: 3
148 : args: -st_type sinvert -st_pc_type cholesky
149 : requires: !single
150 : test:
151 : suffix: 3_evsl
152 : nsize: {{1 2}}
153 : args: -eps_type evsl -eps_evsl_dos_method lanczos
154 : requires: evsl
155 :
156 : TEST*/
|