Date: 2021-09-20T09:43:55+00:00

Actual source code: test12.c
slepc-3.15.2 2021-09-20
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2021, 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[] = "Diagonal eigenproblem. Illustrates use of shell preconditioner.\n\n"
     12:   "The command line options are:\n"
     13:   "  -n <n>, where <n> = number of grid subdivisions = matrix dimension.\n"
     14:   "  -seed <s>, where <s> = seed for random number generation.\n\n";

     16: #include <slepceps.h>

     18: PetscErrorCode PCApply_User(PC pc,Vec x,Vec y)
     19: {

     23:   VecCopy(x,y);
     24:   return(0);
     25: }

     27: int main(int argc,char **argv)
     28: {
     29:   Mat            A;           /* problem matrix */
     30:   EPS            eps;         /* eigenproblem solver context */
     31:   Vec            v0;          /* initial vector */
     32:   PetscRandom    rand;
     33:   PetscReal      tol=PETSC_SMALL;
     34:   PetscInt       n=30,i,Istart,Iend,seed=0x12345678;
     36:   ST             st;
     37:   KSP            ksp;
     38:   PC             pc;

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

     42:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     43:   PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%D\n\n",n);

     45:   MatCreate(PETSC_COMM_WORLD,&A);
     46:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
     47:   MatSetFromOptions(A);
     48:   MatSetUp(A);
     49:   MatGetOwnershipRange(A,&Istart,&Iend);
     50:   for (i=Istart;i<Iend;i++) {
     51:     MatSetValue(A,i,i,i+1,INSERT_VALUES);
     52:   }
     53:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     54:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     56:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     57:                       Solve the eigensystem
     58:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     59:   EPSCreate(PETSC_COMM_WORLD,&eps);
     60:   EPSSetOperators(eps,A,NULL);
     61:   EPSSetProblemType(eps,EPS_HEP);
     62:   EPSSetTolerances(eps,tol,PETSC_DEFAULT);
     63:   EPSSetFromOptions(eps);
     64:   EPSGetST(eps,&st);
     65:   STGetKSP(st,&ksp);
     66:   KSPGetPC(ksp,&pc);
     67:   PCSetType(pc,PCSHELL);
     68:   PCShellSetApply(pc,PCApply_User);

     70:   /* set random initial vector */
     71:   MatCreateVecs(A,&v0,NULL);
     72:   PetscRandomCreate(PETSC_COMM_WORLD,&rand);
     73:   PetscRandomSetFromOptions(rand);
     74:   PetscOptionsGetInt(NULL,NULL,"-seed",&seed,NULL);
     75:   PetscRandomSetSeed(rand,seed);
     76:   PetscRandomSeed(rand);
     77:   VecSetRandom(v0,rand);
     78:   EPSSetInitialSpace(eps,1,&v0);
     79:   /* call the solver */
     80:   EPSSolve(eps);

     82:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     83:                     Display solution and clean up
     84:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     85:   EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
     86:   EPSDestroy(&eps);
     87:   MatDestroy(&A);
     88:   VecDestroy(&v0);
     89:   PetscRandomDestroy(&rand);
     90:   SlepcFinalize();
     91:   return ierr;
     92: }

     94: /*TEST

     96:    testset:
     97:       requires: !single
     98:       output_file: output/test12_1.out
     99:       test:
    100:          suffix: 1
    101:          args: -eps_type {{krylovschur subspace arnoldi gd jd}} -eps_nev 4
    102:       test:
    103:          suffix: 1_power
    104:          args: -eps_type power -eps_max_it 10000 -eps_nev 4
    105:       test:
    106:          suffix: 1_gd2
    107:          args: -eps_type gd -eps_gd_double_expansion -eps_nev 4

    109: TEST*/