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