Date: 2021-02-01T14:42:00+00:00

Actual source code: test4.c
slepc-3.14.2 2021-02-01
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2020, 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 the solution of a HEP without calling EPSSetFromOptions (based on ex1.c).\n\n"
     12:   "The command line options are:\n"
     13:   "  -n <n>, where <n> = number of grid subdivisions = matrix dimension.\n"
     14:   "  -type <eps_type> = eps type to test.\n\n";

     16: #include <slepceps.h>

     18: int main(int argc,char **argv)
     19: {
     20:   Mat            A;           /* problem matrix */
     21:   EPS            eps;         /* eigenproblem solver context */
     22:   PetscReal      tol=1000*PETSC_MACHINE_EPSILON;
     23:   PetscInt       n=30,i,Istart,Iend,nev;
     24:   PetscBool      flg,gd2;
     25:   char           epstype[30] = "krylovschur";

     28:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

     30:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     31:   PetscOptionsGetString(NULL,NULL,"-type",epstype,sizeof(epstype),NULL);
     32:   PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%D\n\n",n);

     34:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     35:      Compute the operator matrix that defines the eigensystem, Ax=kx
     36:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     38:   MatCreate(PETSC_COMM_WORLD,&A);
     39:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
     40:   MatSetFromOptions(A);
     41:   MatSetUp(A);

     43:   MatGetOwnershipRange(A,&Istart,&Iend);
     44:   for (i=Istart;i<Iend;i++) {
     45:     if (i>0) { MatSetValue(A,i,i-1,-1.0,INSERT_VALUES); }
     46:     if (i<n-1) { MatSetValue(A,i,i+1,-1.0,INSERT_VALUES); }
     47:     MatSetValue(A,i,i,2.0,INSERT_VALUES);
     48:   }
     49:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     50:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     52:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     53:                 Create the eigensolver and set various options
     54:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     55:   /*
     56:      Create eigensolver context
     57:   */
     58:   EPSCreate(PETSC_COMM_WORLD,&eps);

     60:   /*
     61:      Set operators. In this case, it is a standard eigenvalue problem
     62:   */
     63:   EPSSetOperators(eps,A,NULL);
     64:   EPSSetProblemType(eps,EPS_HEP);
     65:   EPSSetDimensions(eps,4,PETSC_DEFAULT,PETSC_DEFAULT);
     66:   EPSSetTolerances(eps,tol,PETSC_DEFAULT);

     68:   /*
     69:      Set solver parameters at runtime
     70:   */
     71:   PetscStrcmp(epstype,"gd2",&flg);
     72:   if (flg) {
     73:     EPSSetType(eps,EPSGD);
     74:     EPSGDSetDoubleExpansion(eps,PETSC_TRUE);
     75:     EPSGDGetDoubleExpansion(eps,&gd2);  /* not used */
     76:   } else {
     77:     EPSSetType(eps,epstype);
     78:   }
     79:   PetscStrcmp(epstype,"jd",&flg);
     80:   if (flg) {
     81:     EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE);
     82:     EPSSetTarget(eps,4.0);
     83:   }
     84:   PetscObjectTypeCompareAny((PetscObject)eps,&flg,EPSRQCG,EPSLOBPCG,"");
     85:   if (flg) {
     86:     EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL);
     87:   }

     89:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     90:                       Solve the eigensystem
     91:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     93:   EPSSolve(eps);
     94:   EPSGetDimensions(eps,&nev,NULL,NULL);
     95:   PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %D\n",nev);

     97:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     98:                     Display solution and clean up
     99:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

    101:   EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
    102:   EPSDestroy(&eps);
    103:   MatDestroy(&A);
    104:   SlepcFinalize();
    105:   return ierr;
    106: }

    108: /*TEST

    110:    testset:
    111:       output_file: output/test4_1.out
    112:       test:
    113:          suffix: 1
    114:          args: -type {{krylovschur subspace arnoldi lanczos gd jd gd2 lapack}}
    115:       test:
    116:          suffix: 1_arpack
    117:          args: -type arpack
    118:          requires: arpack
    119:       test:
    120:          suffix: 1_primme
    121:          args: -type primme
    122:          requires: primme
    123:       test:
    124:          suffix: 1_trlan
    125:          args: -type trlan
    126:          requires: trlan

    128:    testset:
    129:       output_file: output/test4_2.out
    130:       test:
    131:          suffix: 2
    132:          args: -type {{rqcg lobpcg}}
    133:       test:
    134:          suffix: 2_blzpack
    135:          args: -type blzpack
    136:          requires: blzpack

    138: TEST*/