Actual source code: test32.c
slepc-3.17.1 2022-04-11
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[] = "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;
26: SlepcInitialize(&argc,&argv,(char*)0,help);
27: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
28: PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);
29: if (!flag) m=n;
30: N = n*m;
31: PetscPrintf(PETSC_COMM_WORLD,"\nGeneralized Symmetric Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m);
33: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34: Compute the matrices that define the eigensystem, Ax=kBx
35: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37: MatCreate(PETSC_COMM_WORLD,&A);
38: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
39: MatSetFromOptions(A);
40: MatSetUp(A);
42: MatCreate(PETSC_COMM_WORLD,&B);
43: MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N);
44: MatSetFromOptions(B);
45: MatSetUp(B);
47: MatGetOwnershipRange(A,&Istart,&Iend);
48: for (II=Istart;II<Iend;II++) {
49: i = II/n; j = II-i*n;
50: if (i>0) MatSetValue(A,II,II-n,-1.0,INSERT_VALUES);
51: if (i<m-1) MatSetValue(A,II,II+n,-1.0,INSERT_VALUES);
52: if (j>0) MatSetValue(A,II,II-1,-1.0,INSERT_VALUES);
53: if (j<n-1) MatSetValue(A,II,II+1,-1.0,INSERT_VALUES);
54: MatSetValue(A,II,II,4.0,INSERT_VALUES);
55: MatSetValue(B,II,II,2.0/PetscLogScalar(II+2),INSERT_VALUES);
56: }
57: MatSetValue(B,0,1,0.4,INSERT_VALUES);
58: MatSetValue(B,1,0,0.4,INSERT_VALUES);
60: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
61: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
62: MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
63: MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);
65: MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
66: MatSetOption(A,MAT_HERMITIAN,PETSC_TRUE);
67: MatSetOption(B,MAT_SYMMETRIC,PETSC_TRUE);
68: MatSetOption(B,MAT_HERMITIAN,PETSC_TRUE);
70: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71: Create the eigensolver and solve the problem
72: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
74: EPSCreate(PETSC_COMM_WORLD,&eps);
75: EPSSetOperators(eps,A,B);
76: EPSSetProblemType(eps,EPS_GHEP);
77: EPSSetFromOptions(eps);
78: EPSSetUp(eps);
79: EPSGetST(eps,&st);
80: STGetKSP(st,&ksp);
81: KSPGetPC(ksp,&pc);
82: PCGetType(pc,&pctype);
83: PetscPrintf(PETSC_COMM_WORLD," Using %s for the PC\n",pctype);
84: EPSSolve(eps);
85: EPSErrorView(eps,EPS_ERROR_BACKWARD,NULL);
87: EPSDestroy(&eps);
88: MatDestroy(&A);
89: MatDestroy(&B);
90: SlepcFinalize();
91: return 0;
92: }
94: /*TEST
96: test:
97: suffix: 1
98: args: -n 18 -eps_nev 3 -st_type sinvert -eps_target 1.02
100: test:
101: suffix: 2
102: args: -n 18 -eps_type ciss -rg_interval_endpoints 1.0,1.2
103: requires: !single
105: testset:
106: nsize: {{1 4}}
107: args: -n 8 -eps_nev 60 -st_pc_type redundant
108: filter: grep -v Using
109: requires: !single
110: output_file: output/test32_3.out
111: test:
112: suffix: 3
113: test:
114: suffix: 3_gnhep
115: args: -eps_gen_non_hermitian
117: testset:
118: nsize: {{1 4}}
119: args: -n 8 -eps_nev 64 -st_pc_type redundant
120: filter: grep -v Using
121: requires: !single
122: output_file: output/test32_4.out
123: test:
124: suffix: 4
125: test:
126: suffix: 4_gnhep
127: args: -eps_gen_non_hermitian
129: testset:
130: requires: !single
131: 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
132: output_file: output/test32_5.out
133: nsize: 3
134: filter: grep -v Using
135: test:
136: suffix: 5_redundant
137: args: -st_pc_type redundant -st_redundant_pc_type cholesky
138: test:
139: suffix: 5_mumps
140: requires: mumps !complex
141: args: -st_pc_factor_mat_solver_type mumps -st_mat_mumps_icntl_13 1
142: test:
143: suffix: 5_superlu
144: requires: superlu_dist
145: args: -st_pc_factor_mat_solver_type superlu_dist -st_mat_superlu_dist_rowperm NOROWPERM
146: timeoutfactor: 10
148: TEST*/