00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _PETSCCOMPGRID_H_
00012 #define _PETSCCOMPGRID_H_
00013 #include "Stencil.H"
00014 #include "BCFunc.H"
00015 #include "DisjointBoxLayout.H"
00016 #include "BoxIterator.H"
00017 #include "FourthOrderInterpStencil.H"
00018 #ifdef CH_USE_PETSC
00019 #include <petsc.h>
00020 #endif
00021 #include "NamespaceHeader.H"
00022
00023 typedef enum {GHOST=-1,FINE_COVERED=-2,DIRI_BC=-3,
00024 NEUM_BC=-4,ANY_BC=-5,UNKNOWN=-6} GID_type;
00025
00026 std::ostream& operator<< (std::ostream& os, GID_type);
00027
00028
00029
00030 class PetscCompGrid
00031 {
00032
00033 public:
00034
00035 virtual ~PetscCompGrid();
00036
00037 #ifdef CH_USE_PETSC
00038
00039
00040 PetscCompGrid(int a_dof) : m_gid0(0),m_mat(0),m_Pmat(0),m_CFStencilRad(2),m_writeMatlab(false),
00041 m_averageFineSolutionToCoarse(true),m_verbose(0),m_dof(a_dof),
00042 m_num_extra_nnz(0),m_repartition(PETSC_FALSE),
00043 m_patch_size(0),m_from_petscscat(0)
00044 {
00045 #if defined(PETSC_USE_LOG)
00046 PetscLogEventRegister("createMatrix",PETSC_VIEWER_CLASSID,&m_event0);
00047 PetscLogEventRegister("PetscCompGrid",PETSC_VIEWER_CLASSID,&m_event1);
00048 PetscLogEventRegister("Prepartsition",PETSC_VIEWER_CLASSID,&m_event2);
00049 #endif
00050 }
00051
00052 virtual void define( const ProblemDomain &a_cdomain,
00053 Vector<DisjointBoxLayout> &a_grids,
00054 Vector<int> &a_refratios,
00055 BCHolder a_bc,
00056 const RealVect &a_cdx,
00057 int a_numLevels=-1, int a_ibase=0);
00058
00059 virtual void clean();
00060
00061 Mat getMatrix() const { return m_mat; }
00062 Mat getPMatrix() const { return m_Pmat; }
00063 void setMatlab(bool b=true) {m_writeMatlab = b;}
00064 void setRepartition(bool b=true) {m_repartition = (b ? PETSC_TRUE : PETSC_FALSE);}
00065 void setVerbose(int a_v){ m_verbose=a_v;}
00066 void setAverageFineSolutionToCoarse(bool b=true) {m_averageFineSolutionToCoarse = b;}
00067
00068
00069 PetscErrorCode createMatrix(int a_makePmat=0);
00070
00071 PetscErrorCode putChomboInPetsc( const Vector<LevelData<FArrayBox> * > &rhs, Vec b )const;
00072 PetscErrorCode putPetscInChombo( Vec b, Vector<LevelData<FArrayBox> * > &rhs )const;
00073
00074 virtual IntVect getGhostVect()const = 0;
00075 virtual void addExtraCovered(GID_type,int,const DataIndex&,BaseFab<PetscInt>&) {}
00076 protected:
00077
00078 virtual void createOpStencil(IntVect,int,const DataIndex&,StencilTensor &) = 0;
00079 virtual void applyBCs(IntVect,int,const DataIndex&,Box,StencilTensor &);
00080 virtual void InterpToFine(IntVect,int,const DataIndex&,StencilTensor &);
00081 virtual void InterpToCoarse(IntVect,int,const DataIndex&,StencilTensor &);
00082
00083 IntVect getCFStencil(const ProblemDomain &a_cdom, const IntVect a_ivc);
00084
00085 PetscErrorCode AddStencilToMat(IntVect,int,const DataIndex&,StencilTensor &, Mat);
00086
00087 void NodeDefine(StencilNode &a_node, IntVect a_iv, int a_lev, Real a_val)
00088 {
00089 a_node.first.setIV(a_iv);
00090 a_node.first.setLevel(a_lev);
00091 a_node.second.define(1);
00092 a_node.second.setValue(a_val);
00093 }
00094 void setCFCoverMaps(int a_nlev);
00095 void setCoverMaps(int a_nlev);
00096 PetscErrorCode permuteDataAndMaps(Vector<StencilTensor> &patchStencil);
00097
00098 Vector<ProblemDomain> m_domains;
00099 Vector<DisjointBoxLayout> m_grids;
00100 Vector<int> m_refRatios;
00101 Vector<RealVect> m_dxs;
00102 public:
00103 Vector<RefCountedPtr<LevelData<BaseFab<PetscInt> > > > m_GIDs;
00104 protected:
00105 Vector<RefCountedPtr<LevelData<BaseFab<PetscInt> > > > m_crsSupportGIDs;
00106 Vector<RefCountedPtr<LevelData<BaseFab<PetscInt> > > > m_fineCoverGIDs;
00107 public:
00108 PetscInt m_gid0,m_nlocrealpatches,m_patchid0;
00109 protected:
00110 Mat m_mat;
00111 Mat m_Pmat;
00112 BCHolder m_bc;
00113
00114 int m_CFStencilRad;
00115 BaseFab<FourthOrderInterpStencil*> m_FCStencils;
00116 bool m_writeMatlab;
00117 bool m_averageFineSolutionToCoarse;
00118 int m_verbose;
00119 const int m_dof;
00120 #if defined(PETSC_USE_LOG)
00121 PetscLogEvent m_event0;
00122 PetscLogEvent m_event1;
00123 PetscLogEvent m_event2;
00124 #endif
00125 public:
00126 int m_num_extra_nnz;
00127
00128 PetscBool m_repartition;
00129 private:
00130 PetscInt m_patch_size;
00131 VecScatter m_from_petscscat;
00132 Vec m_origvec;
00133 private:
00134
00135 void operator=(const PetscCompGrid& a_input)
00136 {
00137 MayDay::Error("invalid operator");
00138 }
00139
00140 PetscCompGrid(const PetscCompGrid& a_input):m_dof(0)
00141 {
00142 MayDay::Error("invalid operator");
00143 }
00144 #endif // ifdef petsc
00145
00146 };
00147
00148 class CompBC : public BCFunction
00149 {
00150 public:
00151 CompBC() {;}
00152 CompBC(int a_nSource, IntVect a_nGhosts);
00153 virtual ~CompBC();
00154 void define(int a_nSource, IntVect a_nGhosts);
00155
00156 virtual void createCoefs() = 0;
00157 virtual void operator()( FArrayBox& a_state,
00158 const Box& a_valid,
00159 const ProblemDomain& a_domain,
00160 Real a_dx,
00161 bool a_homogeneous) = 0;
00162
00163 virtual void operator()( FArrayBox& a_state,
00164 const Box& a_valid,
00165 const ProblemDomain& a_domain,
00166 Real a_dx,
00167 const DataIndex& a_index,
00168 bool a_homogeneous)
00169 {
00170 operator()(a_state, a_valid, a_domain, a_dx, a_homogeneous);
00171 }
00172
00173 IntVect nGhosts()const{return m_nGhosts;}
00174 int nSources()const{return m_nSources;}
00175 #ifdef CH_USE_PETSC
00176 PetscReal getCoef(int a_iSrc, int a_iGhost=0);
00177 #else
00178 Real getCoef(int a_iSrc, int a_iGhost=0);
00179 #endif
00180 protected:
00181 #ifdef CH_USE_PETSC
00182 PetscReal *m_Rcoefs;
00183 #else
00184 Vector<Real> m_Rcoefs;
00185 #endif
00186 IntVect m_nGhosts;
00187 int m_nSources;
00188 bool m_isDefined;
00189
00190 };
00191
00192 class ConstDiriBC : public CompBC
00193 {
00194 public:
00195 ConstDiriBC(int a_nSource=1, IntVect a_nGhosts=IntVect::Unit) : CompBC(a_nSource,a_nGhosts) {}
00196 virtual void createCoefs();
00197 virtual void operator()( FArrayBox& a_state,
00198 const Box& a_valid,
00199 const ProblemDomain& a_domain,
00200 Real a_dx,
00201 bool a_homogeneous);
00202 };
00203
00204 #include "NamespaceFooter.H"
00205
00206 #endif