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 : This example implements one of the problems found at
12 : NLEVP: A Collection of Nonlinear Eigenvalue Problems,
13 : The University of Manchester.
14 : The details of the collection can be found at:
15 : [1] T. Betcke et al., "NLEVP: A Collection of Nonlinear Eigenvalue
16 : Problems", ACM Trans. Math. Software 39(2), Article 7, 2013.
17 :
18 : The butterfly problem is a quartic PEP with T-even structure.
19 : */
20 :
21 : static char help[] = "Quartic polynomial eigenproblem with T-even structure.\n\n"
22 : "The command line options are:\n"
23 : " -m <m>, grid size, the dimension of the matrices is n=m*m.\n"
24 : " -c <array>, problem parameters, must be 10 comma-separated real values.\n\n";
25 :
26 : #include <slepcpep.h>
27 :
28 : #define NMAT 5
29 :
30 4 : int main(int argc,char **argv)
31 : {
32 4 : Mat A[NMAT]; /* problem matrices */
33 4 : PEP pep; /* polynomial eigenproblem solver context */
34 4 : PetscInt n,m=8,k,II,Istart,Iend,i,j;
35 4 : PetscReal c[10] = { 0.6, 1.3, 1.3, 0.1, 0.1, 1.2, 1.0, 1.0, 1.2, 1.0 };
36 4 : PetscBool flg;
37 4 : PetscBool terse;
38 :
39 4 : PetscFunctionBeginUser;
40 4 : PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
41 :
42 4 : PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,NULL));
43 4 : n = m*m;
44 4 : k = 10;
45 4 : PetscCall(PetscOptionsGetRealArray(NULL,NULL,"-c",c,&k,&flg));
46 4 : PetscCheck(!flg || k==10,PETSC_COMM_WORLD,PETSC_ERR_USER,"The number of parameters -c should be 10, you provided %" PetscInt_FMT,k);
47 4 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nButterfly problem, n=%" PetscInt_FMT " (m=%" PetscInt_FMT ")\n\n",n,m));
48 :
49 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 : Compute the polynomial matrices
51 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
52 :
53 : /* initialize matrices */
54 24 : for (i=0;i<NMAT;i++) {
55 20 : PetscCall(MatCreate(PETSC_COMM_WORLD,&A[i]));
56 20 : PetscCall(MatSetSizes(A[i],PETSC_DECIDE,PETSC_DECIDE,n,n));
57 20 : PetscCall(MatSetFromOptions(A[i]));
58 : }
59 4 : PetscCall(MatGetOwnershipRange(A[0],&Istart,&Iend));
60 :
61 : /* A0 */
62 260 : for (II=Istart;II<Iend;II++) {
63 256 : i = II/m; j = II-i*m;
64 256 : PetscCall(MatSetValue(A[0],II,II,4.0*c[0]/6.0+4.0*c[1]/6.0,INSERT_VALUES));
65 256 : if (j>0) PetscCall(MatSetValue(A[0],II,II-1,c[0]/6.0,INSERT_VALUES));
66 256 : if (j<m-1) PetscCall(MatSetValue(A[0],II,II+1,c[0]/6.0,INSERT_VALUES));
67 256 : if (i>0) PetscCall(MatSetValue(A[0],II,II-m,c[1]/6.0,INSERT_VALUES));
68 256 : if (i<m-1) PetscCall(MatSetValue(A[0],II,II+m,c[1]/6.0,INSERT_VALUES));
69 : }
70 :
71 : /* A1 */
72 260 : for (II=Istart;II<Iend;II++) {
73 256 : i = II/m; j = II-i*m;
74 256 : if (j>0) PetscCall(MatSetValue(A[1],II,II-1,c[2],INSERT_VALUES));
75 256 : if (j<m-1) PetscCall(MatSetValue(A[1],II,II+1,-c[2],INSERT_VALUES));
76 256 : if (i>0) PetscCall(MatSetValue(A[1],II,II-m,c[3],INSERT_VALUES));
77 256 : if (i<m-1) PetscCall(MatSetValue(A[1],II,II+m,-c[3],INSERT_VALUES));
78 : }
79 :
80 : /* A2 */
81 260 : for (II=Istart;II<Iend;II++) {
82 256 : i = II/m; j = II-i*m;
83 256 : PetscCall(MatSetValue(A[2],II,II,-2.0*c[4]-2.0*c[5],INSERT_VALUES));
84 256 : if (j>0) PetscCall(MatSetValue(A[2],II,II-1,c[4],INSERT_VALUES));
85 256 : if (j<m-1) PetscCall(MatSetValue(A[2],II,II+1,c[4],INSERT_VALUES));
86 256 : if (i>0) PetscCall(MatSetValue(A[2],II,II-m,c[5],INSERT_VALUES));
87 256 : if (i<m-1) PetscCall(MatSetValue(A[2],II,II+m,c[5],INSERT_VALUES));
88 : }
89 :
90 : /* A3 */
91 260 : for (II=Istart;II<Iend;II++) {
92 256 : i = II/m; j = II-i*m;
93 256 : if (j>0) PetscCall(MatSetValue(A[3],II,II-1,c[6],INSERT_VALUES));
94 256 : if (j<m-1) PetscCall(MatSetValue(A[3],II,II+1,-c[6],INSERT_VALUES));
95 256 : if (i>0) PetscCall(MatSetValue(A[3],II,II-m,c[7],INSERT_VALUES));
96 256 : if (i<m-1) PetscCall(MatSetValue(A[3],II,II+m,-c[7],INSERT_VALUES));
97 : }
98 :
99 : /* A4 */
100 260 : for (II=Istart;II<Iend;II++) {
101 256 : i = II/m; j = II-i*m;
102 256 : PetscCall(MatSetValue(A[4],II,II,2.0*c[8]+2.0*c[9],INSERT_VALUES));
103 256 : if (j>0) PetscCall(MatSetValue(A[4],II,II-1,-c[8],INSERT_VALUES));
104 256 : if (j<m-1) PetscCall(MatSetValue(A[4],II,II+1,-c[8],INSERT_VALUES));
105 256 : if (i>0) PetscCall(MatSetValue(A[4],II,II-m,-c[9],INSERT_VALUES));
106 256 : if (i<m-1) PetscCall(MatSetValue(A[4],II,II+m,-c[9],INSERT_VALUES));
107 : }
108 :
109 : /* assemble matrices */
110 24 : for (i=0;i<NMAT;i++) PetscCall(MatAssemblyBegin(A[i],MAT_FINAL_ASSEMBLY));
111 24 : for (i=0;i<NMAT;i++) PetscCall(MatAssemblyEnd(A[i],MAT_FINAL_ASSEMBLY));
112 :
113 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114 : Create the eigensolver and solve the problem
115 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
116 :
117 4 : PetscCall(PEPCreate(PETSC_COMM_WORLD,&pep));
118 4 : PetscCall(PEPSetOperators(pep,NMAT,A));
119 4 : PetscCall(PEPSetFromOptions(pep));
120 4 : PetscCall(PEPSolve(pep));
121 :
122 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123 : Display solution and clean up
124 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
125 :
126 : /* show detailed info unless -terse option is given by user */
127 4 : PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
128 4 : if (terse) PetscCall(PEPErrorView(pep,PEP_ERROR_BACKWARD,NULL));
129 : else {
130 0 : PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
131 0 : PetscCall(PEPConvergedReasonView(pep,PETSC_VIEWER_STDOUT_WORLD));
132 0 : PetscCall(PEPErrorView(pep,PEP_ERROR_BACKWARD,PETSC_VIEWER_STDOUT_WORLD));
133 0 : PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
134 : }
135 4 : PetscCall(PEPDestroy(&pep));
136 24 : for (i=0;i<NMAT;i++) PetscCall(MatDestroy(&A[i]));
137 4 : PetscCall(SlepcFinalize());
138 : return 0;
139 : }
140 :
141 : /*TEST
142 :
143 : testset:
144 : args: -pep_nev 4 -st_type sinvert -pep_target 0.01 -terse
145 : output_file: output/butterfly_1.out
146 : test:
147 : suffix: 1_toar
148 : args: -pep_type toar -pep_toar_restart 0.3
149 : test:
150 : suffix: 1_linear
151 : args: -pep_type linear
152 :
153 : test:
154 : suffix: 2
155 : args: -pep_type {{toar linear}} -pep_nev 4 -terse
156 : requires: double
157 :
158 : testset:
159 : args: -pep_type ciss -rg_type ellipse -rg_ellipse_center 1+.5i -rg_ellipse_radius .15 -terse
160 : requires: complex
161 : filter: sed -e "s/95386/95385/" | sed -e "s/91010/91009/" | sed -e "s/93092/93091/" | sed -e "s/96723/96724/" | sed -e "s/43015/43016/" | sed -e "s/53513/53514/"
162 : output_file: output/butterfly_ciss.out
163 : timeoutfactor: 2
164 : test:
165 : suffix: ciss_hankel
166 : args: -pep_ciss_extraction hankel -pep_ciss_integration_points 60
167 : requires: !single
168 : test:
169 : suffix: ciss_ritz
170 : args: -pep_ciss_extraction ritz
171 : test:
172 : suffix: ciss_caa
173 : args: -pep_ciss_extraction caa -pep_ciss_moments 4
174 : test:
175 : suffix: ciss_part
176 : nsize: 2
177 : args: -pep_ciss_partitions 2
178 : test:
179 : suffix: ciss_refine
180 : args: -pep_ciss_refine_inner 1 -pep_ciss_refine_blocksize 1
181 :
182 : testset:
183 : args: -pep_type ciss -rg_type ellipse -rg_ellipse_center .5+.5i -rg_ellipse_radius .25 -pep_ciss_moments 4 -pep_ciss_blocksize 5 -pep_ciss_refine_blocksize 2 -terse
184 : requires: complex double
185 : filter: sed -e "s/46483/46484/" | sed -e "s/54946/54945/" | sed -e "s/48456/48457/" | sed -e "s/74117/74116/" | sed -e "s/37240/37241/"
186 : output_file: output/butterfly_4.out
187 : test:
188 : suffix: 4
189 : test:
190 : suffix: 4_hankel
191 : args: -pep_ciss_extraction hankel
192 :
193 : TEST*/
|