Chombo + EB  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 retval = m_regFAB.size(RFace, comps);
83  retval += m_irrFAB.size(R, comps);
84  return retval;
85 }
86 
87 /*************/
88 template <class T>
89 void
90 BaseEBFaceFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
91  const
92 {
93  Box RFace = surroundingNodes(R, m_iDir);
94  unsigned char* buffer = (unsigned char*)buf;
95  m_regFAB.linearOut(buffer, RFace, comps);
96  buffer+= m_regFAB.size(RFace, comps);
97  m_irrFAB.linearOut(buffer, R, comps);
98 }
99 /*************/
100 template <class T>
101 void
102 BaseEBFaceFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
103 {
104  Box RFace = surroundingNodes(R, m_iDir);
105  unsigned char* buffer = (unsigned char*)buf;
106  m_regFAB.linearIn(buffer, RFace, comps);
107  buffer+= m_regFAB.size(RFace, comps);
108  m_irrFAB.linearIn(buffer, R, comps);
109 }
110 
111 /*************/
112 template <class T> inline
113 const EBISBox&
115 {
116  return m_ebisBox;
117 }
118 /*************/
119 template <class T>
122 {
123  CH_assert(isDefined());
124  CH_assert(a_src.isDefined());
125  CH_assert(m_nComp <= a_src.m_nComp);
127 
128  Interval comps(0,m_nComp-1);
129 
130  Box overlap(m_region);
131  overlap &= a_src.m_region;
132 
133  this->copy(overlap,comps,overlap,a_src,comps);
134 
135  return *this;
136 }
137 
138 /*************/
139 template <class T>
140 inline void
141 BaseEBFaceFAB<T>::copy(const Box& a_regionFrom,
142  const Interval& a_dstInt,
143  const Box& a_regionTo,
144  const BaseEBFaceFAB<T>& a_src,
145  const Interval& a_srcInt)
146 {
147  //CH_assert(a_regionFrom == a_regionTo);
148  CH_assert(isDefined());
149  CH_assert(a_dstInt.size()==a_srcInt.size());
150  CH_assert(a_regionTo.cellCentered());
151  CH_assert(a_src.m_iDir ==m_iDir);
152  CH_assert(a_dstInt.begin()>=0);
153  CH_assert(a_srcInt.begin()>=0);
154  CH_assert(a_srcInt.end()< a_src.m_nComp);
155  CH_assert(a_dstInt.end()< m_nComp);
156  CH_assert(a_src.m_region.contains(a_regionFrom));
157  CH_assert(m_region.contains(a_regionTo));
158  Box RFromCell = a_regionFrom;
159  Box RFromFace = surroundingNodes(RFromCell, m_iDir);
160  Box RToCell = a_regionTo;
161  Box RToFace = surroundingNodes(RToCell, m_iDir);
162 
163  CH_assert(m_regionFace.contains(RToFace));
164  CH_assert(a_src.m_regionFace.contains(RFromFace));
165  //this one has to be rface because basefab does not know
166  //from cell vs edge centered
167  m_regFAB.copy(RFromFace, a_dstInt, RToFace, a_src.m_regFAB, a_srcInt);
168  //this has to be cell centered because that is how
169  //it is defined.
170  // GHM next 4 lines determine if irregular cells can be copied.
171  const Box& db = m_ebisBox.getDomain().domainBox();
172  Box rfi = RFromCell & db;
173  Box rti = RToCell & db;
174  if( !rfi.isEmpty() && !rti.isEmpty() )
175  m_irrFAB.copy(RFromCell, a_dstInt, RToCell, a_src.m_irrFAB, a_srcInt);
176 }
177 /**********************/
178 /**********************/
179 template <class T> inline
181 {
183 }
184 
185 /**********************/
186 /**********************/
187 template <class T> inline
189  const Box& a_region,
190  int a_iDir, int a_nComp)
191 {
193  define(a_ebisBox, a_region, a_iDir, a_nComp);
194 }
195 
196 /**********************/
197 /**********************/
198 template <class T> inline
199 void
201  const Box& a_region,
202  int a_iDir, int a_nComp)
203 {
204  clear();
205  m_isDefined = true;
206  CH_assert(a_region.cellCentered());
207  CH_assert(!a_region.isEmpty());
208  CH_assert(a_nComp > 0);
209  CH_assert((a_iDir >= 0) && (a_iDir < SpaceDim));
210 
211  m_ebisBox = a_ebisBox;
212  m_region = a_region;
213  // GHM don't mask region
214  m_region &= a_ebisBox.getDomain().domainBox();
216 
217  m_nComp = a_nComp;
218  m_iDir = a_iDir;
219  m_regionFace= surroundingNodes(a_region, a_iDir);
220  Box grownRegion = a_region;
221  grownRegion.grow(a_iDir, 1);
222  // GHM don't mask region
223  // grownRegion &= a_ebisBox.getDomain().domainBox();
224  Box checkRegion = grownRegion;
225  checkRegion &= a_ebisBox.getDomain().domainBox();
226  //if this fails, you need an ebisbox with more ghost cells
227  CH_assert(a_ebisBox.getRegion().contains(checkRegion));
228 
229  m_regFAB.resize(m_regionFace, m_nComp);
230 
231  m_irrFAB.define(a_region, m_ebisBox.getEBGraph(), m_iDir, m_nComp);
232 }
233 
234 /**********************/
235 /**********************/
236 template <class T> inline
238 {
239  clear();
240 }
241 
242 /**********************/
243 /**********************/
244 template <class T> inline
245 void
247 {
248  m_irrFAB.clear();
249  m_regFAB.clear();
250  m_isDefined = false;
251 }
252 
253 /**********************/
254 /**********************/
255 template <class T> inline
256 void
258 {
259  m_irrFAB.setVal(value);
260  m_regFAB.setVal(value);
261 }
262 
263 /**********************/
264 template <class T> inline
265 void
266 BaseEBFaceFAB<T>::setVal(int ivar, const T& value)
267 {
268  m_irrFAB.setVal(ivar, value);
269  m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
270 }
271 
272 /**********************/
273 /**********************/
274 template <class T> inline
275 bool
277 {
278  return (m_isDefined);
279 }
280 
281 /**********************/
282 /**********************/
283 template <class T> inline
284 int
286 {
287  CH_assert(isDefined());
288  return m_nComp;
289 }
290 
291 /**********************/
292 /**********************/
293 template <class T> inline
294 const MiniIFFAB<T>&
296 {
297  CH_assert(isDefined());
298  return m_irrFAB;
299 }
300 
301 /**********************/
302 /**********************/
303 template <class T> inline
306 {
307  CH_assert(isDefined());
308  return m_irrFAB;
309 }
310 
311 /**********************/
312 /**********************/
313 template <class T> inline
314 const BaseFab<T>&
316 {
317  CH_assert(isDefined());
318  return m_regFAB;
319 }
320 
321 /**********************/
322 /**********************/
323 template <class T> inline
324 BaseFab<T>&
326 {
327  CH_assert(isDefined());
328  return m_regFAB;
329 }
330 
331 /**********************/
332 /**********************/
333 template <class T> inline
334 int
336 {
337  CH_assert(isDefined());
338  return m_iDir;
339 }
340 
341 /**********************/
342 /**********************/
343 template <class T> inline
344 const Box&
346 {
347  CH_assert(isDefined());
348  return m_regionFace;
349 }
350 /**********************/
351 /**********************/
352 template <class T> inline
353 const Box&
355 {
356  CH_assert(isDefined());
357  return m_region;
358 }
359 
360 /**********************/
361 /**********************/
362 template <class T> inline
363 T&
364 BaseEBFaceFAB<T>::operator()(const FaceIndex& a_facein, int a_nCompLoc)
365 {
366  CH_assert(isDefined());
367  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
368  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
370 
371  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
372  T* returnval;
373 
374  bool isFaceHere = false;
375  for (int iface = 0; iface< multiFaces.size(); iface++)
376  {
377  const FaceIndex& face = multiFaces[iface];
378  if (face == a_facein)
379  {
380  isFaceHere = true;
381  }
382  }
383  if (isFaceHere)
384  {
385  returnval = &m_irrFAB(a_facein, a_nCompLoc);
386  }
387  else
388  {
389  returnval = &m_regFAB(ivhi, a_nCompLoc);
390  }
391  return *returnval;
392 }
393 
394 /**********************/
395 /**********************/
396 template <class T> inline
397 const T&
398 BaseEBFaceFAB<T>::operator() (const FaceIndex& a_facein, int a_nCompLoc) const
399 {
400  CH_assert(isDefined());
401  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
402  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
404 
405  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
406  const T* returnval;
407 
408  bool isFaceHere = false;
409  for (int iface = 0; iface< multiFaces.size(); iface++)
410  {
411  const FaceIndex& face = multiFaces[iface];
412  if (face == a_facein)
413  {
414  isFaceHere = true;
415  }
416  }
417  if (isFaceHere)
418  {
419  returnval = &m_irrFAB(a_facein, a_nCompLoc);
420  }
421  else
422  {
423  returnval = &m_regFAB(ivhi, a_nCompLoc);
424  }
425  return *returnval;
426 }
427 
428 /**********************/
429 /**********************/
430 template <class T> inline
431 void
433 {
434  m_isDefined = false;
435  m_nComp = -1;
436  m_iDir = -1;
437 }
438 
439 #include "NamespaceFooter.H"
440 #endif
int m_nComp
number of data values at each face in BaseEBFaceFAB
Definition: BaseEBFaceFAB.H:271
void clear()
Definition: BaseEBFaceFABI.H:246
bool ok()
Definition: BoxIterator.H:281
const Box & getRegion() const
Definition: BaseEBFaceFABI.H:345
void setVal(const T &value)
Definition: BaseEBFaceFABI.H:257
bool ok() const
#define CH_assert(cond)
Definition: CHArray.H:37
const EBGraph & getEBGraph() const
define from scratch using irregular graph
int sign(const CH_XD::Side::LoHiSide &a_side)
int nComp() const
Definition: BaseEBFaceFABI.H:285
bool cellCentered() const
Definition: Box.H:1923
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:477
int begin() const
Definition: Interval.H:97
Box m_region
the cell-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:280
Definition: EBISBox.H:46
bool contains(const IntVect &p) const
Definition: Box.H:1871
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:364
EBISBox m_ebisBox
Definition: BaseEBFaceFAB.H:285
const int SpaceDim
Definition: SPACE.H:38
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:90
virtual ~BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:237
BaseFab< T > m_regFAB
data at faces between two single-valued cells
Definition: BaseEBFaceFAB.H:268
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:266
void copy(const Box &RegionFrom, const Interval &destInt, const Box &RegionTo, const BaseEBFaceFAB< T > &source, const Interval &srcInt)
Definition: BaseEBFaceFABI.H:141
bool isAllRegular() const
Definition: EBISBox.H:439
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2145
const Box & getCellRegion() const
Definition: BaseEBFaceFABI.H:354
const EBISBox & getEBISBox() const
Definition: BaseEBFaceFABI.H:114
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseEBFaceFABI.H:102
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:77
const BaseFab< T > & getSingleValuedFAB() const
Definition: BaseEBFaceFABI.H:315
bool sameType(const Box &b) const
Definition: Box.H:1880
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
Iterator for low and high side.
Definition: LoHiSide.H:74
const Box & getRegion() const
Definition: MiniIFFAB.H:34
BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:180
bool isAllCovered() const
Definition: EBISBox.H:433
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:283
Box & grow(int i)
grow functions
Definition: Box.H:2247
int end() const
Definition: Interval.H:102
Box m_regionFace
the face-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:277
const Box & domainBox() const
Returns the logical computational domain.
Definition: ProblemDomain.H:887
int direction() const
Definition: BaseEBFaceFABI.H:335
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1846
virtual void define(const EBISBox &a_ebisBox, const Box &a_region, int a_iDir, int a_nVar)
Definition: BaseEBFaceFABI.H:200
void setDefaultValues()
Definition: BaseEBFaceFABI.H:432
int m_iDir
Definition: BaseEBFaceFAB.H:274
const MiniIFFAB< T > & getMultiValuedFAB() const
Definition: BaseEBFaceFABI.H:295
bool isDefined() const
Definition: BaseEBFaceFABI.H:276