Actual source code: test19.c

slepc-3.22.1 2024-10-28
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[] = "Tests the usage of object prefix.\n\n"
 12:   "The command line options are:\n"
 13:   "  -n <n>, where <n> = matrix dimension.\n\n";

 15: #include <slepceps.h>

 17: int main(int argc,char **argv)
 18: {
 19:   Mat            A;           /* problem matrix */
 20:   EPS            eps;         /* eigenproblem solver context */
 21:   PetscInt       n=30,i,Istart,Iend;
 22:   const char     *prefix;

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

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

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

 38:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 39:            Create the eigensolver and mess up with the prefix
 40:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 41:   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
 42:   PetscCall(EPSSetOptionsPrefix(eps,"check_"));
 43:   PetscCall(EPSAppendOptionsPrefix(eps,"myprefix_"));
 44:   PetscCall(EPSGetOptionsPrefix(eps,&prefix));
 45:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"EPS prefix is currently: %s\n\n",prefix));

 47:   PetscCall(EPSSetOperators(eps,A,NULL));
 48:   PetscCall(EPSSetProblemType(eps,EPS_HEP));
 49:   PetscCall(EPSSetFromOptions(eps));
 50:   PetscCall(EPSSolve(eps));

 52:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 53:                     Display solution and clean up
 54:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 55:   PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
 56:   PetscCall(EPSDestroy(&eps));
 57:   PetscCall(MatDestroy(&A));
 58:   PetscCall(SlepcFinalize());
 59:   return 0;
 60: }

 62: /*TEST

 64:    test:
 65:       suffix: 1
 66:       args: -check_myprefix_eps_nev 2 -check_myprefix_st_type sinvert

 68: TEST*/