Subversion Repositories slepc-dev

Rev

Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2492 jroman 1
/*
2
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
   SLEPc - Scalable Library for Eigenvalue Problem Computations
4
   Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
5
 
6
   This file is part of SLEPc.
7
 
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.
11
 
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.
16
 
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
*/
21
 
2493 jroman 22
static char help[] = "Test different builds with a matrix loaded from a file.\n"
2492 jroman 23
  "This test is based on ex4.c in tutorials.\n"
2493 jroman 24
  "It loads test matrices available in PETSc's distribution.\n"
25
  "Add -symm or -herm to select the symmetric/Hermitian matrix.\n\n";
2492 jroman 26
 
27
#include <slepceps.h>
28
 
29
#undef __FUNCT__
30
#define __FUNCT__ "main"
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
  PetscViewer    viewer;
38
  PetscBool      flg,symm;
2540 jroman 39
  PetscReal      tol=1000*PETSC_MACHINE_EPSILON;
2492 jroman 40
  PetscErrorCode ierr;
41
 
42
  SlepcInitialize(&argc,&argv,(char*)0,help);
43
 
44
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45
        Load the operator matrix that defines the eigensystem, Ax=kx
46
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
47
  ierr = PetscOptionsHasName(PETSC_NULL,"-symm",&symm);CHKERRQ(ierr);
48
  ierr = PetscOptionsHasName(PETSC_NULL,"-herm",&flg);CHKERRQ(ierr);
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
67
 
68
  ierr = PetscSNPrintf(filename,PETSC_MAX_PATH_LEN,"%s/share/petsc/datafiles/matrices/%s-%s-%s-%s",PETSC_DIR,prefix,scalar,ints,floats);CHKERRQ(ierr);
2530 jroman 69
  ierr = PetscPrintf(PETSC_COMM_WORLD,"\nReading matrix from binary file...\n\n");CHKERRQ(ierr);
2492 jroman 70
  ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
71
  ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
72
  ierr = MatSetFromOptions(A);CHKERRQ(ierr);
73
  ierr = MatLoad(A,viewer);CHKERRQ(ierr);
74
  ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
75
 
76
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77
                     Create the eigensolver
78
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
79
  ierr = EPSCreate(PETSC_COMM_WORLD,&eps);CHKERRQ(ierr);
80
  ierr = EPSSetOperators(eps,A,PETSC_NULL);CHKERRQ(ierr);
2493 jroman 81
  if (symm) { ierr = EPSSetProblemType(eps,EPS_HEP);CHKERRQ(ierr); }
82
  else      { ierr = EPSSetProblemType(eps,EPS_NHEP);CHKERRQ(ierr); }
2540 jroman 83
  ierr = EPSSetTolerances(eps,tol,PETSC_DEFAULT);CHKERRQ(ierr);
2492 jroman 84
  ierr = EPSSetFromOptions(eps);CHKERRQ(ierr);
85
 
86
  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87
                Solve the eigensystem and display solution
88
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
89
  ierr = EPSSolve(eps);CHKERRQ(ierr);
2508 jroman 90
  ierr = EPSPrintSolution(eps,PETSC_NULL);CHKERRQ(ierr);
2492 jroman 91
  ierr = EPSDestroy(&eps);CHKERRQ(ierr);
92
  ierr = MatDestroy(&A);CHKERRQ(ierr);
93
  ierr = SlepcFinalize();CHKERRQ(ierr);
94
  return 0;
95
}
96