Chombo + EB  3.0
EBIndexSpace.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // ANAG, LBNL, DTG
12 
13 #ifndef _EBINDEXSPACE_H_
14 #define _EBINDEXSPACE_H_
15 
16 #include "REAL.H"
17 #include "IntVect.H"
18 #include "IntVectSet.H"
19 #include "VolIndex.H"
20 #include "FaceIndex.H"
21 #include "IntVectSet.H"
22 #include "DisjointBoxLayout.H"
23 #include "LevelData.H"
24 #include "EBISBox.H"
25 #include "GeometryService.H"
26 #include "EBISLayout.H"
27 #include "CH_HDF5.H"
28 #include <map>
29 
30 #include "NamespaceHeader.H"
31 
32 typedef std::map<DisjointBoxLayout, EBISLayout> dmap;
33 
34 class EBIndexSpace;
35 
36 ///singleton version of EBIndexSpace.
38 {
39 private:
40  ///
41  /**
42  This is NULL until the first time
43  instance() is called.
44  On the first time it is called it
45  is set to new EBIndexSpace();
46  After that it points to the same
47  thing.
48  */
50 
52  {;}
53 
55  {;}
56 
57  ///if you want to sneak an existing EBIS into the singleton.
58  static bool s_aliased;
59 public:
60  ///
61  /**
62  Return a pointer to the singleton
63  EBIndexSpace. Until this is called
64  once, the singleton is null. See
65  Design patterns for why this is done
66  this way.
67  */
68  static EBIndexSpace* instance();
69 
70  ///
71  static void alias(const EBIndexSpace* a_input);
72 };
73 
74 ///
75 /**
76  EBISLevel represents the geometric information
77  of the domain at a particular level of refinement.
78 */
79 class EBISLevel
80 {
81 public:
82  void dumpDebug(const string& a_string);
83 
84  void coarsenVoFs(EBISLevel& a_fineEBIS);
85 
86  void fixFineToCoarse(EBISLevel& a_fineEBIS);
87 
88  void coarsenFaces(EBISLevel& a_fineEBIS);
89 
90  int numVoFsOnProc() const;
91 
92  void levelStitch(EBISLevel& a_otherPhase,
93  const EBISLevel* a_fineThisPtr,
94  const EBISLevel* a_fineOtherPtr); // MF Addition bvs
95 
96  void reconcileIrreg(EBISLevel & a_otherPhase);
97 
98  void cellStitch(EBData& a_ebdataCoarA,
99  EBData& a_ebdataCoarB,
100  const EBGraph& a_ebgrapCoarA,
101  const EBGraph& a_ebgrapCoarB,
102  const EBISBox& a_ebisbxFineA,
103  const EBISBox& a_ebisbxFineB,
104  const IntVect& a_iv,
105  const int& a_aphase,
106  const int& a_bphase);
107  EBISLevel();
108 
109  ///
110  /**
111  Defines the level. Calls the geoserver
112  to fill the layout with geometric information.
113  */
114  EBISLevel(const ProblemDomain & a_domain,
115  const RealVect & a_origin,
116  const Real & a_dx,
117  const GeometryService & a_geoserver,
118  const EBIndexSpace * const a_ebisPtr = Chombo_EBIS::instance(),
119  const bool & a_distributedData = false,
120  const bool & a_fixRegularNextToMultiValued = true);
121 
122  ///
123  /**
124  Defines the level from a finer level
125  (factor of two refinement ratio).
126  Fills in all the coarse-fine information
127  in both levels.
128  */
129  EBISLevel(EBISLevel & a_finerLevel,
130  const GeometryService & a_geoserver,
131  const EBIndexSpace * const a_ebisPtr = Chombo_EBIS::instance(),
132  const bool & a_distributedData = false,
133  const bool & a_fixRegularNextToMultiValued = true);
134 
135 #ifdef CH_USE_HDF5
136  /// read from file
137  EBISLevel(HDF5Handle& handle);
138 
139  ///
140  void write(HDF5Handle& a_handle) const;
141 #endif
142 
143  ///
144  /**
145  Checks to see the vofs are in the correct cells.
146  Checks to see that the faces are over the correct cells.
147  Checks that volume fractions, area fractions are positive.
148  Bail out with MayDay::Error if anything fails.
149  */
150  void sanityCheck(const EBIndexSpace* const a_ebisPtr = Chombo_EBIS::instance());
151 
152  ///
153  void fillEBISLayout(EBISLayout& a_ebis,
154  const DisjointBoxLayout& a_grids,
155  const int& a_nghost) const;
156 
157  ~EBISLevel();
158 
159  const ProblemDomain& getDomain() const;
160 
161  const DisjointBoxLayout& getGrids() const;
162 
163  DisjointBoxLayout getIrregGrids() const;
164 
165  DisjointBoxLayout getFlowGrids() const;
166 
167  IntVectSet irregCells() const;
168 
169  const Real& getDX() const;
170 
171  const RealVect& getOrigin() const;
172 
173  ///
174  void fixRegularNextToMultiValued();
175 
176  void clearMultiBoundaries();
177  void setBoundaryPhase(int phase);
178 
179  int m_phase;
180 
181 
182 private:
183 
184  ///
186 
187  ///
189 
190  ///
192 
193  ///
195 
196  ///
198 
199  ///
201 
202  Real m_tolerance; // used in Multifluid face matching algorithm.
203 
204  mutable std::map<int, dmap> m_cache;
205 
206  mutable int m_cacheMisses, m_cacheHits, m_cacheStale;
207 
209  static bool s_verbose;
210 
211  //make grids for this level.
212 
213  static void makeBoxes(Vector<Box>& a_boxes,
214  Vector<long>& a_irregCount,
215  const Box& a_region,
216  const ProblemDomain& a_domain,
217  const GeometryService& a_geoserver,
218  const RealVect& a_origin,
219  const Real& a_dx,
220  const int a_ncellmax,
221  const EBIndexSpace* const a_ebisPtr);
222 
223  static void makeBoxes(std::list<Box>& a_boxes,
224  const Box& a_region,
225  const ProblemDomain& a_domain,
226  const GeometryService& a_geoserver,
227  const RealVect& a_origin,
228  const Real& a_dx,
229  const int a_ncellmax);
230 
231  //these are disallowed
232  void operator=(const EBISLevel& ebiin)
233  {
234  MayDay::Error("EBISLevel::operator= not allowed");
235  }
236 
237  EBISLevel(const EBISLevel& ebiin)
238  {
239  MayDay::Error("EBISLevel::copy constructor not allowed");
240  }
241 
242  bool match(const Real& a_a,
243  const Real& a_b) const;
244 
245  bool match(const RealVect& a_a,
246  const RealVect& a_b) const;
247 
248  void refreshCache() const;
249 
250  friend class EBIndexSpace;
251 };
252 
253 ///
254 /**
255  EBIndexSpace represents the geometric information
256  of the domain. It should be generated through
257  the Chombo_EBIS class. This follows the singleton
258  pattern.
259 */
261 {
262 public:
263 
264  EBIndexSpace();
265 
266  ///
267  /**
268  If a_ncellMax is set, that is the max width of
269  an internal grid. Otherwise use defaults
270  of (16 in 3D, 64 in 2d)
271  */
272  void
273  define(const ProblemDomain & a_domain,
274  const RealVect & a_origin,
275  const Real & a_dx,
276  const GeometryService & a_geoserver,
277  int a_nCellMax = -1,
278  int a_maxCoarsenings = -1);
279 
280 #ifdef CH_USE_HDF5
281  ///
282  void
283  define(HDF5Handle & a_handle,
284  int a_maxCoarsenings = -1);
285 #endif
286 
287  void
288  define(EBISLevel * a_level0,
289  int a_nCellMax = -1,
290  int a_maxCoarsenings = -1);
291 
292  void
293  define(const ProblemDomain & a_entireDomain,
294  const RealVect & a_origin,
295  const Real & a_dx,
296  const Vector<RefCountedPtr<EBIndexSpace> > & a_patches,
297  const Vector<IntVect> & a_offsets,
298  int a_maxCoarsenings = -1);
299 
300  EBISLevel* buildFirstLevel(const ProblemDomain& a_domain,
301  const RealVect& a_origin,
302  const Real& a_dx,
303  const GeometryService& a_geoserver,
304  int a_nCellMax,
305  int a_maxCoarsenings,
306  bool a_fixRegularNextToMultiValued = true);
307 
308  EBISLevel* buildNextLevel(const GeometryService & a_geoserver,
309  bool a_fixRegularNextToMultiValued = true);
310 
311  ///
312  ~EBIndexSpace();
313 
314  ///
315  /**
316  Set a flag that indicates the data defining the EB is distributed.
317  This will signal EBISLevel to hand grid generation off to the
318  GeometryService. Function returns previous value of m_distributedData.
319  Call this before define() if this functionality is desired.
320  */
322  {
323  bool was = m_distributedData;
324  m_distributedData = true;
325  return was;
326  }
327 
328  ///
329  int numLevels() const;
330 
331  ///
332  /**
333  Get the number of vofs over the entire domain.
334  This is blocking as a broadcast and gather are required.
335  */
336  int numVoFs(const ProblemDomain& a_domain) const;
337 
338  ///
339  /**
340  return level index of domain.
341  return -1 if a_domain does not
342  correspond to any refinement of EBIS.
343  */
344  int getLevel(const ProblemDomain& a_domain) const;
345 
347  {
348  return m_ebisLevel[0]->getOrigin();
349  }
350 
351  ///
352  /**
353  returns the problem domain box at a level of refinement
354  */
355  const ProblemDomain& getBox(int level) const
356  {
357  return m_domainLevel[level];
358  }
359 
360  ///
361  void fillEBISLayout(EBISLayout& a_ebis,
362  const DisjointBoxLayout& a_grids,
363  const ProblemDomain& a_domain,
364  const int& a_nghost) const;
365 
366  ///
367  /**
368  Return true if the define function has been called.
369  */
370  bool isDefined() const;
371 
372  ///
373  void clear();
374 
375  int getNCellMax() const;
376  ///
377  /**
378  This makes Chombo_EBIS be the only function
379  that can call the private constructor.
380  */
381  friend class Chombo_EBIS;
382 
383 #ifdef CH_USE_HDF5
384  ///
385  /**
386  Writes out finest level as a default. Writes at the level you are domain
387  you want if a_outputLevel is defined.
388  */
389  void
390  write(HDF5Handle& a_handle,
391  ProblemDomain a_outputLevel = ProblemDomain()) const;
392 
393  void
394  writeInfo(HDF5Handle& handle) const ;
395 
396 #endif
397 
399  {
400  return m_ebisLevel[level]->getIrregGrids();
401  }
402 
404  {
405  return m_ebisLevel[level]->getFlowGrids();
406  }
407 
408  DisjointBoxLayout levelGrids(int level) const
409  {
410  return m_ebisLevel[level]->m_grids;
411  }
412 
413  Real dx(int level) const
414  {
415  return m_ebisLevel[level]->m_dx;
416  }
417 
418  IntVectSet irregCells(int depth=0) const
419  {
420  return m_ebisLevel[depth]->irregCells();
421  }
422 
423  void setCellMax(int max)
424  {
425  m_nCellMax = max;
426  }
427 
428  void resetLevels(int nLevel);
429 
430  Vector<RefCountedPtr<EBIndexSpace> > connectedComponents();
431 
432  RefCountedPtr<EBIndexSpace> biggestConnectedComponent(int & a_numComponents);
433 
434  static bool s_MFSingleBox;
435 
436 private:
437  Vector<RefCountedPtr<EBIndexSpace> > findConnectedComponents(int & a_numComponents,
438  const bool & a_onlyBiggest);
439 
440  bool setAllConnectedVoFs(Real& a_totalVolFrac,
441  EBCellFAB& a_curEBCellFAB,
442  const EBGraph& a_curEBGraph,
443  const EBISBox& a_curEBISBox,
444  const VolIndex& a_curVoF,
445  const VolIndex& a_lastVoF,
446  const unsigned int& a_curNum);
447 
448  void resetAllConnectedVoFs(EBCellFAB& a_curEBCellFAB,
449  const EBGraph& a_curEBGraph,
450  const EBISBox& a_curEBISBox,
451  const VolIndex& a_curVoF,
452  const VolIndex& a_lastVoF);
453 
454  //this is private to force the singleton thing.
455  //EBIndexSpace();
456 
459 
461 
464 
466 
468  static bool s_verbose;
469 
470  //disallowed for performance reasons
471  void operator=(const EBIndexSpace& ebiin)
472  {
473  MayDay::Error("no assignment of EBIndexSpace allowed");
474  }
475 
477  {
478  MayDay::Error("no copy construction of EBIndexSpace allowed");
479  }
480 };
481 
482 inline bool EBISLevel::match(const Real& a_a,
483  const Real& a_b) const
484 {
485  return (a_a < (a_b + m_tolerance)) && (a_a > (a_b - m_tolerance));
486 }
487 
488 inline bool EBISLevel::match(const RealVect& a_a,
489  const RealVect& a_b) const
490 {
491  return D_TERM6( (a_a[0] < (a_b[0] + m_tolerance)) &&
492  (a_a[0] > (a_b[0] - m_tolerance)),
493  &&
494  (a_a[1] < (a_b[1] + m_tolerance)) &&
495  (a_a[1] > (a_b[1] - m_tolerance)),
496  &&
497  (a_a[2] < (a_b[2] + m_tolerance)) &&
498  (a_a[2] > (a_b[2] - m_tolerance)),
499  &&
500  (a_a[3] < (a_b[3] + m_tolerance)) &&
501  (a_a[3] > (a_b[3] - m_tolerance)),
502  &&
503  (a_a[4] < (a_b[4] + m_tolerance)) &&
504  (a_a[4] > (a_b[4] - m_tolerance)),
505  &&
506  (a_a[5] < (a_b[5] + m_tolerance)) &&
507  (a_a[5] > (a_b[5] - m_tolerance)));
508 }
509 
510 #include "NamespaceFooter.H"
511 
512 #endif
int m_nlevels
Definition: EBIndexSpace.H:465
IntVectSet irregCells(int depth=0) const
Definition: EBIndexSpace.H:418
DisjointBoxLayout getIrregGrids(int level) const
Definition: EBIndexSpace.H:398
static bool s_verbose
Definition: EBIndexSpace.H:468
Vector< EBISLevel * > m_ebisLevel
Definition: EBIndexSpace.H:462
A reference-counting handle class.
Definition: RefCountedPtr.H:66
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
DisjointBoxLayout getFlowGrids(int level) const
Definition: EBIndexSpace.H:403
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
DisjointBoxLayout levelGrids(int level) const
Definition: EBIndexSpace.H:408
Definition: EBIndexSpace.H:260
Chombo_EBIS()
Definition: EBIndexSpace.H:51
static Real s_tolerance
Definition: EBIndexSpace.H:467
std::map< int, dmap > m_cache
Definition: EBIndexSpace.H:204
int m_nCellMax
Definition: EBIndexSpace.H:457
Definition: EBISBox.H:46
DisjointBoxLayout m_grids
Definition: EBIndexSpace.H:185
~Chombo_EBIS()
Definition: EBIndexSpace.H:54
Definition: EBIndexSpace.H:79
bool m_isDefined
Definition: EBIndexSpace.H:458
RealVect m_origin
Definition: EBIndexSpace.H:191
bool setDistributedData()
Definition: EBIndexSpace.H:321
singleton version of EBIndexSpace.
Definition: EBIndexSpace.H:37
RealVect getOrigin() const
Definition: EBIndexSpace.H:346
Real dx(int level) const
Definition: EBIndexSpace.H:413
Vector< ProblemDomain > m_domainLevel
Definition: EBIndexSpace.H:463
int m_cacheStale
Definition: EBIndexSpace.H:206
Geometric description within a box.
Definition: EBGraph.H:432
Definition: EBData.H:321
LevelData< EBGraph > m_graph
Definition: EBIndexSpace.H:197
static void alias(const EBIndexSpace *a_input)
EBISLevel(const EBISLevel &ebiin)
Definition: EBIndexSpace.H:237
static EBIndexSpace * instance()
static bool s_aliased
if you want to sneak an existing EBIS into the singleton.
Definition: EBIndexSpace.H:58
void operator=(const EBIndexSpace &ebiin)
Definition: EBIndexSpace.H:471
Definition: EBCellFAB.H:29
LevelData< EBData > m_data
Definition: EBIndexSpace.H:200
double Real
Definition: REAL.H:33
Definition: GeometryService.H:37
ProblemDomain m_domain
Definition: EBIndexSpace.H:188
IndexTM< T, N > max(const IndexTM< T, N > &a_p1, const IndexTM< T, N > &a_p2)
Definition: IndexTMI.H:403
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
EBIndexSpace(const EBIndexSpace &ebiin)
Definition: EBIndexSpace.H:476
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
int write(HDF5Handle &a_handle, const BoxLayout &a_layout, const std::string &name="boxes")
writes BoxLayout to HDF5 file.
bool m_distributedData
Definition: EBIndexSpace.H:460
static EBIndexSpace * s_instance
Definition: EBIndexSpace.H:49
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
Real m_dx
Definition: EBIndexSpace.H:194
static Real s_tolerance
Definition: EBIndexSpace.H:208
Real m_tolerance
Definition: EBIndexSpace.H:202
void setCellMax(int max)
Definition: EBIndexSpace.H:423
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:267
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Volume of Fluid Index.
Definition: VolIndex.H:31
const ProblemDomain & getBox(int level) const
Definition: EBIndexSpace.H:355
Definition: EBISLayout.H:39
std::map< DisjointBoxLayout, EBISLayout > dmap
Definition: EBIndexSpace.H:32
bool match(const Real &a_a, const Real &a_b) const
Definition: EBIndexSpace.H:482
static bool s_MFSingleBox
Definition: EBIndexSpace.H:434
void operator=(const EBISLevel &ebiin)
Definition: EBIndexSpace.H:232
static bool s_verbose
Definition: EBIndexSpace.H:209
int m_phase
Definition: EBIndexSpace.H:179