Actual source code: ex4.c
slepc-3.11.2 2019-07-30
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2019, 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[] = "Solves a standard eigensystem Ax=kx with the matrix loaded from a file.\n"
12: "This example works for both real and complex numbers.\n\n"
13: "The command line options are:\n"
14: " -file <filename>, where <filename> = matrix file in PETSc binary form.\n\n";
16: #include <slepceps.h>
18: int main(int argc,char **argv)
19: {
20: Mat A; /* operator matrix */
21: EPS eps; /* eigenproblem solver context */
22: EPSType type;
23: PetscReal tol;
24: PetscInt nev,maxit,its;
25: char filename[PETSC_MAX_PATH_LEN];
26: PetscViewer viewer;
27: PetscBool flg,terse;
30: SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
32: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33: Load the operator matrix that defines the eigensystem, Ax=kx
34: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36: PetscPrintf(PETSC_COMM_WORLD,"\nEigenproblem stored in file.\n\n");
37: PetscOptionsGetString(NULL,NULL,"-file",filename,PETSC_MAX_PATH_LEN,&flg);
38: if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate a file name with the -file option");
40: #if defined(PETSC_USE_COMPLEX)
41: PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrix from a binary file...\n");
42: #else
43: PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrix from a binary file...\n");
44: #endif
45: PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);
46: MatCreate(PETSC_COMM_WORLD,&A);
47: MatSetFromOptions(A);
48: MatLoad(A,viewer);
49: PetscViewerDestroy(&viewer);
51: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52: Create the eigensolver and set various options
53: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
55: /*
56: Create eigensolver context
57: */
58: EPSCreate(PETSC_COMM_WORLD,&eps);
60: /*
61: Set operators. In this case, it is a standard eigenvalue problem
62: */
63: EPSSetOperators(eps,A,NULL);
65: /*
66: Set solver parameters at runtime
67: */
68: EPSSetFromOptions(eps);
70: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71: Solve the eigensystem
72: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
74: EPSSolve(eps);
75: EPSGetIterationNumber(eps,&its);
76: PetscPrintf(PETSC_COMM_WORLD," Number of iterations of the method: %D\n",its);
78: /*
79: Optional: Get some information from the solver and display it
80: */
81: EPSGetType(eps,&type);
82: PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type);
83: EPSGetDimensions(eps,&nev,NULL,NULL);
84: PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %D\n",nev);
85: EPSGetTolerances(eps,&tol,&maxit);
86: PetscPrintf(PETSC_COMM_WORLD," Stopping condition: tol=%.4g, maxit=%D\n",(double)tol,maxit);
88: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89: Display solution and clean up
90: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
92: /* show detailed info unless -terse option is given by user */
93: PetscOptionsHasName(NULL,NULL,"-terse",&terse);
94: if (terse) {
95: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
96: } else {
97: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
98: EPSReasonView(eps,PETSC_VIEWER_STDOUT_WORLD);
99: EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
100: PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
101: }
102: EPSDestroy(&eps);
103: MatDestroy(&A);
104: SlepcFinalize();
105: return ierr;
106: }
108: /*TEST
110: test:
111: suffix: 1
112: args: -file ${SLEPC_DIR}/share/slepc/datafiles/matrices/rdb200.petsc -eps_nev 4 -terse
113: requires: double !complex !define(PETSC_USE_64BIT_INDICES)
115: test:
116: suffix: ciss_1
117: args: -file ${DATAFILESPATH}/matrices/complex/qc324.petsc -eps_type ciss -rg_type ellipse -rg_ellipse_center -.012-.08i -rg_ellipse_radius .05 -terse
118: requires: complex datafilespath
120: TEST*/