Overture  Version 25
PETScEquationSolver.h
Go to the documentation of this file.
1 #ifndef PETSC_EQUATION_SOLVER_H
2 #define PETSC_EQUATION_SOLVER_H
3 
4 //
5 // Petsc solvers in Overture **** SERIAL VERSION ****
6 //
7 // $Id: PETScEquationSolver.h,v 1.12 2008/12/03 17:54:53 chand Exp $
8 //
9 
10 //kkc 081124 #include <iostream.h>
11 #include <iostream>
12 #include <math.h>
13 #include <assert.h>
14 
15 #include "mpi.h"
16 #include "Overture.h"
17 #include "Oges.h"
18 
19 #include "EquationSolver.h"
20 
21 // krb do not use extern "C" if PETSc is linked using BOPT=g_c++
22 extern "C"
23 {
24 #include "petscksp.h"
25 }
26 
27 
28 // Experimental Preconditioner from David Hysom (Summer 2000)
29 #ifdef USE_DH_PRECONDITIONER
30 extern "C"
31 {
32 #include "dhPreconditioner.h"
33 #include "dh_timer.h"
34 }
35 #else
36 class MyPcData;
37 #endif /* USE_DH_PRECONDITIONER */
38 
40 {
41  public:
42  PETScEquationSolver(Oges & oges_);
43  virtual ~PETScEquationSolver();
44 
45  virtual int solve(realCompositeGridFunction & u,
47 
48  virtual int saveBinaryMatrix(aString filename00,
51 
52  virtual real sizeOf( FILE *file=NULL ); // return number of bytes allocated
53 
54  MPI_Comm comm;
55  KSP ksp; // Linear solver ConTeXt, Krylov Space solver ctx
56  PC pc; // Preconditioner ctx
57  Vec xsol,brhs;
58  Mat Amx;
59 
60  virtual real getMaximumResidual();
61 
62  int allocateMatrix(int,int,int,int);
63  int setMatrixElement(int,int,int,real);
64  int displayMatrix();
65 
66 // So far a common data structure is used by all vector types, so there is no need to have these:
67 // void setRHSVectorElement(int,real);
68 // void setSolVectorElement(int,real);
69 
72 
73 
74  int initializePetscKSP();
75  int setPetscParameters();
77 
78  //....Aux to solve
79  int buildPetscMatrix();
80  void preallocRowStorage(int blockSize);
81  void getCsortWorkspace(int nWorkSpace00);
82  void computeDiagScaling();
85 
86  int setupPreconditioner(KSP ksp, Vec brhs, Vec xsol );
87 
88  //....Logging
91 
92  //private:
93  //..The remaining data is essentially PRIVATE,
94  // shouldn't be accessed or modified directly from outside the class
95  //......N.B: if you want to modify these objects, write
96  //...... access routines -- irect modification from
97  //...... outside the class is discouraged, and may not
98  //...... supported in future revisions.
99 
100  //CRITICAL------These are NOT to be tampered with from outside this class!!
101  bool petscInitialized; // if tru PETSc has been initialized
102 
103  int neqBuilt; // size of CURRENT matrix & vectors
104  real *aval; // local POINTERS to the matrix in Oges
105  int *ia_,*ja_;
106  int *iWorkRow; // Workspace for CSORT(=sorts the columns of A)
107  int nWorkRow;
108  int *nzzAlloc; // num. columns on each row--> for prealloc.
109  real *dscale; // Diagonal reSCALING to set rownorms==1
110 
111  //END CRITICAL----------------------------------
112 
115  // bool optionsChanged;
118 
119  bool turnOnPETScMemoryTracing; // have PETSc keep track of allocated memory.
120 
121  // here we save the values of the current state so we can compare for any changes
122  // with oges.parameters
128 
129 
130  //
131  // Information for new Hysom/Chow preconditioners
132  //
134 
135  MyPcData *dh_ctx;
136  double dh_setupTime;
137  double dh_solveTime;
138 
139  //int dh_ilu_type;
140  //int dh_ilu_levels;
141  //double dh_dropTolerance;
142  //double dh_sparseA;
143  //double dh_sparseF;
144 
146 
147  void dh_initialize();
148  void dh_setParameters();
149 
150  void dh_computeResidualReduction( double & residReduction );
151 
152 private:
153  int ierr;
154 
155 };
156 
157 // Note: The following macro will be distributed in versions of
158 // PETSc after version 2.0.28, so this is included here to allow linking
159 // with version 2.0.28 and earlier.
160 // *wdh* ?? #if !defined(PetscFunctionReturnVoid())
161 #if !defined(PetscFunctionReturnVoid)
162 #if defined(PETSC_USE_STACK)
163 #define PetscFunctionReturnVoid() \
164  {\
165  PetscStackPop;}
166 #else
167 #define PetscFunctionReturnVoid()
168 #endif
169 #endif
170 
171 #endif