00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012
00013 #ifndef _EBINDEXSPACE_H_
00014 #define _EBINDEXSPACE_H_
00015
00016 #include "REAL.H"
00017 #include "IntVect.H"
00018 #include "IntVectSet.H"
00019 #include "VolIndex.H"
00020 #include "FaceIndex.H"
00021 #include "IntVectSet.H"
00022 #include "DisjointBoxLayout.H"
00023 #include "LevelData.H"
00024 #include "EBISBox.H"
00025 #include "GeometryService.H"
00026 #include "EBISLayout.H"
00027 #include "CH_HDF5.H"
00028 #include <map>
00029 #include "NamespaceHeader.H"
00030
00031 typedef std::map<DisjointBoxLayout, EBISLayout> dmap;
00032
00033 class EBIndexSpace;
00034
00036 class Chombo_EBIS
00037 {
00038 private:
00040
00048 static EBIndexSpace* s_instance;
00049
00050 Chombo_EBIS()
00051 {;}
00052
00053 ~Chombo_EBIS()
00054 {;}
00055 public:
00057
00064 static EBIndexSpace* instance();
00065
00066 };
00067
00069
00073 class EBISLevel
00074 {
00075 public:
00076 void coarsenVoFs(EBISLevel& a_fineEBIS);
00077
00078 void fixFineToCoarse(EBISLevel& a_fineEBIS);
00079
00080 void coarsenFaces(EBISLevel& a_fineEBIS);
00081
00082 int numVoFsOnProc() const;
00083
00084 void levelStitch(EBISLevel& a_otherPhase,
00085 const EBISLevel* a_fineThisPtr,
00086 const EBISLevel* a_fineOtherPtr);
00087
00088 void cellStitch(EBData& a_ebdataCoarA,
00089 EBData& a_ebdataCoarB,
00090 const EBGraph& a_ebgrapCoarA,
00091 const EBGraph& a_ebgrapCoarB,
00092 const EBISBox& a_ebisbxFineA,
00093 const EBISBox& a_ebisbxFineB,
00094 const IntVect& a_iv,
00095 const int& a_aphase,
00096 const int& a_bphase);
00097 EBISLevel();
00099
00103 EBISLevel(const ProblemDomain& a_domain,
00104 const RealVect& a_origin,
00105 const Real& a_dx,
00106 const GeometryService& a_geoserver,
00107 const EBIndexSpace* const ebisPtr = Chombo_EBIS::instance());
00108
00110
00116 EBISLevel(EBISLevel& a_finerLevel, const GeometryService& a_geoserver,
00117 const EBIndexSpace* const ebisPtr = Chombo_EBIS::instance());
00118
00119 #ifdef CH_USE_HDF5
00121 EBISLevel(HDF5Handle& handle);
00122
00124 void
00125 write(HDF5Handle& a_handle);
00126 #endif
00127
00129
00135 void sanityCheck(const EBIndexSpace* const ebisPtr = Chombo_EBIS::instance());
00136
00138 void fillEBISLayout(EBISLayout& a_ebis,
00139 const DisjointBoxLayout& a_grids,
00140 const int& nghost) const;
00141 ~EBISLevel();
00142
00143 const ProblemDomain& getDomain() const;
00144
00145 const DisjointBoxLayout& getGrids() const;
00146
00147 DisjointBoxLayout getIrregGrids() const;
00148
00149 DisjointBoxLayout getFlowGrids() const;
00150
00151 IntVectSet irregCells() const;
00152
00153 const Real& getDX() const;
00154
00155 const RealVect& getOrigin() const;
00156
00158 void fixRegularNextToMultiValued();
00159
00160 void clearMultiBoundaries();
00161 void setBoundaryPhase(int phase);
00162
00163 int m_phase;
00164
00165
00166
00167 private:
00168
00170 DisjointBoxLayout m_grids;
00171
00173 ProblemDomain m_domain;
00174
00176 RealVect m_origin;
00177
00179 Real m_dx;
00180
00182 LevelData<EBGraph> m_graph;
00183
00184 static bool s_verbose;
00185
00186 static Real s_tolerance;
00188 LevelData<EBData> m_data;
00189
00190
00191
00192 static void makeBoxes(Vector<Box>& a_boxes,
00193 Vector<long>& a_irregCount,
00194 const Box& a_region,
00195 const ProblemDomain& a_domain,
00196 const GeometryService& a_geoserver,
00197 const RealVect& a_origin,
00198 const Real& a_dx,
00199 const int a_ncellmax,
00200 const EBIndexSpace* const ebisPtr);
00201 static void makeBoxes(std::list<Box>& a_boxes,
00202 const Box& a_region,
00203 const ProblemDomain& a_domain,
00204 const GeometryService& a_geoserver,
00205 const RealVect& a_origin,
00206 const Real& a_dx,
00207 const int a_ncellmax);
00208
00209
00210 void operator=(const EBISLevel& ebiin)
00211 {
00212 MayDay::Error("EBISLevel::operator= not allowed");
00213 }
00214
00215 EBISLevel(const EBISLevel& ebiin)
00216 {
00217 MayDay::Error("EBISLevel::copy constructor not allowed");
00218 }
00219
00220 Real m_tolerance;
00221
00222 bool match(const Real& a, const Real& b) const;
00223
00224 bool match(const RealVect& a, const RealVect& b) const;
00225
00226 void refreshCache() const ;
00227 mutable std::map<int, dmap> cache;
00228 mutable int m_cacheMisses, m_cacheHits, m_cacheStale;
00229
00230 friend class EBIndexSpace;
00231 };
00232
00234
00240 class EBIndexSpace
00241 {
00242 public:
00243
00244 EBIndexSpace();
00246
00251 void
00252 define(const ProblemDomain& a_domain,
00253 const RealVect& a_origin,
00254 const Real& a_dx,
00255 const GeometryService& a_geoserver,
00256 int a_nCellMax = -1,
00257 int maxCoarsenings = -1);
00258
00259 #ifdef CH_USE_HDF5
00261 void
00262 define(HDF5Handle& handle, int maxCoarsenings = -1);
00263 #endif
00264
00265 void
00266 define(EBISLevel* level0,
00267 int a_nCellMax = -1,
00268 int a_maxCoarsenings = -1);
00269
00270 EBISLevel* buildFirstLevel(const ProblemDomain& a_domain,
00271 const RealVect& a_origin,
00272 const Real& a_dx,
00273 const GeometryService& a_geoserver,
00274 int a_nCellMax,
00275 int a_maxCoarsenings);
00276
00277 EBISLevel* buildNextLevel(const GeometryService& a_geoserver);
00278
00280 ~EBIndexSpace();
00281
00283 int numLevels() const;
00284
00286
00290 int numVoFs(const ProblemDomain& a_domain) const;
00291
00293
00298 int getLevel(const ProblemDomain& a_domain) const;
00299
00300 RealVect getOrigin() const {return m_ebisLevel[0]->getOrigin();}
00302
00305 const ProblemDomain& getBox(int level) const
00306 {
00307 return m_domainLevel[level];
00308 }
00309
00311 void fillEBISLayout(EBISLayout& a_ebis,
00312 const DisjointBoxLayout& a_grids,
00313 const ProblemDomain& a_domain,
00314 const int & nghost) const;
00315
00317
00320 bool isDefined() const;
00321
00323 void clear();
00324
00325 int getNCellMax() const;
00327
00331 friend class Chombo_EBIS;
00332
00333 #ifdef CH_USE_HDF5
00335
00339 void
00340 write(HDF5Handle& handle,
00341 ProblemDomain a_outputLevel = ProblemDomain());
00342
00343 void
00344 writeInfo(HDF5Handle& handle) const ;
00345
00346 #endif
00347
00348 DisjointBoxLayout getIrregGrids(int level) const
00349 { return m_ebisLevel[level]->getIrregGrids();}
00350
00351 DisjointBoxLayout getFlowGrids(int level) const
00352 { return m_ebisLevel[level]->getFlowGrids();}
00353
00354 DisjointBoxLayout levelGrids(int level) const
00355 { return m_ebisLevel[level]->m_grids;}
00356
00357 Real dx(int level) const
00358 { return m_ebisLevel[level]->m_dx;}
00359
00360 IntVectSet irregCells(int depth=0) const
00361 {
00362 return m_ebisLevel[depth]->irregCells();
00363 }
00364
00365 void setCellMax(int max) {m_nCellMax = max;}
00366
00367 void resetLevels(int nLevel);
00368
00369 static bool s_MFSingleBox;
00370 private:
00371
00372
00373
00374 int m_nCellMax;
00375 bool m_isDefined;
00376
00377 Vector<EBISLevel*> m_ebisLevel;
00378 Vector<ProblemDomain> m_domainLevel;
00379 int m_nlevels;
00380 static Real s_tolerance;
00381 static bool s_verbose;
00382
00383
00384 void operator=(const EBIndexSpace& ebiin)
00385 {
00386 MayDay::Error("no assignment of EBIndexSpace allowed");
00387 }
00388 EBIndexSpace(const EBIndexSpace& ebiin)
00389 {
00390 MayDay::Error("no copy construction of EBIndexSpace allowed");
00391 }
00392 };
00393
00394 inline
00395 bool EBISLevel::match(const Real& a, const Real& b) const
00396 {
00397 return a<b+m_tolerance && a>b-m_tolerance;
00398 }
00399
00400 inline
00401 bool EBISLevel::match(const RealVect& a, const RealVect& b) const
00402 {
00403 return D_TERM( a[0]<b[0]+m_tolerance && a[0]>b[0]-m_tolerance, &&
00404 a[1]<b[1]+m_tolerance && a[1]>b[1]-m_tolerance, &&
00405 a[2]<b[2]+m_tolerance && a[2]>b[2]-m_tolerance) ;
00406 }
00407
00408 #include "NamespaceFooter.H"
00409 #endif