Date: 2020-01-13T12:00:40+00:00

Actual source code: test28.c
slepc-3.12.2 2020-01-13
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2019, 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 with different matrix of different size.\n\n"
     12:   "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,B;
     21:   EPS            eps;
     22:   PetscInt       N,n=10,m=11,Istart,Iend,II,nev=3,i,j;
     23:   PetscBool      flag,terse;

     26:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     27:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     28:   PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);
     29:   N = n*m;
     30:   PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%D (%Dx%D grid)\n\n",N,n,m);

     32:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     33:                 Create the 2-D Laplacian with coarse mesh
     34:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     36:   MatCreate(PETSC_COMM_WORLD,&A);
     37:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
     38:   MatSetFromOptions(A);
     39:   MatSetUp(A);
     40:   MatGetOwnershipRange(A,&Istart,&Iend);
     41:   for (II=Istart;II<Iend;II++) {
     42:     i = II/n; j = II-i*n;
     43:     if (i>0) { MatSetValue(A,II,II-n,-1.0,INSERT_VALUES); }
     44:     if (i<m-1) { MatSetValue(A,II,II+n,-1.0,INSERT_VALUES); }
     45:     if (j>0) { MatSetValue(A,II,II-1,-1.0,INSERT_VALUES); }
     46:     if (j<n-1) { MatSetValue(A,II,II+1,-1.0,INSERT_VALUES); }
     47:     MatSetValue(A,II,II,4.0,INSERT_VALUES);
     48:   }
     49:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     50:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     52:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     53:         Create the eigensolver, set options and solve the eigensystem
     54:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     56:   EPSCreate(PETSC_COMM_WORLD,&eps);
     57:   EPSSetOperators(eps,A,NULL);
     58:   EPSSetProblemType(eps,EPS_HEP);
     59:   EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL);
     60:   EPSSetDimensions(eps,nev,PETSC_DEFAULT,PETSC_DEFAULT);
     61:   EPSSetFromOptions(eps);

     63:   EPSSolve(eps);

     65:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     66:                     Display solution of first solve
     67:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     69:   PetscOptionsHasName(NULL,NULL,"-terse",&terse);
     70:   if (terse) {
     71:     EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
     72:   } else {
     73:     PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
     74:     EPSReasonView(eps,PETSC_VIEWER_STDOUT_WORLD);
     75:     EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
     76:     PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
     77:   }

     79:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     80:                Create the 2-D Laplacian with finer mesh
     81:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     83:   n *= 2;
     84:   m *= 2;
     85:   N = n*m;
     86:   PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%D (%Dx%D grid)\n\n",N,n,m);

     88:   MatCreate(PETSC_COMM_WORLD,&B);
     89:   MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N);
     90:   MatSetFromOptions(B);
     91:   MatSetUp(B);
     92:   MatGetOwnershipRange(B,&Istart,&Iend);
     93:   for (II=Istart;II<Iend;II++) {
     94:     i = II/n; j = II-i*n;
     95:     if (i>0) { MatSetValue(B,II,II-n,-1.0,INSERT_VALUES); }
     96:     if (i<m-1) { MatSetValue(B,II,II+n,-1.0,INSERT_VALUES); }
     97:     if (j>0) { MatSetValue(B,II,II-1,-1.0,INSERT_VALUES); }
     98:     if (j<n-1) { MatSetValue(B,II,II+1,-1.0,INSERT_VALUES); }
     99:     MatSetValue(B,II,II,4.0,INSERT_VALUES);
    100:   }
    101:   MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
    102:   MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);

    104:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    105:        Solve again, calling EPSReset() since matrix size has changed
    106:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

    108:   EPSReset(eps);  /* if this is omitted, it will be called in EPSSetOperators() */
    109:   EPSSetOperators(eps,B,NULL);
    110:   EPSSolve(eps);

    112:   if (terse) {
    113:     EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
    114:   } else {
    115:     PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
    116:     EPSReasonView(eps,PETSC_VIEWER_STDOUT_WORLD);
    117:     EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
    118:     PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
    119:   }

    121:   EPSDestroy(&eps);
    122:   MatDestroy(&A);
    123:   MatDestroy(&B);
    124:   SlepcFinalize();
    125:   return ierr;
    126: }

    128: /*TEST

    130:    test:
    131:       suffix: 1
    132:       args: -eps_type {{krylovschur arnoldi lanczos gd jd rqcg lobpcg lapack}} -terse
    133:       requires: !single
    134:       output_file: output/test28_1.out

    136:    test:
    137:       suffix: 2
    138:       args: -eps_type {{power subspace}} -eps_target 8 -st_type sinvert -terse
    139:       requires: !single
    140:       output_file: output/test28_2.out

    142:    test:
    143:       suffix: 3
    144:       args: -eps_interval 0.5,0.67 -st_type sinvert -st_pc_type cholesky -terse
    145:       requires: !single

    147: TEST*/