Date: 2013-09-02T10:05:23+00:00

Actual source code: test5.c

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2013, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.

      8:    SLEPc is free software: you can redistribute it and/or modify it under  the
      9:    terms of version 3 of the GNU Lesser General Public License as published by
     10:    the Free Software Foundation.

     12:    SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
     13:    WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
     14:    FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
     15:    more details.

     17:    You  should have received a copy of the GNU Lesser General  Public  License
     18:    along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
     19:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     20: */

     22: static char help[] = "Test EPS with different builds with a matrix loaded from a file.\n"
     23:   "This test is based on ex4.c in tutorials.\n"
     24:   "It loads test matrices available in PETSc's distribution.\n"
     25:   "Add -symm or -herm to select the symmetric/Hermitian matrix.\n\n";

     27: #include <slepceps.h>

     31: int main(int argc,char **argv)
     32: {
     33:   Mat            A;               /* operator matrix */
     34:   EPS            eps;             /* eigenproblem solver context */
     35:   char           filename[PETSC_MAX_PATH_LEN];
     36:   const char     *prefix,*scalar,*ints,*floats;
     37:   PetscReal      tol=1000*PETSC_MACHINE_EPSILON;
     38:   PetscViewer    viewer;
     39:   PetscBool      flg,symm;

     42:   SlepcInitialize(&argc,&argv,(char*)0,help);

     44:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     45:         Load the operator matrix that defines the eigensystem, Ax=kx
     46:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     47:   PetscOptionsHasName(NULL,"-symm",&symm);
     48:   PetscOptionsHasName(NULL,"-herm",&flg);
     49:   if (flg) symm=PETSC_TRUE;
     50: #if defined(PETSC_USE_COMPLEX)
     51:   prefix = symm? "hpd": "nh";
     52:   scalar = "complex";
     53: #else
     54:   prefix = symm? "spd": "ns";
     55:   scalar = "real";
     56: #endif
     57: #if defined(PETSC_USE_64BIT_INDICES)
     58:   ints   = "int64";
     59: #else
     60:   ints   = "int32";
     61: #endif
     62: #if defined(PETSC_USE_REAL_DOUBLE)
     63:   floats = "float64";
     64: #elif defined(PETSC_USE_REAL_SINGLE)
     65:   floats = "float32";
     66: #endif

     68:   PetscSNPrintf(filename,PETSC_MAX_PATH_LEN,"%s/share/petsc/datafiles/matrices/%s-%s-%s-%s",PETSC_DIR,prefix,scalar,ints,floats);
     69:   PetscPrintf(PETSC_COMM_WORLD,"\nReading matrix from binary file...\n\n");
     70:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);
     71:   MatCreate(PETSC_COMM_WORLD,&A);
     72:   MatSetFromOptions(A);
     73:   MatLoad(A,viewer);
     74:   PetscViewerDestroy(&viewer);

     76:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     77:                      Create the eigensolver
     78:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     79:   EPSCreate(PETSC_COMM_WORLD,&eps);
     80:   EPSSetOperators(eps,A,NULL);
     81:   if (symm) {
     82:     EPSSetProblemType(eps,EPS_HEP);
     83:   } else {
     84:     EPSSetProblemType(eps,EPS_NHEP);
     85:   }
     86:   EPSSetTolerances(eps,tol,PETSC_DEFAULT);
     87:   EPSSetFromOptions(eps);

     89:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     90:                 Solve the eigensystem and display solution
     91:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     92:   EPSSolve(eps);
     93:   EPSPrintSolution(eps,NULL);
     94:   EPSDestroy(&eps);
     95:   MatDestroy(&A);
     96:   SlepcFinalize();
     97:   return 0;
     98: }