Actual source code: test20.c

slepc-3.22.1 2024-10-28
Report Typos and Errors
  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[] = "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;

 22:   PetscFunctionBeginUser;
 23:   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
 24:   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
 25:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%" PetscInt_FMT "\n\n",n));

 27:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 28:      Compute the operator matrix that defines the eigensystem, Ax=kx
 29:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 31:   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
 32:   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
 33:   PetscCall(MatSetFromOptions(A));
 34:   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
 35:   for (i=Istart;i<Iend;i++) {
 36:     if (i>0) PetscCall(MatSetValue(A,i,i-1,-1.0,INSERT_VALUES));
 37:     if (i<n-1) PetscCall(MatSetValue(A,i,i+1,-1.0,INSERT_VALUES));
 38:     PetscCall(MatSetValue(A,i,i,2.0,INSERT_VALUES));
 39:   }
 40:   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
 41:   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));

 43:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 44:              Create the solver, call EPSSolve() twice
 45:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 46:   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
 47:   PetscCall(EPSSetOperators(eps,A,NULL));
 48:   PetscCall(EPSSetProblemType(eps,EPS_HEP));
 49:   PetscCall(EPSSetTolerances(eps,tol,PETSC_CURRENT));
 50:   PetscCall(EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL));
 51:   PetscCall(EPSSetFromOptions(eps));

 53:   /* First solve */
 54:   PetscCall(EPSSolve(eps));
 55:   PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - First solve, default subspace dimension - - -\n"));
 56:   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));

 58:   /* Second solve */
 59:   PetscCall(EPSGetDimensions(eps,&nev,&ncv,NULL));
 60:   PetscCall(EPSSetDimensions(eps,nev,ncv+2,PETSC_DETERMINE));
 61:   PetscCall(EPSSolve(eps));
 62:   PetscCall(PetscPrintf(PETSC_COMM_WORLD," - - - Second solve, subspace of increased size - - -\n"));
 63:   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));

 65:   PetscCall(EPSDestroy(&eps));
 66:   PetscCall(MatDestroy(&A));
 67:   PetscCall(SlepcFinalize());
 68:   return 0;
 69: }

 71: /*TEST

 73:    test:
 74:       suffix: 1
 75:       args: -n 18 -eps_type {{krylovschur arnoldi gd jd rqcg lobpcg lapack}} -eps_max_it 1500
 76:       output_file: output/test20_1.out

 78:    test:
 79:       suffix: 1_lanczos
 80:       args: -n 18 -eps_type lanczos -eps_lanczos_reorthog full -eps_max_it 1500
 81:       output_file: output/test20_1.out

 83: TEST*/