Actual source code: test45.c

      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[] = "Test interface to external package ChASE.\n\n"
     12:   "This is based on ex3.c. The command line options are:\n"
     13:   "  -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
     14:   "  -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";

     16: #include <slepceps.h>

     18: int main(int argc,char **argv)
     19: {
     20:   Mat        A;           /* matrix */
     21:   EPS        eps;         /* eigenproblem solver context */
     22:   PetscInt   N,n=35,m,Istart,Iend,II,i,j,deg;
     23:   PetscBool  opt,flag;

     25:   PetscFunctionBeginUser;
     26:   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));

     28:   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
     29:   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
     30:   if (!flag) m=n;
     31:   N = n*m;
     32:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nStandard eigenproblem with ChASE, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));

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

     38:   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
     39:   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
     40:   PetscCall(MatSetFromOptions(A));

     42:   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
     43:   for (II=Istart;II<Iend;II++) {
     44:     i = II/n; j = II-i*n;
     45:     if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
     46:     if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
     47:     if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
     48:     if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
     49:     PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
     50:   }

     52:   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
     53:   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));

     55:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     56:                 Create the eigensolver and set various options
     57:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     59:   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
     60:   PetscCall(EPSSetOperators(eps,A,NULL));
     61:   PetscCall(EPSSetProblemType(eps,EPS_HEP));
     62:   PetscCall(EPSSetType(eps,EPSCHASE));
     63:   PetscCall(EPSSetDimensions(eps,6,PETSC_DETERMINE,PETSC_DETERMINE));
     64:   PetscCall(EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL));
     65:   deg = 20;
     66:   opt = PETSC_TRUE;
     67:   PetscCall(EPSCHASESetDegree(eps,deg,opt));
     68:   PetscCall(EPSSetFromOptions(eps));

     70:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     71:                  Compute eigenvalues and display info
     72:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     74:   PetscCall(EPSSolve(eps));
     75:   PetscCall(EPSCHASEGetDegree(eps,&deg,&opt));
     76:   PetscCall(PetscPrintf(PETSC_COMM_WORLD," ChASE: using degree %" PetscInt_FMT ", optimization %s\n",deg,PetscBools[opt]));

     78:   PetscCall(EPSErrorView(eps,EPS_ERROR_ABSOLUTE,NULL));

     80:   PetscCall(EPSDestroy(&eps));
     81:   PetscCall(MatDestroy(&A));
     82:   PetscCall(SlepcFinalize());
     83:   return 0;
     84: }

     86: /*TEST

     88:    build:
     89:       requires: chase

     91:    testset:
     92:       requires: chase
     93:       output_file: output/test45_1.out
     94:       test:
     95:          suffix: 1
     96:       test:
     97:          suffix: 2
     98:          args: -mat_scalapack_grid_height 2
     99:          nsize: 2

    101: TEST*/