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[] = "Illustrates the PGNHEP problem type. "
12 : "Based on ex7.\n"
13 : "The command line options are:\n"
14 : " -f1 <filename> -f2 <filename>, PETSc binary files containing A and B.\n\n";
15 :
16 : #include <slepceps.h>
17 :
18 2 : int main(int argc,char **argv)
19 : {
20 2 : EPS eps;
21 2 : Mat A,B;
22 2 : PetscBool flg;
23 2 : PetscReal tol=1000*PETSC_MACHINE_EPSILON;
24 2 : char filename[PETSC_MAX_PATH_LEN];
25 2 : PetscViewer viewer;
26 :
27 2 : PetscFunctionBeginUser;
28 2 : PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
29 2 : PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nPGNHEP problem loaded from file\n\n"));
30 :
31 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 : Load the matrices that define the eigensystem, Ax=kBx
33 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
34 :
35 2 : PetscCall(PetscOptionsGetString(NULL,NULL,"-f1",filename,sizeof(filename),&flg));
36 2 : PetscCheck(flg,PETSC_COMM_WORLD,PETSC_ERR_USER_INPUT,"Must indicate a file name for matrix A with the -f1 option");
37 :
38 : #if defined(PETSC_USE_COMPLEX)
39 2 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrices from binary files...\n"));
40 : #else
41 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrices from binary files...\n"));
42 : #endif
43 2 : PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
44 2 : PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
45 2 : PetscCall(MatSetFromOptions(A));
46 2 : PetscCall(MatLoad(A,viewer));
47 2 : PetscCall(PetscViewerDestroy(&viewer));
48 :
49 2 : PetscCall(PetscOptionsGetString(NULL,NULL,"-f2",filename,sizeof(filename),&flg));
50 2 : if (flg) {
51 2 : PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
52 2 : PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
53 2 : PetscCall(MatSetFromOptions(B));
54 2 : PetscCall(MatLoad(B,viewer));
55 2 : PetscCall(PetscViewerDestroy(&viewer));
56 : } else {
57 0 : PetscCall(PetscPrintf(PETSC_COMM_WORLD," Matrix B was not provided, setting B=I\n\n"));
58 0 : B = NULL;
59 : }
60 :
61 : /* This example is intended for a matrix pair (A,B) where B is symmetric positive definite;
62 : If we load matrices bfw62a/bfw62b, scale both of them because bfw62b is negative definite */
63 2 : PetscCall(PetscStrendswith(filename,"bfw62b.petsc",&flg));
64 2 : if (flg) {
65 0 : PetscCall(MatScale(A,-1.0));
66 0 : PetscCall(MatScale(B,-1.0));
67 : }
68 :
69 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70 : Create the eigensolver and solve the problem
71 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
72 :
73 2 : PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
74 2 : PetscCall(EPSSetOperators(eps,A,B));
75 2 : PetscCall(EPSSetProblemType(eps,EPS_PGNHEP));
76 2 : PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
77 2 : PetscCall(EPSSetFromOptions(eps));
78 2 : PetscCall(EPSSolve(eps));
79 :
80 : /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 : Display solution and clean up
82 : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
83 :
84 2 : PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
85 2 : PetscCall(EPSDestroy(&eps));
86 2 : PetscCall(MatDestroy(&A));
87 2 : PetscCall(MatDestroy(&B));
88 2 : PetscCall(SlepcFinalize());
89 : return 0;
90 : }
91 :
92 : /*TEST
93 :
94 : testset:
95 : args: -f1 ${SLEPC_DIR}/share/slepc/datafiles/matrices/bfw62a.petsc -f2 ${SLEPC_DIR}/share/slepc/datafiles/matrices/bfw62b.petsc -eps_largest_real -eps_nev 4
96 : requires: double !complex !defined(PETSC_USE_64BIT_INDICES)
97 : output_file: output/test26_1.out
98 : test:
99 : args: -eps_true_residual {{0 1}}
100 : suffix: 1
101 : test:
102 : args: -eps_type arpack
103 : suffix: 1_arpack
104 : requires: arpack
105 :
106 : testset:
107 : args: -f1 ${DATAFILESPATH}/matrices/complex/mhd1280a.petsc -f2 ${DATAFILESPATH}/matrices/complex/mhd1280b.petsc -eps_smallest_real -eps_nev 4
108 : requires: double complex datafilespath !defined(PETSC_USE_64BIT_INDICES)
109 : output_file: output/test26_2.out
110 : test:
111 : suffix: 2
112 : test:
113 : args: -eps_type arpack
114 : suffix: 2_arpack
115 : requires: arpack
116 :
117 : TEST*/
|