Chombo + EB + MF  3.2
BaseEBCellFABI.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
12 
13 #ifndef _BASEEBCELLFABI_H_
14 #define _BASEEBCELLFABI_H_
15 
16 #include "BoxIterator.H"
17 #include "CH_Timer.H"
18 #include "NamespaceHeader.H"
19 /**********************/
20 /**********************/
21 template <class T>
22 void
24  const int& a_comp,
25  const bool& a_doMulti)
26 {
27  CH_TIME("BaseEBCellFAB::setCoveredCellVal");
28  CH_assert(a_comp >= 0);
29  CH_assert(a_comp < m_regFAB.nComp());
30 
31  if (m_ebisBox.isAllRegular())
32  {
33  return;
34  }
35  else if (m_ebisBox.isAllCovered())
36  {
37  m_regFAB.setVal(a_val, a_comp);
38  }
39  else
40  {
41  for (BoxIterator bit(getRegion()); bit.ok(); ++bit)
42  {
43  const IntVect& iv = bit();
44  if (m_ebisBox.isCovered(iv))
45  {
46  m_regFAB(iv, a_comp) = a_val;
47  }
48  }
49  if (a_doMulti && m_irrFAB.numVoFs()>0)
50  {
51  const Vector<VolIndex>& vofs = m_irrFAB.getVoFs();
52  for (int i=0; i< vofs.size(); i++)
53  {
54  const IntVect& iv = vofs[i].gridIndex();
55  m_regFAB(iv, a_comp) = a_val;
56  }
57  }
58  }
59 }
60 /*************/
61 // alias constructor
62 template <class T>
64 :m_irrFAB(a_interval,a_original.m_irrFAB),
65  m_regFAB(a_interval,a_original.m_regFAB),
66  m_ebisBox(a_original.m_ebisBox),
67  m_region(a_original.m_region),
68  m_hasMultiCells(a_original.m_hasMultiCells),
69  m_isDefined(a_original.m_isDefined)
70 {
71  if(!m_isDefined) MayDay::Error("Calling alias constructor on undefined BaseEBCellFAB. Probably an earlier error");
72 
73 }
74 /*************/
75 template <class T>
78 {
79  CH_TIMERS("BaseEBCellFAB::copy");
80  CH_TIMER("sameregion_copy", t1);
81  CH_TIMER("overlap_copy", t2);
83  CH_assert(a_src.isDefined());
84  // CH_assert(m_ebisBox == a_src.m_ebisBox);));
85 
86  int ncomp=m_regFAB.nComp();
87  Interval comps(0,ncomp-1);
88 
89  if (getRegion() == a_src.getRegion())
90  {
91  CH_START(t1);
92  m_regFAB.copy(a_src.m_regFAB);
93 
94  if (m_hasMultiCells)
95  {
96  const T* src = a_src.m_irrFAB.dataPtr(0);
97  T* dest = m_irrFAB.dataPtr(0);
98  T* end = dest + m_irrFAB.numVoFs()*ncomp;
99  for (; dest<end ; src++, dest++)
100  {
101  *dest = *src;
102  }
103  }
104  CH_STOP(t1);
105  }
106  else
107  {
108  CH_START(t2);
109  Box overlap(getRegion());
110  overlap &= a_src.getRegion();
111 
112  this->copy(overlap,comps,overlap,a_src,comps);
113  CH_STOP(t2);
114  }
115 
116  return *this;
117 }
118 
119 /*************/
120 /*************/
121 template <class T>
122 void
123 BaseEBCellFAB<T>::copy(const Box& a_RegionFrom,
124  const Interval& a_dstInt,
125  const Box& a_RegionTo,
126  const BaseEBCellFAB<T>& a_src,
127  const Interval& a_srcInt)
128 {
129  CH_TIME("BaseEBCellFAB::copy");
130  CH_assert(isDefined());
131  CH_assert(a_dstInt.size()==a_srcInt.size());
132  CH_assert(a_dstInt.begin()>=0);
133  CH_assert(a_srcInt.begin()>=0);
134 
135  ProblemDomain domain = m_ebisBox.getDomain();
136  bool isPeriodic = domain.isPeriodic();
137  Box intersect = a_RegionFrom & domain.domainBox();
138  if ( (!isPeriodic) &&
139  (!intersect.isEmpty()) &&
140  (!m_ebisBox.getRegion().contains(intersect)) )
141  {
142  MayDay::Error("BaseEBCellFAB::copy: I was probably defined with too small an ebisBox");
143  }
144 
145  CH_assert( (a_RegionFrom == a_RegionTo) || isPeriodic);
146  {
147  CH_TIME("BaseEBCellFAB::regcopy");
148  m_regFAB.copy(a_RegionFrom, a_dstInt, a_RegionTo, a_src.m_regFAB, a_srcInt);
149  }
150 
151  if (m_hasMultiCells)
152  {
153  CH_TIME("BaseEBCellFAB::irrcopy");
154  m_irrFAB.copy(a_RegionFrom, a_dstInt, a_RegionTo, a_src.m_irrFAB, a_srcInt);
155  }
156 }
157 
158 /*************/
159 /*************/
160 template <class T>
161 int
162 BaseEBCellFAB<T>::size(const Box& R, const Interval& comps) const
163 {
164  CH_TIME("BaseEBCellFAB::size");
165  int retval = m_regFAB.size(R, comps);
166  retval += m_irrFAB.size(R, comps);
167  return retval;
168 }
169 
170 /*************/
171 template <class T>
172 void
173 BaseEBCellFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
174  const
175 {
176  CH_TIME("BaseEBCellFAB::linearOut");
177  unsigned char* buffer = (unsigned char*)buf;
178  m_regFAB.linearOut(buffer, R, comps);
179  buffer+= m_regFAB.size(R, comps);
180  m_irrFAB.linearOut(buffer, R, comps);
181 }
182 /*************/
183 /*************/
184 template <class T>
185 void
186 BaseEBCellFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
187 {
188  CH_TIME("BaseEBCellFAB::linearIn");
189  unsigned char* buffer = (unsigned char*)buf;
190  m_regFAB.linearIn(buffer, R, comps);
191  buffer+= m_regFAB.size(R, comps);
192  m_irrFAB.linearIn(buffer, R, comps);
193 }
194 
195 /*************/
196 /*************/
197 template <class T>
200 {
201  Vector<VolIndex> retval;
202  CH_assert(isDefined());
203  if(m_irrFAB.hasVoFs())
204  {
205  retval = m_irrFAB.getVoFs();
206  }
207  return retval;
208 }
209 
210 /*************/
211 /*************/
212 template <class T>
214 {
216 }
217 
218 /*************/
219 /*************/
220 template <class T>
222  const Box& a_region, int a_nVar)
223 {
225  define(a_ebisBox, a_region, a_nVar);
226 }
227 
228 /*************/
229 /*************/
230 template <class T>
231 void
233  const Box& a_region, int a_nVar)
234 {
235  CH_TIME("BaseEBCellFAB::define");
236  clear();
237  m_isDefined = true;
238  CH_assert(a_region.cellCentered());
239  CH_assert(a_nVar > 0);
240  CH_assert(!a_region.isEmpty());
241 
242  m_region = a_region & a_ebisBox.getRegion();
243  m_ebisBox = a_ebisBox;
244 
245  //make reg fab the full size of the box.
246  //this makes ebalias possible
247  m_regFAB.resize(a_region, a_nVar);
248  //add all the multi-valued
249  //cells to m_multiValued
251 
252  m_hasMultiCells = !multiCells.isEmpty();
253 
254  //define irregular fab to be over multi-valued cells.
255  m_irrFAB.define(multiCells, m_ebisBox.getEBGraph(), a_nVar);
256 }
257 
258 /*************/
259 /*************/
260 template <class T>
263 {
264  clear();
265 }
266 
267 /*************/
268 /*************/
269 template <class T>
270 void
272 {
273  //m_irrFAB.clear();
274  m_regFAB.clear();
275  // m_multiCells.makeEmpty();
276 
277  m_isDefined = false;
278 }
279 /*************/
280 /*************/
281 template <class T>
282 void
284 {
285  m_irrFAB.setVal(value);
286  m_regFAB.setVal(value);
287 }
288 
289 /*************/
290 template <class T>
291 void
292 BaseEBCellFAB<T>::setVal(int ivar,const T& value)
293 {
294  m_irrFAB.setVal(ivar, value);
295  m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
296 }
297 /*************/
298 template <class T>
299 void
300 BaseEBCellFAB<T>::setVal(const T& a_value,
301  const Box& a_box,
302  int a_nstart,
303  int a_numcomp)
304 {
305  CH_assert(isDefined());
306  if (!a_box.isEmpty())
307  {
308  m_irrFAB.setVal(a_value,a_box,a_nstart,a_numcomp);
309  m_regFAB.setVal(a_value,a_box,a_nstart,a_numcomp);
310  }
311 }
312 
313 /*************/
314 /*************/
315 template <class T>
316 bool
318 {
319  return (m_isDefined);
320 }
321 /*************/
322 /*************/
323 template <class T>
324 int
326 {
327  CH_assert(isDefined());
328  return m_regFAB.nComp();
329 }
330 /*************/
331 /*************/
332 template <class T>
333 const Box&
335 {
336  CH_assert(isDefined());
337  return m_region;
338 }
339 /*************/
340 /*************/
341 template <class T>
342 const Box&
344 {
345  return getRegion();
346 }
347 
348 /*************/
349 /*************/
350 template <class T>
351 const BaseIVFAB<T>&
353 {
354  CH_assert(isDefined());
355  return m_irrFAB;
356 }
357 
358 //
359 /*************/
360 /*************/
361 template <class T>
364 {
365  CH_assert(isDefined());
366  return m_irrFAB;
367 }
368 
369 /*************/
370 /*************/
371 template <class T>
372 const BaseFab<T>&
374 {
375  CH_assert(isDefined());
376  return m_regFAB;
377 }
378 
379 //
380 /*************/
381 /*************/
382 template <class T>
383 BaseFab<T>&
385 {
386  CH_assert(isDefined());
387  return m_regFAB;
388 }
389 /*************/
390 
391 /*************
392  Arg a_isKnownMultiValued should be set to:
393  -1 if arg a_ndin is known to be in a single-valued cell;
394  +1 if arg a_ndin is known to be in a multi-valued cell;
395  0 if you're not sure (in which case the expensive IntVectSet::contains()
396  function gets called).
397 */
398 template <class T>
399 const T&
400 BaseEBCellFAB<T>::operator()(const VolIndex& a_ndin,int a_nVarLoc,
401  int a_isKnownMultiValued ) const
402 {
403  CH_assert(isDefined());
405  //CH_assert(getRegion().contains(a_ndin.gridIndex())); caught in m_regFAB
406  CH_assert((a_nVarLoc >= 0)&&(a_nVarLoc < nComp()));
407  CH_assert( (a_isKnownMultiValued == -1)
408  || (a_isKnownMultiValued == 0)
409  || (a_isKnownMultiValued == +1) );
410 
411  const T* returnval = NULL;
412 
413  switch( a_isKnownMultiValued )
414  {
415  case -1:
416  returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
417  break; // m_regFAB is a BaseFab
418  case +1:
419  returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
420  break; // m_irrFAB is a BaseIVFAB
421  case 0:
422  {
423  if ( m_ebisBox.isMultiValued(a_ndin.gridIndex()))
424  {
425  returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
426  } else
427  {
428  returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
429  }
430  }
431  }
432 
433  return *returnval;
434 
435 }
436 
437 /************
438  See comment for const version of this function.
439 */
440 template <class T>
441 T&
442 BaseEBCellFAB<T>::operator()(const VolIndex& a_ndin,int a_nVarLoc,
443  int a_isKnownMultiValued )
444 {
445  CH_assert(isDefined());
446  CH_assert(getRegion().contains(a_ndin.gridIndex()));
447  CH_assert((a_nVarLoc >= 0)&&(a_nVarLoc < nComp()));
449  CH_assert( (a_isKnownMultiValued == -1)
450  || (a_isKnownMultiValued == 0)
451  || (a_isKnownMultiValued == +1) );
452 
453  T* returnval = NULL;
454 
455  if ( (a_isKnownMultiValued == -1) || !m_hasMultiCells)
456  {
457  returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
458  }
459  else if (a_isKnownMultiValued == 1)
460  {
461  returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
462  }
463  else if (a_isKnownMultiValued == 0)
464  {
465  if ( m_ebisBox.isMultiValued(a_ndin.gridIndex()) )
466  {
467  returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
468  }
469  else
470  {
471  returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
472  }
473  }
474  else
475  {
476  MayDay::Error("bogus a_isKnownMultiValued input");
477  }
478 
479  return *returnval;
480 }
481 
482 
483 template <class T>
484 void
485 BaseEBCellFAB<T>::fill(T* array, const VolIndex& a_ndin, const Interval& a_comps) const
486 {
487  CH_TIME("BaseEBCellFAB::fill");
488  CH_assert(isDefined());
489  CH_assert(getRegion().contains(a_ndin.gridIndex()));
491 
492  if (m_ebisBox.isMultiValued(a_ndin.gridIndex()))
493  {
494  const T* val = &(m_irrFAB(a_ndin,a_comps.begin()));
495  for (int i=0; i<a_comps.size(); i++)
496  {
497  array[i] = val[i];
498  }
499 
500  }
501  else
502  {
503  const T* val = &(m_regFAB(a_ndin.gridIndex(), a_comps.begin()));
504  int numPts = m_regFAB.box().numPts();
505  for (int i=0; i<a_comps.size(); i++)
506  {
507  array[i] = val[i*numPts];
508  }
509 
510  }
511 
512 }
513 
514 template <class T>
515 void
517  const VolIndex& a_ndin,
518  const Interval& a_comps)
519 {
520  CH_TIME("BaseEBCellFAB::assign");
521  CH_assert(isDefined());
522  CH_assert(getRegion().contains(a_ndin.gridIndex()));
524 
525  if (m_ebisBox.isMultiValued(a_ndin.gridIndex()))
526  {
527  T* val = &(m_irrFAB(a_ndin,a_comps.begin()));
528  for (int i=0; i<a_comps.size(); i++)
529  {
530  val[i] = array[i];
531  }
532 
533  }
534  else
535  {
536  T* val = &(m_regFAB(a_ndin.gridIndex(), a_comps.begin()));
537  int numPts = m_regFAB.box().numPts();
538  for (int i=0; i<a_comps.size(); i++)
539  {
540  val[i*numPts] = array[i];
541  }
542 
543  }
544 
545 }
546 
547  /*************/
548 /*************/
549 template <class T>
550 void
552 {
553  m_isDefined = false;
554 
555 }
556 /*************/
557 /*************/
558 template <class T>
559 const EBISBox&
561 {
562  return m_ebisBox;
563 }
564 
565 #include "NamespaceFooter.H"
566 #endif
bool m_hasMultiCells
Definition: BaseEBCellFAB.H:268
bool ok()
Definition: BoxIterator.H:281
#define CH_TIMERS(name)
Definition: CH_Timer.H:133
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseEBCellFABI.H:186
EBISBox m_ebisBox
Definition: BaseEBCellFAB.H:264
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
#define CH_assert(cond)
Definition: CHArray.H:37
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
bool isCovered(const IntVect &a_iv) const
Definition: EBISBox.H:399
const EBGraph & getEBGraph() const
void fill(T *array, const VolIndex &a_ndin, const Interval &a_comps) const
Definition: BaseEBCellFABI.H:485
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseEBCellFABI.H:173
bool cellCentered() const
Definition: Box.H:1939
Vector< VolIndex > getMultiCells() const
has to be by value because sometimes the vector does not exist.
Definition: BaseEBCellFABI.H:199
IntVectSet getMultiCells(const Box &a_subbox) const
const ProblemDomain & getDomain() const
int size() const
Definition: Interval.H:75
int begin() const
Definition: Interval.H:99
bool isMultiValued(const IntVect &a_iv) const
Definition: EBISBox.H:405
#define CH_START(tpointer)
Definition: CH_Timer.H:145
Definition: EBISBox.H:46
const IntVect & gridIndex() const
Definition: VolIndex.H:125
const BaseIVFAB< T > & getMultiValuedFAB() const
Definition: BaseEBCellFABI.H:352
bool contains(const IntVect &p) const
Definition: Box.H:1887
const BaseFab< T > & getSingleValuedFAB() const
Definition: BaseEBCellFABI.H:373
iterates through the IntVects of a Box
Definition: BoxIterator.H:37
void copy(const Box &RegionFrom, const Interval &destInt, const Box &RegionTo, const BaseEBCellFAB< T > &source, const Interval &srcInt)
Definition: BaseEBCellFABI.H:123
const Box & getRegion() const
Definition: BaseEBCellFABI.H:334
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:63
const EBISBox & getEBISBox() const
Definition: BaseEBCellFABI.H:560
const Box & box() const
Definition: BaseEBCellFABI.H:343
virtual void setCoveredCellVal(const T &a_val, const int &a_comp, const bool &a_doMulti=true)
Definition: BaseEBCellFABI.H:23
#define CH_TIME(name)
Definition: CH_Timer.H:82
Structure for passing component ranges in code.
Definition: Interval.H:23
const T & operator()(const VolIndex &a_ndin, int a_nVarLoc, int a_isKnownMultiValued=0) const
Definition: BaseEBCellFABI.H:400
virtual void define(const EBISBox &a_ebisBox, const Box &a_region, int a_nVar)
Definition: BaseEBCellFABI.H:232
void setVal(const T &value)
Definition: BaseEBCellFABI.H:283
Array defined at the VolIndexs of an Box in an EBIS.
Definition: BaseEBCellFAB.H:40
bool isPeriodic(int a_dir) const
Returns true if BC is periodic in direction a_dir.
Definition: ProblemDomain.H:894
size_t size() const
Definition: Vector.H:192
MiniIVFAB< T > m_irrFAB
data at multi-valued cells
Definition: BaseEBCellFAB.H:259
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.
Definition: BaseFab.H:81
int size(const Box &R, const Interval &comps) const
Definition: BaseEBCellFABI.H:162
virtual ~BaseEBCellFAB()
Definition: BaseEBCellFABI.H:262
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
bool m_isDefined
has full define function been called?
Definition: BaseEBCellFAB.H:271
const Box & getRegion() const
#define CH_STOP(tpointer)
Definition: CH_Timer.H:150
void setDefaultValues()
Definition: BaseEBCellFABI.H:551
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void clear()
Definition: BaseEBCellFABI.H:271
BaseEBCellFAB()
Definition: BaseEBCellFABI.H:213
Volume of Fluid Index.
Definition: VolIndex.H:31
bool isDefined() const
Definition: BaseEBCellFABI.H:317
int nComp() const
Definition: BaseEBCellFABI.H:325
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1862
bool isEmpty() const
Returns true if no IntVects are in this IntVectSet.
void assign(const T *array, const VolIndex &a_ndin, const Interval &a_comps)
Definition: BaseEBCellFABI.H:516
Definition: BaseIVFAB.H:32
BaseFab< T > m_regFAB
data at single-valued cells
Definition: BaseEBCellFAB.H:262
Box m_region
Definition: BaseEBCellFAB.H:266