Chombo + EB + MF  3.2
BaseEBFaceFABI.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 _BASEEBFACEFABI_H_
14 #define _BASEEBFACEFABI_H_
15 
16 #include "BoxIterator.H"
17 #include "NamespaceHeader.H"
18 
19 /**********************/
20 template <class T>
22 :m_irrFAB(a_interval,a_original.m_irrFAB),
23  m_regFAB(a_interval,a_original.m_regFAB),
24  m_nComp(a_interval.size()),
25  m_iDir(a_original.m_iDir),
26  m_regionFace(a_original.m_regionFace),
27  m_region(a_original.m_region),
28  m_isDefined(a_original.m_isDefined),
29  m_ebisBox(a_original.m_ebisBox)
30 {
31  if(!m_isDefined) MayDay::Error("Calling alias constructor on undefined BaseEBFaceFAB. Probably an earlier error");
32 
33 }
34 /**********************/
35 template <class T>
36 void
38  const int& a_comp,
39  const bool& a_doMulti)
40 {
41  CH_assert(a_comp >= 0);
42  CH_assert(a_comp < m_nComp);
43 
44  if (m_ebisBox.isAllRegular())
45  {
46  return;
47  }
48  else if (m_ebisBox.isAllCovered())
49  {
50  m_regFAB.setVal(a_val, a_comp);
51  }
52  else
53  {
54  for (BoxIterator bit(m_region); bit.ok(); ++bit)
55  {
56  const IntVect& ivCell = bit();
57  for (SideIterator sit; sit.ok(); ++sit)
58  {
59  const Vector< FaceIndex >& faces = m_ebisBox.getAllFaces(ivCell,m_iDir,sit());
60  if ( (faces.size()==0) || (faces.size()>1) )
61  {
62  const int& hilo = sign(sit());
63  IntVect ivFace = ivCell;
64  if (hilo == 1)
65  {
66  ivFace[m_iDir] += 1;
67  }
68  m_regFAB(ivFace,a_comp) = a_val;
69  }
70  }
71  }
72  }
73 }
74 /*************/
75 /*************/
76 template <class T>
77 int
78 BaseEBFaceFAB<T>::size(const Box& R, const Interval& comps) const
79 {
80 
81  Box RFace = surroundingNodes(R, m_iDir);
82  int regsize = m_regFAB.size(RFace, comps);
83  int irrsize = m_irrFAB.size(R, comps);
84  int retval = regsize + irrsize;
85 
86  if(m_verbose)
87  {
88  pout() <<"baseebfacefab R = " << R << ", RFace = " << RFace << ", comps = " << comps;
89  pout() << ", regbox = " << m_regFAB.box() << ", regsize = " << regsize << ", irrsize = " << irrsize << ", total = " << retval << endl;
90  }
91 
92  return retval;
93 }
94 
95 /*************/
96 template <class T>
97 void
98 BaseEBFaceFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
99  const
100 {
101  Box RFace = surroundingNodes(R, m_iDir);
102  unsigned char* buffer = (unsigned char*)buf;
103  m_regFAB.linearOut(buffer, RFace, comps);
104  buffer+= m_regFAB.size(RFace, comps);
105  m_irrFAB.linearOut(buffer, R, comps);
106 }
107 /*************/
108 template <class T>
109 void
110 BaseEBFaceFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
111 {
112  Box RFace = surroundingNodes(R, m_iDir);
113  unsigned char* buffer = (unsigned char*)buf;
114  m_regFAB.linearIn(buffer, RFace, comps);
115  buffer+= m_regFAB.size(RFace, comps);
116  m_irrFAB.linearIn(buffer, R, comps);
117 }
118 
119 /*************/
120 template <class T> inline
121 const EBISBox&
123 {
124  return m_ebisBox;
125 }
126 /*************/
127 template <class T>
130 {
131  CH_assert(isDefined());
132  CH_assert(a_src.isDefined());
133  CH_assert(m_nComp <= a_src.m_nComp);
135 
136  Interval comps(0,m_nComp-1);
137 
138  Box overlap(m_region);
139  overlap &= a_src.m_region;
140 
141  this->copy(overlap,comps,overlap,a_src,comps);
142 
143  return *this;
144 }
145 
146 /*************/
147 template <class T>
148 inline void
149 BaseEBFaceFAB<T>::copy(const Box& a_regionFrom,
150  const Interval& a_dstInt,
151  const Box& a_regionTo,
152  const BaseEBFaceFAB<T>& a_src,
153  const Interval& a_srcInt)
154 {
155  //CH_assert(a_regionFrom == a_regionTo);
156  CH_assert(isDefined());
157  CH_assert(a_dstInt.size()==a_srcInt.size());
158  CH_assert(a_regionTo.cellCentered());
159  CH_assert(a_src.m_iDir ==m_iDir);
160  CH_assert(a_dstInt.begin()>=0);
161  CH_assert(a_srcInt.begin()>=0);
162  CH_assert(a_srcInt.end()< a_src.m_nComp);
163  CH_assert(a_dstInt.end()< m_nComp);
164  CH_assert(a_src.m_region.contains(a_regionFrom));
165  CH_assert(m_region.contains(a_regionTo));
166  Box RFromCell = a_regionFrom;
167  Box RFromFace = surroundingNodes(RFromCell, m_iDir);
168  Box RToCell = a_regionTo;
169  Box RToFace = surroundingNodes(RToCell, m_iDir);
170 
171  CH_assert(m_regionFace.contains(RToFace));
172  CH_assert(a_src.m_regionFace.contains(RFromFace));
173  //this one has to be rface because basefab does not know
174  //from cell vs edge centered
175  m_regFAB.copy(RFromFace, a_dstInt, RToFace, a_src.m_regFAB, a_srcInt);
176  //this has to be cell centered because that is how
177  //it is defined.
178  // GHM next 4 lines determine if irregular cells can be copied.
179  // DFM 10/16/26 -- intersect with ProblemDomain itself instead of domain box to preserve periodicity
180  //const Box& db = m_ebisBox.getDomain().domainBox();
181  const ProblemDomain& db = m_ebisBox.getDomain();
182  Box rfi = RFromCell & db;
183  Box rti = RToCell & db;
184  if( !rfi.isEmpty() && !rti.isEmpty() )
185  m_irrFAB.copy(RFromCell, a_dstInt, RToCell, a_src.m_irrFAB, a_srcInt);
186 }
187 /**********************/
188 /**********************/
189 template <class T> inline
191 {
193 }
194 
195 /**********************/
196 /**********************/
197 template <class T> inline
199  const Box& a_region,
200  int a_iDir, int a_nComp)
201 {
203  define(a_ebisBox, a_region, a_iDir, a_nComp);
204 }
205 
206 /**********************/
207 /**********************/
208 template <class T> inline
209 void
211  const Box& a_region,
212  int a_iDir, int a_nComp)
213 {
214  clear();
215  m_isDefined = true;
216  CH_assert(a_region.cellCentered());
217  CH_assert(!a_region.isEmpty());
218  CH_assert(a_nComp > 0);
219  CH_assert((a_iDir >= 0) && (a_iDir < SpaceDim));
220 
221  m_ebisBox = a_ebisBox;
222  m_region = a_region;
223  // GHM don't mask region
224  // DFM 10/16/26 -- intersect with ProblemDomain itself instead of domain box to preserve periodicity
225  //m_region &= a_ebisBox.getDomain().domainBox();
226  m_region &= a_ebisBox.getDomain();
228 
229  m_nComp = a_nComp;
230  m_iDir = a_iDir;
231  m_regionFace= surroundingNodes(a_region, a_iDir);
232  Box grownRegion = a_region;
233  grownRegion.grow(a_iDir, 1);
234  // GHM don't mask region
235  // grownRegion &= a_ebisBox.getDomain().domainBox();
236  Box checkRegion = grownRegion;
237  // DFM 10/16/26 -- intersect with ProblemDomain itself instead of domain box to preserve periodicity
238  // checkRegion &= a_ebisBox.getDomain().domainBox();
239  checkRegion &= a_ebisBox.getDomain();
240  //if this fails, you need an ebisbox with more ghost cells
241  CH_assert(a_ebisBox.getRegion().contains(checkRegion));
242 
243  m_regFAB.resize(m_regionFace, m_nComp);
244 
245  m_irrFAB.define(a_region, m_ebisBox.getEBGraph(), m_iDir, m_nComp);
246 }
247 
248 /**********************/
249 /**********************/
250 template <class T> inline
252 {
253  clear();
254 }
255 
256 /**********************/
257 /**********************/
258 template <class T> inline
259 void
261 {
262  m_irrFAB.clear();
263  m_regFAB.clear();
264  m_isDefined = false;
265 }
266 
267 /**********************/
268 /**********************/
269 template <class T> inline
270 void
272 {
273  m_irrFAB.setVal(value);
274  m_regFAB.setVal(value);
275 }
276 
277 /**********************/
278 template <class T> inline
279 void
280 BaseEBFaceFAB<T>::setVal(int ivar, const T& value)
281 {
282  m_irrFAB.setVal(ivar, value);
283  m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
284 }
285 
286 /**********************/
287 /**********************/
288 template <class T> inline
289 bool
291 {
292  return (m_isDefined);
293 }
294 
295 /**********************/
296 /**********************/
297 template <class T> inline
298 int
300 {
301  CH_assert(isDefined());
302  return m_nComp;
303 }
304 
305 /**********************/
306 /**********************/
307 template <class T> inline
308 const MiniIFFAB<T>&
310 {
311  CH_assert(isDefined());
312  return m_irrFAB;
313 }
314 
315 /**********************/
316 /**********************/
317 template <class T> inline
320 {
321  CH_assert(isDefined());
322  return m_irrFAB;
323 }
324 
325 /**********************/
326 /**********************/
327 template <class T> inline
328 const BaseFab<T>&
330 {
331  CH_assert(isDefined());
332  return m_regFAB;
333 }
334 
335 /**********************/
336 /**********************/
337 template <class T> inline
338 BaseFab<T>&
340 {
341  CH_assert(isDefined());
342  return m_regFAB;
343 }
344 
345 /**********************/
346 /**********************/
347 template <class T> inline
348 int
350 {
351  CH_assert(isDefined());
352  return m_iDir;
353 }
354 
355 /**********************/
356 /**********************/
357 template <class T> inline
358 const Box&
360 {
361  CH_assert(isDefined());
362  return m_regionFace;
363 }
364 /**********************/
365 /**********************/
366 template <class T> inline
367 const Box&
369 {
370  CH_assert(isDefined());
371  return m_region;
372 }
373 
374 /**********************/
375 /**********************/
376 template <class T> inline
377 T&
378 BaseEBFaceFAB<T>::operator()(const FaceIndex& a_facein, int a_nCompLoc)
379 {
380  CH_assert(isDefined());
381  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
382  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
384 
385  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
386  T* returnval;
387 
388  bool isFaceHere = false;
389  for (int iface = 0; iface< multiFaces.size(); iface++)
390  {
391  const FaceIndex& face = multiFaces[iface];
392  if (face == a_facein)
393  {
394  isFaceHere = true;
395  }
396  }
397  if (isFaceHere)
398  {
399  returnval = &m_irrFAB(a_facein, a_nCompLoc);
400  }
401  else
402  {
403  returnval = &m_regFAB(ivhi, a_nCompLoc);
404  }
405  return *returnval;
406 }
407 
408 /**********************/
409 /**********************/
410 template <class T> inline
411 const T&
412 BaseEBFaceFAB<T>::operator() (const FaceIndex& a_facein, int a_nCompLoc) const
413 {
414  CH_assert(isDefined());
415  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
416  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
418 
419  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
420  const T* returnval;
421 
422  bool isFaceHere = false;
423  for (int iface = 0; iface< multiFaces.size(); iface++)
424  {
425  const FaceIndex& face = multiFaces[iface];
426  if (face == a_facein)
427  {
428  isFaceHere = true;
429  }
430  }
431  if (isFaceHere)
432  {
433  returnval = &m_irrFAB(a_facein, a_nCompLoc);
434  }
435  else
436  {
437  returnval = &m_regFAB(ivhi, a_nCompLoc);
438  }
439  return *returnval;
440 }
441 
442 /**********************/
443 /**********************/
444 template <class T> inline
445 void
447 {
448  m_isDefined = false;
449  m_nComp = -1;
450  m_iDir = -1;
451 }
452 
453 #include "NamespaceFooter.H"
454 #endif
std::ostream & pout()
Use this in place of std::cout for program output.
int m_nComp
number of data values at each face in BaseEBFaceFAB
Definition: BaseEBFaceFAB.H:273
void clear()
Definition: BaseEBFaceFABI.H:260
bool ok()
Definition: BoxIterator.H:281
const Box & getRegion() const
Definition: BaseEBFaceFABI.H:359
void setVal(const T &value)
Definition: BaseEBFaceFABI.H:271
bool ok() const
#define CH_assert(cond)
Definition: CHArray.H:37
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
const EBGraph & getEBGraph() const
int sign(const CH_XD::Side::LoHiSide &a_side)
int nComp() const
Definition: BaseEBFaceFABI.H:299
bool cellCentered() const
Definition: Box.H:1939
void setCoveredFaceVal(const T &a_val, const int &a_comp, const bool &a_doMulti=true)
Definition: BaseEBFaceFABI.H:37
Definition: FaceIndex.H:28
const ProblemDomain & getDomain() const
int size() const
Definition: Interval.H:75
Vector< FaceIndex > getAllFaces(const IntVect &a_iv, const int &a_idir, const Side::LoHiSide &a_sd) const
Definition: EBISBox.H:431
int begin() const
Definition: Interval.H:99
Box m_region
the cell-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:282
Definition: EBISBox.H:46
bool contains(const IntVect &p) const
Definition: Box.H:1887
const IntVect & gridIndex(const Side::LoHiSide &a_sd) const
iterates through the IntVects of a Box
Definition: BoxIterator.H:37
Array defined at the Faces of an Box in an EBISBox.
Definition: BaseEBFaceFAB.H:43
Definition: LoHiSide.H:31
T & operator()(const FaceIndex &a_facein, int a_nVarLoc)
Definition: BaseEBFaceFABI.H:378
EBISBox m_ebisBox
Definition: BaseEBFaceFAB.H:287
const int SpaceDim
Definition: SPACE.H:38
bool m_verbose
Definition: BaseEBFaceFAB.H:47
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:98
virtual ~BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:251
BaseFab< T > m_regFAB
data at faces between two single-valued cells
Definition: BaseEBFaceFAB.H:270
Structure for passing component ranges in code.
Definition: Interval.H:23
MiniIFFAB< T > m_irrFAB
data at faces which abut multi-valued cells
Definition: BaseEBFaceFAB.H:268
void copy(const Box &RegionFrom, const Interval &destInt, const Box &RegionTo, const BaseEBFaceFAB< T > &source, const Interval &srcInt)
Definition: BaseEBFaceFABI.H:149
bool isAllRegular() const
Definition: EBISBox.H:393
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2161
const Box & getCellRegion() const
Definition: BaseEBFaceFABI.H:368
const EBISBox & getEBISBox() const
Definition: BaseEBFaceFABI.H:122
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseEBFaceFABI.H:110
size_t size() const
Definition: Vector.H:192
int size(const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:78
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
const BaseFab< T > & getSingleValuedFAB() const
Definition: BaseEBFaceFABI.H:329
bool sameType(const Box &b) const
Definition: Box.H:1896
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
Iterator for low and high side.
Definition: LoHiSide.H:74
const Box & getRegion() const
Definition: MiniIFFAB.H:34
BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:190
bool isAllCovered() const
Definition: EBISBox.H:387
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
bool m_isDefined
has the full define function been called for the BaseEBFaceFAB?
Definition: BaseEBFaceFAB.H:285
Box & grow(int i)
grow functions
Definition: Box.H:2263
int end() const
Definition: Interval.H:104
Box m_regionFace
the face-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:279
int direction() const
Definition: BaseEBFaceFABI.H:349
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1862
virtual void define(const EBISBox &a_ebisBox, const Box &a_region, int a_iDir, int a_nVar)
Definition: BaseEBFaceFABI.H:210
void setDefaultValues()
Definition: BaseEBFaceFABI.H:446
int m_iDir
Definition: BaseEBFaceFAB.H:276
const MiniIFFAB< T > & getMultiValuedFAB() const
Definition: BaseEBFaceFABI.H:309
bool isDefined() const
Definition: BaseEBFaceFABI.H:290