Actual source code: test30.c
slepc-3.20.1 2023-11-27
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 changing EPS type.\n\n";
13: #include <slepceps.h>
15: int main(int argc,char **argv)
16: {
17: Mat A; /* problem matrix */
18: EPS eps; /* eigenproblem solver context */
19: ST st;
20: KSP ksp;
21: PetscInt n=20,i,Istart,Iend,nrest;
23: PetscFunctionBeginUser;
24: PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
25: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%" PetscInt_FMT "\n\n",n));
27: PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
28: PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
29: PetscCall(MatSetFromOptions(A));
30: PetscCall(MatSetUp(A));
31: PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
32: for (i=Istart;i<Iend;i++) PetscCall(MatSetValue(A,i,i,i+1,INSERT_VALUES));
33: PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
34: PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
36: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37: Create eigensolver and view options
38: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39: PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
40: PetscCall(EPSSetOperators(eps,A,NULL));
41: PetscCall(EPSSetProblemType(eps,EPS_HEP));
42: PetscCall(EPSSetTarget(eps,4.8));
43: PetscCall(EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE));
44: PetscCall(EPSSetDimensions(eps,4,PETSC_DEFAULT,PETSC_DEFAULT));
46: PetscCall(EPSSetType(eps,EPSRQCG));
47: PetscCall(EPSRQCGSetReset(eps,10));
48: PetscCall(EPSSetFromOptions(eps));
49: PetscCall(EPSRQCGGetReset(eps,&nrest));
50: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"RQCG reset parameter = %" PetscInt_FMT "\n\n",nrest));
51: PetscCall(EPSView(eps,NULL));
53: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54: Change eigensolver type and solve problem
55: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
56: PetscCall(EPSSetType(eps,EPSGD));
57: PetscCall(EPSGetST(eps,&st));
58: PetscCall(STGetKSP(st,&ksp));
59: PetscCall(KSPSetType(ksp,KSPPREONLY));
60: PetscCall(EPSSolve(eps));
61: PetscCall(EPSView(eps,NULL));
63: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64: Display solution and clean up
65: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
66: PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
67: PetscCall(EPSDestroy(&eps));
68: PetscCall(MatDestroy(&A));
69: PetscCall(SlepcFinalize());
70: return 0;
71: }
73: /*TEST
75: test:
76: suffix: 1
77: args: -eps_harmonic -eps_conv_norm
78: filter: grep -v tolerance | sed -e "s/symmetric/hermitian/"
80: TEST*/