Actual source code: test8.c
slepc-3.18.0 2022-10-01
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[] = "Test interface functions of polynomial JD.\n\n"
12: "This is based on ex16.c. 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";
16: #include <slepcpep.h>
18: int main(int argc,char **argv)
19: {
20: Mat M,C,K,A[3]; /* problem matrices */
21: PEP pep; /* polynomial eigenproblem solver context */
22: PetscInt N,n=10,m,Istart,Iend,II,i,j,midx;
23: PetscReal restart,fix;
24: PetscBool flag,reuse;
25: PEPJDProjection proj;
28: SlepcInitialize(&argc,&argv,(char*)0,help);
30: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
31: PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);
32: if (!flag) m=n;
33: N = n*m;
34: PetscPrintf(PETSC_COMM_WORLD,"\nQuadratic Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m);
36: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37: Compute the matrices that define the eigensystem, (k^2*M+k*C+K)x=0
38: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
40: /* K is the 2-D Laplacian */
41: MatCreate(PETSC_COMM_WORLD,&K);
42: MatSetSizes(K,PETSC_DECIDE,PETSC_DECIDE,N,N);
43: MatSetFromOptions(K);
44: MatSetUp(K);
45: MatGetOwnershipRange(K,&Istart,&Iend);
46: for (II=Istart;II<Iend;II++) {
47: i = II/n; j = II-i*n;
48: if (i>0) MatSetValue(K,II,II-n,-1.0,INSERT_VALUES);
49: if (i<m-1) MatSetValue(K,II,II+n,-1.0,INSERT_VALUES);
50: if (j>0) MatSetValue(K,II,II-1,-1.0,INSERT_VALUES);
51: if (j<n-1) MatSetValue(K,II,II+1,-1.0,INSERT_VALUES);
52: MatSetValue(K,II,II,4.0,INSERT_VALUES);
53: }
54: MatAssemblyBegin(K,MAT_FINAL_ASSEMBLY);
55: MatAssemblyEnd(K,MAT_FINAL_ASSEMBLY);
57: /* C is the 1-D Laplacian on horizontal lines */
58: MatCreate(PETSC_COMM_WORLD,&C);
59: MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,N,N);
60: MatSetFromOptions(C);
61: MatSetUp(C);
62: MatGetOwnershipRange(C,&Istart,&Iend);
63: for (II=Istart;II<Iend;II++) {
64: i = II/n; j = II-i*n;
65: if (j>0) MatSetValue(C,II,II-1,-1.0,INSERT_VALUES);
66: if (j<n-1) MatSetValue(C,II,II+1,-1.0,INSERT_VALUES);
67: MatSetValue(C,II,II,2.0,INSERT_VALUES);
68: }
69: MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
70: MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
72: /* M is a diagonal matrix */
73: MatCreate(PETSC_COMM_WORLD,&M);
74: MatSetSizes(M,PETSC_DECIDE,PETSC_DECIDE,N,N);
75: MatSetFromOptions(M);
76: MatSetUp(M);
77: MatGetOwnershipRange(M,&Istart,&Iend);
78: for (II=Istart;II<Iend;II++) MatSetValue(M,II,II,(PetscReal)(II+1),INSERT_VALUES);
79: MatAssemblyBegin(M,MAT_FINAL_ASSEMBLY);
80: MatAssemblyEnd(M,MAT_FINAL_ASSEMBLY);
82: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83: Create the eigensolver and set various options
84: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
86: PEPCreate(PETSC_COMM_WORLD,&pep);
87: A[0] = K; A[1] = C; A[2] = M;
88: PEPSetOperators(pep,3,A);
89: PEPSetType(pep,PEPJD);
91: /*
92: Test interface functions of JD solver
93: */
94: PEPJDGetRestart(pep,&restart);
95: PetscPrintf(PETSC_COMM_WORLD," Restart parameter before changing = %g",(double)restart);
96: PEPJDSetRestart(pep,0.3);
97: PEPJDGetRestart(pep,&restart);
98: PetscPrintf(PETSC_COMM_WORLD," ... changed to %g\n",(double)restart);
100: PEPJDGetFix(pep,&fix);
101: PetscPrintf(PETSC_COMM_WORLD," Fix parameter before changing = %g",(double)fix);
102: PEPJDSetFix(pep,0.001);
103: PEPJDGetFix(pep,&fix);
104: PetscPrintf(PETSC_COMM_WORLD," ... changed to %g\n",(double)fix);
106: PEPJDGetReusePreconditioner(pep,&reuse);
107: PetscPrintf(PETSC_COMM_WORLD," Reuse preconditioner flag before changing = %d",(int)reuse);
108: PEPJDSetReusePreconditioner(pep,PETSC_TRUE);
109: PEPJDGetReusePreconditioner(pep,&reuse);
110: PetscPrintf(PETSC_COMM_WORLD," ... changed to %d\n",(int)reuse);
112: PEPJDGetProjection(pep,&proj);
113: PetscPrintf(PETSC_COMM_WORLD," Projection type before changing = %d",(int)proj);
114: PEPJDSetProjection(pep,PEP_JD_PROJECTION_ORTHOGONAL);
115: PEPJDGetProjection(pep,&proj);
116: PetscPrintf(PETSC_COMM_WORLD," ... changed to %d\n",(int)proj);
118: PEPJDGetMinimalityIndex(pep,&midx);
119: PetscPrintf(PETSC_COMM_WORLD," Minimality index before changing = %" PetscInt_FMT,midx);
120: PEPJDSetMinimalityIndex(pep,2);
121: PEPJDGetMinimalityIndex(pep,&midx);
122: PetscPrintf(PETSC_COMM_WORLD," ... changed to %" PetscInt_FMT "\n",midx);
124: PEPSetFromOptions(pep);
126: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127: Solve the eigensystem
128: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
130: PEPSolve(pep);
131: PEPErrorView(pep,PEP_ERROR_BACKWARD,NULL);
132: PEPDestroy(&pep);
133: MatDestroy(&M);
134: MatDestroy(&C);
135: MatDestroy(&K);
136: SlepcFinalize();
137: return 0;
138: }
140: /*TEST
142: test:
143: args: -n 12 -pep_nev 2 -pep_ncv 21 -pep_conv_abs
145: TEST*/