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

Actual source code: test18.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[] = "Symmetric-indefinite eigenproblem.\n\n"
     12:   "The command line options are:\n"
     13:   "  -n <n>, where <n> = number of grid subdivisions in x dimension.\n\n";

     15: #include <slepceps.h>

     17: int main(int argc,char **argv)
     18: {
     19:   Mat            A,B;             /* problem matrices */
     20:   EPS            eps;             /* eigenproblem solver context */
     21:   PetscInt       N,n=10,Istart,Iend,II,nev,i,j;
     22:   PetscBool      terse;

     25:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     26:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     27:   N = n*n;
     28:   PetscPrintf(PETSC_COMM_WORLD,"\nSymmetric-indefinite eigenproblem, N=%D\n\n",N);

     30:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     31:           Compute the matrices that define the eigensystem, Ax=kBx
     32:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     34:   MatCreate(PETSC_COMM_WORLD,&A);
     35:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
     36:   MatSetFromOptions(A);
     37:   MatSetUp(A);

     39:   MatCreate(PETSC_COMM_WORLD,&B);
     40:   MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N);
     41:   MatSetFromOptions(B);
     42:   MatSetUp(B);

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

     55:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     56:   MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
     57:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
     58:   MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);

     60:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     61:                 Create the eigensolver and set various options
     62:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     64:   EPSCreate(PETSC_COMM_WORLD,&eps);
     65:   EPSSetOperators(eps,A,B);
     66:   EPSSetProblemType(eps,EPS_GHIEP);
     67:   EPSSetFromOptions(eps);

     69:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     70:                       Solve the eigensystem
     71:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     73:   EPSSolve(eps);
     74:   EPSGetDimensions(eps,&nev,NULL,NULL);
     75:   PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %D\n",nev);

     77:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     78:                     Display solution and clean up
     79:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     81:   /* show detailed info unless -terse option is given by user */
     82:   PetscOptionsHasName(NULL,NULL,"-terse",&terse);
     83:   if (terse) {
     84:     EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
     85:   } else {
     86:     PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
     87:     EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD);
     88:     EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
     89:     PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
     90:   }

     92:   EPSDestroy(&eps);
     93:   MatDestroy(&A);
     94:   MatDestroy(&B);
     95:   SlepcFinalize();
     96:   return ierr;
     97: }

     99: /*TEST

    101:    testset:
    102:       args: -eps_nev 4 -eps_ncv 12 -terse -st_type sinvert -eps_krylovschur_restart .3
    103:       requires: !single
    104:       output_file: output/test18_1.out
    105:       test:
    106:          suffix: 1_ks
    107:       test:
    108:          suffix: 1_ks_gnhep
    109:          args: -eps_gen_non_hermitian
    110:       test:
    111:          suffix: 2_cuda_ks
    112:          args: -mat_type aijcusparse
    113:          requires: cuda
    114:       test:
    115:          suffix: 2_cuda_ks_gnhep
    116:          args: -eps_gen_non_hermitian -mat_type aijcusparse
    117:          requires: cuda

    119:    test:
    120:       suffix: 1_davidson
    121:       args: -eps_type {{gd jd}} -eps_target 0 -eps_harmonic -eps_nev 4 -eps_ncv 16 -terse
    122:       requires: !single
    123:       filter: sed -e "s/[+-]0\.0*i//g"
    124:       output_file: output/test18_1.out
    125: TEST*/