Date: 2022-08-09T09:05:38+00:00

Actual source code: test20.c
slepc-3.17.2 2022-08-09
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:   SlepcInitialize(&argc,&argv,(char*)0,help);
     23:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     24:   PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%" PetscInt_FMT "\n\n",n);

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

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

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

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

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

     65:   EPSDestroy(&eps);
     66:   MatDestroy(&A);
     67:   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*/