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[] = "Standard symmetric eigenproblem corresponding to the Laplacian operator in 2 dimensions.\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 13 : int main(int argc,char **argv)
19 : {
20 13 : Mat A; /* operator matrix */
21 13 : EPS eps; /* eigenproblem solver context */
22 13 : EPSType type;
23 13 : PetscInt N,n=10,m,Istart,Iend,II,nev,i,j;
24 13 : PetscBool flag,terse;
25 :
26 13 : PetscFunctionBeginUser;
27 13 : PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
28 :
29 13 : PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
30 13 : PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
31 13 : if (!flag) m=n;
32 13 : N = n*m;
33 13 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
34 :
35 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 : Compute the operator matrix that defines the eigensystem, Ax=kx
37 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38 :
39 13 : PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
40 13 : PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
41 13 : PetscCall(MatSetFromOptions(A));
42 :
43 13 : PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
44 23161 : for (II=Istart;II<Iend;II++) {
45 23148 : i = II/n; j = II-i*n;
46 23148 : if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
47 23148 : if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
48 23148 : if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
49 23148 : if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
50 23148 : PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
51 : }
52 :
53 13 : PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
54 13 : PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
55 :
56 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 : Create the eigensolver and set various options
58 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
59 :
60 : /*
61 : Create eigensolver context
62 : */
63 13 : PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
64 :
65 : /*
66 : Set operators. In this case, it is a standard eigenvalue problem
67 : */
68 13 : PetscCall(EPSSetOperators(eps,A,NULL));
69 13 : PetscCall(EPSSetProblemType(eps,EPS_HEP));
70 :
71 : /*
72 : Set solver parameters at runtime
73 : */
74 13 : PetscCall(EPSSetFromOptions(eps));
75 :
76 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 : Solve the eigensystem
78 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
79 :
80 13 : PetscCall(EPSSolve(eps));
81 :
82 : /*
83 : Optional: Get some information from the solver and display it
84 : */
85 13 : PetscCall(EPSGetType(eps,&type));
86 13 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type));
87 13 : PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
88 13 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
89 :
90 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 : Display solution and clean up
92 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
93 :
94 : /* show detailed info unless -terse option is given by user */
95 13 : PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
96 13 : if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
97 : else {
98 0 : PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
99 0 : PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
100 0 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
101 0 : PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
102 : }
103 13 : PetscCall(EPSDestroy(&eps));
104 13 : PetscCall(MatDestroy(&A));
105 13 : PetscCall(SlepcFinalize());
106 : return 0;
107 : }
108 :
109 : /*TEST
110 :
111 : testset:
112 : args: -n 72 -eps_nev 4 -eps_ncv 20 -terse
113 : output_file: output/ex2_1.out
114 : requires: !single
115 : test:
116 : suffix: 1
117 : test:
118 : suffix: 2
119 : args: -library_preload
120 :
121 : testset:
122 : args: -n 30 -eps_type ciss -eps_ciss_realmats -terse
123 : requires: !single
124 : output_file: output/ex2_ciss.out
125 : filter: grep -v method
126 : test:
127 : suffix: ciss_1
128 : nsize: 1
129 : args: -rg_type interval -rg_interval_endpoints 1.1,1.25,-.1,.1
130 : requires: complex
131 : test:
132 : suffix: ciss_1_hpddm
133 : nsize: 1
134 : args: -rg_type interval -rg_interval_endpoints 1.1,1.25 -st_ksp_type hpddm
135 : requires: hpddm
136 : test:
137 : suffix: ciss_2
138 : nsize: 2
139 : args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2
140 : test:
141 : suffix: ciss_2_block
142 : args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_blocksize 3 -eps_ciss_moments 2
143 : requires: complex !__float128
144 : test:
145 : suffix: ciss_2_hpddm
146 : nsize: 2
147 : args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2 -eps_ciss_ksp_type hpddm
148 : requires: hpddm
149 : test:
150 : suffix: feast
151 : args: -eps_type feast -eps_interval 1.1,1.25 -eps_ncv 64 -options_left 0
152 : requires: feast
153 :
154 : testset:
155 : args: -n 30 -m 30 -eps_interval 3.9,4.15 -terse
156 : output_file: output/ex2_3.out
157 : filter: grep -v Solution
158 : requires: !single
159 : test:
160 : suffix: 3
161 : args: -st_type sinvert -st_pc_type cholesky
162 : test:
163 : suffix: 3_evsl
164 : args: -eps_type evsl -eps_evsl_slices 6
165 : requires: evsl
166 :
167 : testset:
168 : args: -n 45 -m 46 -eps_interval 4.54,4.57 -eps_ncv 24 -terse
169 : output_file: output/ex2_4.out
170 : filter: grep -v Solution
171 : requires: !single
172 : timeoutfactor: 2
173 : test:
174 : suffix: 4
175 : args: -st_type sinvert -st_pc_type cholesky
176 : test:
177 : suffix: 4_filter
178 : args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200
179 : requires: !__float128
180 : test:
181 : suffix: 4_filter_cuda
182 : args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijcusparse
183 : requires: cuda
184 : test:
185 : suffix: 4_filter_hip
186 : args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijhipsparse
187 : requires: hip
188 : test:
189 : suffix: 4_evsl
190 : args: -eps_type evsl
191 : requires: evsl
192 :
193 : TEST*/
|