Date: 2023-11-27T17:18:33+00:00

Actual source code: test6.c
slepc-3.20.1 2023-11-27
Report Typos and Errors

      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[] = "Diagonal eigenproblem.\n\n"
     12:   "The command line options are:\n"
     13:   "  -n <n>, where <n> = matrix dimension.\n"
     14:   "  -seed <s>, where <s> = seed for random number generation.\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:   Vec            v0;          /* initial vector */
     23:   PetscRandom    rand;
     24:   PetscReal      tol=PETSC_SMALL;
     25:   PetscInt       n=30,i,Istart,Iend,seed=0x12345678;

     27:   PetscFunctionBeginUser;
     28:   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));

     30:   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
     31:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%" PetscInt_FMT "\n\n",n));

     33:   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
     34:   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
     35:   PetscCall(MatSetFromOptions(A));
     36:   PetscCall(MatSetUp(A));
     37:   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
     38:   for (i=Istart;i<Iend;i++) PetscCall(MatSetValue(A,i,i,i+1,INSERT_VALUES));
     39:   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
     40:   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));

     42:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     43:                       Solve the eigensystem
     44:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     45:   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
     46:   PetscCall(EPSSetOperators(eps,A,NULL));
     47:   PetscCall(EPSSetProblemType(eps,EPS_HEP));
     48:   PetscCall(EPSSetTolerances(eps,tol,PETSC_DEFAULT));
     49:   PetscCall(EPSSetFromOptions(eps));
     50:   /* set random initial vector */
     51:   PetscCall(MatCreateVecs(A,&v0,NULL));
     52:   PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&rand));
     53:   PetscCall(PetscRandomSetFromOptions(rand));
     54:   PetscCall(PetscOptionsGetInt(NULL,NULL,"-seed",&seed,NULL));
     55:   PetscCall(PetscRandomSetSeed(rand,seed));
     56:   PetscCall(PetscRandomSeed(rand));
     57:   PetscCall(VecSetRandom(v0,rand));
     58:   PetscCall(EPSSetInitialSpace(eps,1,&v0));
     59:   /* call the solver */
     60:   PetscCall(EPSSolve(eps));

     62:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     63:                     Display solution and clean up
     64:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     65:   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
     66:   PetscCall(EPSDestroy(&eps));
     67:   PetscCall(MatDestroy(&A));
     68:   PetscCall(VecDestroy(&v0));
     69:   PetscCall(PetscRandomDestroy(&rand));
     70:   PetscCall(SlepcFinalize());
     71:   return 0;
     72: }

     74: /*TEST

     76:    testset:
     77:       args: -eps_nev 4
     78:       requires: !single
     79:       output_file: output/test6_1.out
     80:       test:
     81:          suffix: 1
     82:          args: -eps_type {{krylovschur subspace arnoldi gd}}
     83:       test:
     84:          suffix: 1_power
     85:          args: -eps_type power -eps_max_it 20000
     86:       test:
     87:          suffix: 1_gd2
     88:          args: -eps_type gd -eps_gd_double_expansion
     89:       test:
     90:          suffix: 1_arpack
     91:          args: -eps_type arpack
     92:          requires: arpack
     93:       test:
     94:          suffix: 1_trlan
     95:          args: -eps_type trlan
     96:          requires: trlan

     98: TEST*/