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);
134  CH_assert(m_region.sameType(a_src.m_region));
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  const Box& db = m_ebisBox.getDomain().domainBox();
180  Box rfi = RFromCell & db;
181  Box rti = RToCell & db;
182  if( !rfi.isEmpty() && !rti.isEmpty() )
183  m_irrFAB.copy(RFromCell, a_dstInt, RToCell, a_src.m_irrFAB, a_srcInt);
184 }
185 /**********************/
186 /**********************/
187 template <class T> inline
189 {
190  setDefaultValues();
191 }
192 
193 /**********************/
194 /**********************/
195 template <class T> inline
197  const Box& a_region,
198  int a_iDir, int a_nComp)
199 {
200  setDefaultValues();
201  define(a_ebisBox, a_region, a_iDir, a_nComp);
202 }
203 
204 /**********************/
205 /**********************/
206 template <class T> inline
207 void
209  const Box& a_region,
210  int a_iDir, int a_nComp)
211 {
212  clear();
213  m_isDefined = true;
214  CH_assert(a_region.cellCentered());
215  CH_assert(!a_region.isEmpty());
216  CH_assert(a_nComp > 0);
217  CH_assert((a_iDir >= 0) && (a_iDir < SpaceDim));
218 
219  m_ebisBox = a_ebisBox;
220  m_region = a_region;
221  // GHM don't mask region
222  m_region &= a_ebisBox.getDomain().domainBox();
223  CH_assert(!m_region.isEmpty());
224 
225  m_nComp = a_nComp;
226  m_iDir = a_iDir;
227  m_regionFace= surroundingNodes(a_region, a_iDir);
228  Box grownRegion = a_region;
229  grownRegion.grow(a_iDir, 1);
230  // GHM don't mask region
231  // grownRegion &= a_ebisBox.getDomain().domainBox();
232  Box checkRegion = grownRegion;
233  checkRegion &= a_ebisBox.getDomain().domainBox();
234  //if this fails, you need an ebisbox with more ghost cells
235  CH_assert(a_ebisBox.getRegion().contains(checkRegion));
236 
237  m_regFAB.resize(m_regionFace, m_nComp);
238 
239  m_irrFAB.define(a_region, m_ebisBox.getEBGraph(), m_iDir, m_nComp);
240 }
241 
242 /**********************/
243 /**********************/
244 template <class T> inline
246 {
247  clear();
248 }
249 
250 /**********************/
251 /**********************/
252 template <class T> inline
253 void
255 {
256  m_irrFAB.clear();
257  m_regFAB.clear();
258  m_isDefined = false;
259 }
260 
261 /**********************/
262 /**********************/
263 template <class T> inline
264 void
266 {
267  m_irrFAB.setVal(value);
268  m_regFAB.setVal(value);
269 }
270 
271 /**********************/
272 template <class T> inline
273 void
274 BaseEBFaceFAB<T>::setVal(int ivar, const T& value)
275 {
276  m_irrFAB.setVal(ivar, value);
277  m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
278 }
279 
280 /**********************/
281 /**********************/
282 template <class T> inline
283 bool
285 {
286  return (m_isDefined);
287 }
288 
289 /**********************/
290 /**********************/
291 template <class T> inline
292 int
294 {
295  CH_assert(isDefined());
296  return m_nComp;
297 }
298 
299 /**********************/
300 /**********************/
301 template <class T> inline
302 const MiniIFFAB<T>&
304 {
305  CH_assert(isDefined());
306  return m_irrFAB;
307 }
308 
309 /**********************/
310 /**********************/
311 template <class T> inline
314 {
315  CH_assert(isDefined());
316  return m_irrFAB;
317 }
318 
319 /**********************/
320 /**********************/
321 template <class T> inline
322 const BaseFab<T>&
324 {
325  CH_assert(isDefined());
326  return m_regFAB;
327 }
328 
329 /**********************/
330 /**********************/
331 template <class T> inline
332 BaseFab<T>&
334 {
335  CH_assert(isDefined());
336  return m_regFAB;
337 }
338 
339 /**********************/
340 /**********************/
341 template <class T> inline
342 int
344 {
345  CH_assert(isDefined());
346  return m_iDir;
347 }
348 
349 /**********************/
350 /**********************/
351 template <class T> inline
352 const Box&
354 {
355  CH_assert(isDefined());
356  return m_regionFace;
357 }
358 /**********************/
359 /**********************/
360 template <class T> inline
361 const Box&
363 {
364  CH_assert(isDefined());
365  return m_region;
366 }
367 
368 /**********************/
369 /**********************/
370 template <class T> inline
371 T&
372 BaseEBFaceFAB<T>::operator()(const FaceIndex& a_facein, int a_nCompLoc)
373 {
374  CH_assert(isDefined());
375  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
376  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
377  CH_assert(m_regionFace.contains(ivhi));
378 
379  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
380  T* returnval;
381 
382  bool isFaceHere = false;
383  for (int iface = 0; iface< multiFaces.size(); iface++)
384  {
385  const FaceIndex& face = multiFaces[iface];
386  if (face == a_facein)
387  {
388  isFaceHere = true;
389  }
390  }
391  if (isFaceHere)
392  {
393  returnval = &m_irrFAB(a_facein, a_nCompLoc);
394  }
395  else
396  {
397  returnval = &m_regFAB(ivhi, a_nCompLoc);
398  }
399  return *returnval;
400 }
401 
402 /**********************/
403 /**********************/
404 template <class T> inline
405 const T&
406 BaseEBFaceFAB<T>::operator() (const FaceIndex& a_facein, int a_nCompLoc) const
407 {
408  CH_assert(isDefined());
409  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
410  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
411  CH_assert(m_regionFace.contains(ivhi));
412 
413  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
414  const T* returnval;
415 
416  bool isFaceHere = false;
417  for (int iface = 0; iface< multiFaces.size(); iface++)
418  {
419  const FaceIndex& face = multiFaces[iface];
420  if (face == a_facein)
421  {
422  isFaceHere = true;
423  }
424  }
425  if (isFaceHere)
426  {
427  returnval = &m_irrFAB(a_facein, a_nCompLoc);
428  }
429  else
430  {
431  returnval = &m_regFAB(ivhi, a_nCompLoc);
432  }
433  return *returnval;
434 }
435 
436 /**********************/
437 /**********************/
438 template <class T> inline
439 void
441 {
442  m_isDefined = false;
443  m_nComp = -1;
444  m_iDir = -1;
445 }
446 
447 #include "NamespaceFooter.H"
448 #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:254
bool ok()
Definition: BoxIterator.H:281
void setVal(const T &value)
Definition: BaseEBFaceFABI.H:265
#define CH_assert(cond)
Definition: CHArray.H:37
int direction() const
Definition: BaseEBFaceFABI.H:343
Box copy() const
Definition: Box.H:571
void setCoveredFaceVal(const T &a_val, const int &a_comp, const bool &a_doMulti=true)
Definition: BaseEBFaceFABI.H:37
Definition: FaceIndex.H:28
Box m_region
the cell-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:282
Definition: EBISBox.H:46
const Box & getRegion() const
Definition: BaseEBFaceFABI.H:353
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
const MiniIFFAB< T > & getMultiValuedFAB() const
Definition: BaseEBFaceFABI.H:303
int size() const
Definition: Interval.H:75
Definition: LoHiSide.H:31
T & operator()(const FaceIndex &a_facein, int a_nVarLoc)
Definition: BaseEBFaceFABI.H:372
const int SpaceDim
Definition: SPACE.H:38
const Box & getRegion() const
virtual ~BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:245
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
int nComp() const
Definition: BaseEBFaceFABI.H:293
const ProblemDomain & getDomain() const
int sign(const Side::LoHiSide &a_side)
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 cellCentered() const
Definition: Box.H:1939
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2161
const BaseFab< T > & getSingleValuedFAB() const
Definition: BaseEBFaceFABI.H:323
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseEBFaceFABI.H:110
const Box & domainBox() const
Returns the logical computational domain.
Definition: ProblemDomain.H:887
const EBISBox & getEBISBox() const
Definition: BaseEBFaceFABI.H:122
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:99
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1862
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:98
Definition: BaseFab.H:81
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
Iterator for low and high side.
Definition: LoHiSide.H:74
Definition: MiniIFFAB.H:34
bool contains(const IntVect &p) const
Definition: Box.H:1887
BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:188
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
const IntVect & gridIndex(const Side::LoHiSide &a_sd) const
size_t size() const
Definition: Vector.H:192
Box & grow(int i)
grow functions
Definition: Box.H:2263
bool ok() const
int end() const
Definition: Interval.H:104
Box m_regionFace
the face-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:279
int size(const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:78
const Box & getCellRegion() const
Definition: BaseEBFaceFABI.H:362
virtual void define(const EBISBox &a_ebisBox, const Box &a_region, int a_iDir, int a_nVar)
Definition: BaseEBFaceFABI.H:208
void setDefaultValues()
Definition: BaseEBFaceFABI.H:440
int m_iDir
Definition: BaseEBFaceFAB.H:276
bool isDefined() const
Definition: BaseEBFaceFABI.H:284