Actual source code: test38.c
slepc-3.15.2 2021-09-20
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[] = "Test EPSLYAPII interface functions.\n\n"
12: "Based on ex2.\n"
13: "The command line options are:\n"
14: " -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
15: " -m <m>, where <m> = number of grid subdivisions in y dimension.\n"
16: " -shift <sigma>, where <sigma> = shift of origin.\n\n";
18: #include <slepceps.h>
20: int main(int argc,char **argv)
21: {
22: Mat A;
23: EPS eps;
24: PetscInt N,n=10,m,Istart,Iend,II,i,j,rkl,rkc;
25: PetscBool flag,terse;
26: PetscReal sigma=8.0;
29: SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
30: PetscOptionsGetReal(NULL,NULL,"-shift",&sigma,NULL);
31: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
32: PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);
33: if (!flag) m=n;
34: N = n*m;
35: PetscPrintf(PETSC_COMM_WORLD,"\nShifted 2-D Laplacian Eigenproblem, N=%D (%Dx%D grid) sigma=%.1f\n\n",N,n,m,(double)sigma);
37: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38: Create the 2-D Laplacian
39: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41: MatCreate(PETSC_COMM_WORLD,&A);
42: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
43: MatSetFromOptions(A);
44: MatSetUp(A);
45: MatGetOwnershipRange(A,&Istart,&Iend);
46: for (II=Istart;II<Iend;II++) {
47: i = II/n; j = II-i*n;
48: if (i>0) { MatSetValue(A,II,II-n,-1.0,INSERT_VALUES); }
49: if (i<m-1) { MatSetValue(A,II,II+n,-1.0,INSERT_VALUES); }
50: if (j>0) { MatSetValue(A,II,II-1,-1.0,INSERT_VALUES); }
51: if (j<n-1) { MatSetValue(A,II,II+1,-1.0,INSERT_VALUES); }
52: MatSetValue(A,II,II,4.0-sigma,INSERT_VALUES);
53: }
54: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
55: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
57: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58: Create the eigensolver and set various options
59: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
61: EPSCreate(PETSC_COMM_WORLD,&eps);
62: EPSSetOperators(eps,A,NULL);
63: EPSSetProblemType(eps,EPS_HEP);
64: EPSSetWhichEigenpairs(eps,EPS_LARGEST_REAL);
65: EPSSetType(eps,EPSLYAPII);
66: EPSSetFromOptions(eps);
68: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69: Solve the problem and display the solution
70: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
72: EPSSolve(eps);
74: /* print solver information */
75: PetscObjectTypeCompare((PetscObject)eps,EPSLYAPII,&flag);
76: if (flag) {
77: EPSLyapIIGetRanks(eps,&rkc,&rkl);
78: PetscPrintf(PETSC_COMM_WORLD," EPSLYAPII ranks: for Lyapunov solver=%D, after compression=%D\n\n",rkl,rkc);
79: }
81: PetscOptionsHasName(NULL,NULL,"-terse",&terse);
82: if (terse) {
83: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
84: } else {
85: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
86: EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD);
87: EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
88: PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
89: }
91: EPSDestroy(&eps);
92: MatDestroy(&A);
93: SlepcFinalize();
94: return ierr;
95: }
97: /*TEST
99: test:
100: args: -eps_view -terse
101: filter: grep -v tolerance | sed -e "s/symmetric/hermitian/"
103: TEST*/