Actual source code: test32.c
slepc-3.16.3 2022-04-11
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2021, 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[] = "Tests a GHEP problem with symmetric matrices.\n\n";
13: #include <slepceps.h>
15: int main(int argc,char **argv)
16: {
17: Mat A,B; /* matrices */
18: EPS eps; /* eigenproblem solver context */
19: ST st;
20: KSP ksp;
21: PC pc;
22: PCType pctype;
23: PetscInt N,n=45,m,Istart,Iend,II,i,j;
24: PetscBool flag;
27: SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
28: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
29: PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);
30: if (!flag) m=n;
31: N = n*m;
32: PetscPrintf(PETSC_COMM_WORLD,"\nGeneralized Symmetric Eigenproblem, N=%D (%Dx%D grid)\n\n",N,n,m);
34: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35: Compute the matrices that define the eigensystem, Ax=kBx
36: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38: MatCreate(PETSC_COMM_WORLD,&A);
39: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
40: MatSetFromOptions(A);
41: MatSetUp(A);
43: MatCreate(PETSC_COMM_WORLD,&B);
44: MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N);
45: MatSetFromOptions(B);
46: MatSetUp(B);
48: MatGetOwnershipRange(A,&Istart,&Iend);
49: for (II=Istart;II<Iend;II++) {
50: i = II/n; j = II-i*n;
51: if (i>0) { MatSetValue(A,II,II-n,-1.0,INSERT_VALUES); }
52: if (i<m-1) { MatSetValue(A,II,II+n,-1.0,INSERT_VALUES); }
53: if (j>0) { MatSetValue(A,II,II-1,-1.0,INSERT_VALUES); }
54: if (j<n-1) { MatSetValue(A,II,II+1,-1.0,INSERT_VALUES); }
55: MatSetValue(A,II,II,4.0,INSERT_VALUES);
56: MatSetValue(B,II,II,2.0/PetscLogScalar(II+2),INSERT_VALUES);
57: }
58: MatSetValue(B,0,1,0.4,INSERT_VALUES);
59: MatSetValue(B,1,0,0.4,INSERT_VALUES);
61: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
62: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
63: MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
64: MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);
66: MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
67: MatSetOption(A,MAT_HERMITIAN,PETSC_TRUE);
68: MatSetOption(B,MAT_SYMMETRIC,PETSC_TRUE);
69: MatSetOption(B,MAT_HERMITIAN,PETSC_TRUE);
71: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72: Create the eigensolver and solve the problem
73: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
75: EPSCreate(PETSC_COMM_WORLD,&eps);
76: EPSSetOperators(eps,A,B);
77: EPSSetProblemType(eps,EPS_GHEP);
78: EPSSetFromOptions(eps);
79: EPSSetUp(eps);
80: EPSGetST(eps,&st);
81: STGetKSP(st,&ksp);
82: KSPGetPC(ksp,&pc);
83: PCGetType(pc,&pctype);
84: PetscPrintf(PETSC_COMM_WORLD," Using %s for the PC\n",pctype);
85: EPSSolve(eps);
86: EPSErrorView(eps,EPS_ERROR_BACKWARD,NULL);
88: EPSDestroy(&eps);
89: MatDestroy(&A);
90: MatDestroy(&B);
91: SlepcFinalize();
92: return ierr;
93: }
95: /*TEST
97: test:
98: suffix: 1
99: args: -n 18 -eps_nev 3 -st_type sinvert -eps_target 1.02
101: test:
102: suffix: 2
103: args: -n 18 -eps_type ciss -rg_interval_endpoints 1.0,1.2
104: requires: !single
106: testset:
107: nsize: {{1 4}}
108: args: -n 8 -eps_nev 60 -st_pc_type redundant
109: filter: grep -v Using
110: requires: !single !valgrind
111: output_file: output/test32_3.out
112: test:
113: suffix: 3
114: test:
115: suffix: 3_gnhep
116: args: -eps_gen_non_hermitian
118: testset:
119: nsize: {{1 4}}
120: args: -n 8 -eps_nev 64 -st_pc_type redundant
121: filter: grep -v Using
122: requires: !single
123: output_file: output/test32_4.out
124: test:
125: suffix: 4
126: test:
127: suffix: 4_gnhep
128: args: -eps_gen_non_hermitian
130: testset:
131: requires: !single
132: args: -eps_tol 1e-10 -st_type sinvert -st_ksp_type preonly -st_pc_type cholesky -eps_interval .8,1.1 -eps_krylovschur_partitions 2
133: output_file: output/test32_5.out
134: nsize: 3
135: filter: grep -v Using
136: test:
137: suffix: 5_redundant
138: args: -st_pc_type redundant -st_redundant_pc_type cholesky
139: test:
140: suffix: 5_mumps
141: requires: mumps !complex
142: args: -st_pc_factor_mat_solver_type mumps -st_mat_mumps_icntl_13 1
143: test:
144: suffix: 5_superlu
145: requires: superlu_dist
146: args: -st_pc_factor_mat_solver_type superlu_dist -st_mat_superlu_dist_rowperm NOROWPERM
147: timeoutfactor: 10
149: TEST*/