Actual source code: test20.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[] = "Tests multiple calls to EPSSolve changing ncv.\n\n";
13: #include <slepceps.h>
15: int main(int argc,char **argv)
16: {
17: Mat A;
18: EPS eps;
19: PetscReal tol=PetscMax(1000*PETSC_MACHINE_EPSILON,1e-9);
20: PetscInt n=30,i,Istart,Iend,nev,ncv;
23: SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
24: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
25: PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%D\n\n",n);
27: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28: Compute the operator matrix that defines the eigensystem, Ax=kx
29: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
31: MatCreate(PETSC_COMM_WORLD,&A);
32: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
33: MatSetFromOptions(A);
34: MatSetUp(A);
35: MatGetOwnershipRange(A,&Istart,&Iend);
36: for (i=Istart;i<Iend;i++) {
37: if (i>0) { MatSetValue(A,i,i-1,-1.0,INSERT_VALUES); }
38: if (i<n-1) { MatSetValue(A,i,i+1,-1.0,INSERT_VALUES); }
39: MatSetValue(A,i,i,2.0,INSERT_VALUES);
40: }
41: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
42: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
44: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45: Create the solver, call EPSSolve() twice
46: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
47: EPSCreate(PETSC_COMM_WORLD,&eps);
48: EPSSetOperators(eps,A,NULL);
49: EPSSetProblemType(eps,EPS_HEP);
50: EPSSetTolerances(eps,tol,PETSC_DEFAULT);
51: EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL);
52: EPSSetFromOptions(eps);
54: /* First solve */
55: EPSSolve(eps);
56: PetscPrintf(PETSC_COMM_WORLD," - - - First solve, default subspace dimension - - -\n");
57: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
59: /* Second solve */
60: EPSGetDimensions(eps,&nev,&ncv,NULL);
61: EPSSetDimensions(eps,nev,ncv+2,PETSC_DEFAULT);
62: EPSSolve(eps);
63: PetscPrintf(PETSC_COMM_WORLD," - - - Second solve, subspace of increased size - - -\n");
64: EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
66: EPSDestroy(&eps);
67: MatDestroy(&A);
68: SlepcFinalize();
69: return ierr;
70: }
72: /*TEST
74: test:
75: suffix: 1
76: args: -n 18 -eps_type {{krylovschur arnoldi gd jd rqcg lobpcg lapack}} -eps_max_it 1500
77: output_file: output/test20_1.out
79: test:
80: suffix: 1_lanczos
81: args: -n 18 -eps_type lanczos -eps_lanczos_reorthog full -eps_max_it 1500
82: output_file: output/test20_1.out
84: TEST*/