Actual source code: test20.c

slepc-3.20.1 2023-11-27
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,(char*)0,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(MatSetUp(A));
 35:   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
 36:   for (i=Istart;i<Iend;i++) {
 37:     if (i>0) PetscCall(MatSetValue(A,i,i-1,-1.0,INSERT_VALUES));
 38:     if (i<n-1) PetscCall(MatSetValue(A,i,i+1,-1.0,INSERT_VALUES));
 39:     PetscCall(MatSetValue(A,i,i,2.0,INSERT_VALUES));
 40:   }
 41:   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
 42:   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));

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

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

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

 66:   PetscCall(EPSDestroy(&eps));
 67:   PetscCall(MatDestroy(&A));
 68:   PetscCall(SlepcFinalize());
 69:   return 0;
 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*/