Line data Source code
1 : /*
2 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3 : SLEPc - Scalable Library for Eigenvalue Problem Computations
4 : Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
5 :
6 : This file is part of SLEPc.
7 : SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 : */
10 :
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";
15 :
16 : #include <slepceps.h>
17 :
18 1 : int main(int argc,char **argv)
19 : {
20 1 : Mat A; /* operator matrix */
21 1 : EPS eps; /* eigenproblem solver context */
22 1 : EPSType type;
23 1 : PetscReal tol;
24 1 : PetscInt nev,maxit,its;
25 1 : char filename[PETSC_MAX_PATH_LEN];
26 1 : PetscViewer viewer;
27 1 : PetscBool flg,terse;
28 :
29 1 : PetscFunctionBeginUser;
30 1 : PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
31 :
32 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 : Load the operator matrix that defines the eigensystem, Ax=kx
34 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
35 :
36 1 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nEigenproblem stored in file.\n\n"));
37 1 : PetscCall(PetscOptionsGetString(NULL,NULL,"-file",filename,sizeof(filename),&flg));
38 1 : PetscCheck(flg,PETSC_COMM_WORLD,PETSC_ERR_USER_INPUT,"Must indicate a file name with the -file option");
39 :
40 : #if defined(PETSC_USE_COMPLEX)
41 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrix from a binary file...\n"));
42 : #else
43 1 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrix from a binary file...\n"));
44 : #endif
45 1 : PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
46 1 : PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
47 1 : PetscCall(MatSetFromOptions(A));
48 1 : PetscCall(MatLoad(A,viewer));
49 1 : PetscCall(PetscViewerDestroy(&viewer));
50 :
51 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 : Create the eigensolver and set various options
53 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
54 :
55 : /*
56 : Create eigensolver context
57 : */
58 1 : PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
59 :
60 : /*
61 : Set operators. In this case, it is a standard eigenvalue problem
62 : */
63 1 : PetscCall(EPSSetOperators(eps,A,NULL));
64 :
65 : /*
66 : Set solver parameters at runtime
67 : */
68 1 : PetscCall(EPSSetFromOptions(eps));
69 :
70 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71 : Solve the eigensystem
72 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73 :
74 1 : PetscCall(EPSSolve(eps));
75 1 : PetscCall(EPSGetIterationNumber(eps,&its));
76 1 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of iterations of the method: %" PetscInt_FMT "\n",its));
77 :
78 : /*
79 : Optional: Get some information from the solver and display it
80 : */
81 1 : PetscCall(EPSGetType(eps,&type));
82 1 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type));
83 1 : PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
84 1 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
85 1 : PetscCall(EPSGetTolerances(eps,&tol,&maxit));
86 1 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Stopping condition: tol=%.4g, maxit=%" PetscInt_FMT "\n",(double)tol,maxit));
87 :
88 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 : Display solution and clean up
90 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
91 :
92 : /* show detailed info unless -terse option is given by user */
93 1 : PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
94 1 : if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
95 : else {
96 0 : PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
97 0 : PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
98 0 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
99 0 : PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
100 : }
101 1 : PetscCall(EPSDestroy(&eps));
102 1 : PetscCall(MatDestroy(&A));
103 1 : PetscCall(SlepcFinalize());
104 : return 0;
105 : }
106 :
107 : /*TEST
108 :
109 : test:
110 : suffix: 1
111 : args: -file ${SLEPC_DIR}/share/slepc/datafiles/matrices/rdb200.petsc -eps_nev 4 -terse
112 : requires: double !complex !defined(PETSC_USE_64BIT_INDICES)
113 :
114 : testset:
115 : args: -file ${DATAFILESPATH}/matrices/complex/qc324.petsc -eps_type ciss -terse
116 : requires: double complex datafilespath !defined(PETSC_USE_64BIT_INDICES)
117 : test:
118 : suffix: ciss_1
119 : args: -rg_type ellipse -rg_ellipse_center -.012-.08i -rg_ellipse_radius .05
120 : test:
121 : suffix: ciss_2
122 : args: -rg_type interval -rg_interval_endpoints -0.062,.038,-.13,-.03 -eps_max_it 1
123 :
124 : TEST*/
|