Chombo + EB  3.0
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 /**********************/
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& ivCell = bit();
43  for (SideIterator sit; sit.ok(); ++sit)
44  {
45  const Vector< FaceIndex >& faces = m_ebisBox.getAllFaces(ivCell,m_iDir,sit());
46  if ( (faces.size()==0) || (faces.size()>1) )
47  {
48  const int& hilo = sign(sit());
49  IntVect ivFace = ivCell;
50  if (hilo == 1)
51  {
52  ivFace[m_iDir] += 1;
53  }
54  m_regFAB(ivFace,a_comp) = a_val;
55  }
56  }
57  }
58  }
59 }
60 /*************/
61 /*************/
62 template <class T>
63 int
64 BaseEBFaceFAB<T>::size(const Box& R, const Interval& comps) const
65 {
66 
67  Box RFace = surroundingNodes(R, m_iDir);
68  int retval = m_regFAB.size(RFace, comps);
69  retval += m_irrFAB.size(R, comps);
70  return retval;
71 }
72 
73 /*************/
74 template <class T>
75 void
76 BaseEBFaceFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
77  const
78 {
79  Box RFace = surroundingNodes(R, m_iDir);
80  unsigned char* buffer = (unsigned char*)buf;
81  m_regFAB.linearOut(buffer, RFace, comps);
82  buffer+= m_regFAB.size(RFace, comps);
83  m_irrFAB.linearOut(buffer, R, comps);
84 }
85 /*************/
86 template <class T>
87 void
88 BaseEBFaceFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
89 {
90  Box RFace = surroundingNodes(R, m_iDir);
91  unsigned char* buffer = (unsigned char*)buf;
92  m_regFAB.linearIn(buffer, RFace, comps);
93  buffer+= m_regFAB.size(RFace, comps);
94  m_irrFAB.linearIn(buffer, R, comps);
95 }
96 
97 /*************/
98 template <class T> inline
99 const EBISBox&
101 {
102  return m_ebisBox;
103 }
104 /*************/
105 template <class T>
108 {
109  CH_assert(isDefined());
110  CH_assert(a_src.isDefined());
111  CH_assert(m_nComp <= a_src.m_nComp);
112  CH_assert(m_region.sameType(a_src.m_region));
113 
114  Interval comps(0,m_nComp-1);
115 
116  Box overlap(m_region);
117  overlap &= a_src.m_region;
118 
119  this->copy(overlap,comps,overlap,a_src,comps);
120 
121  return *this;
122 }
123 
124 /*************/
125 template <class T>
126 inline void
127 BaseEBFaceFAB<T>::copy(const Box& a_regionFrom,
128  const Interval& a_dstInt,
129  const Box& a_regionTo,
130  const BaseEBFaceFAB<T>& a_src,
131  const Interval& a_srcInt)
132 {
133  //CH_assert(a_regionFrom == a_regionTo);
134  CH_assert(isDefined());
135  CH_assert(a_dstInt.size()==a_srcInt.size());
136  CH_assert(a_regionTo.cellCentered());
137  CH_assert(a_src.m_iDir ==m_iDir);
138  CH_assert(a_dstInt.begin()>=0);
139  CH_assert(a_srcInt.begin()>=0);
140  CH_assert(a_srcInt.end()< a_src.m_nComp);
141  CH_assert(a_dstInt.end()< m_nComp);
142  CH_assert(a_src.m_region.contains(a_regionFrom));
143  CH_assert(m_region.contains(a_regionTo));
144  Box RFromCell = a_regionFrom;
145  Box RFromFace = surroundingNodes(RFromCell, m_iDir);
146  Box RToCell = a_regionTo;
147  Box RToFace = surroundingNodes(RToCell, m_iDir);
148 
149  CH_assert(m_regionFace.contains(RToFace));
150  CH_assert(a_src.m_regionFace.contains(RFromFace));
151  //this one has to be rface because basefab does not know
152  //from cell vs edge centered
153  m_regFAB.copy(RFromFace, a_dstInt, RToFace, a_src.m_regFAB, a_srcInt);
154  //this has to be cell centered because that is how
155  //it is defined.
156  m_irrFAB.copy(RFromCell, a_dstInt, RToCell, a_src.m_irrFAB, a_srcInt);
157 }
158 /**********************/
159 /**********************/
160 template <class T> inline
162 {
163  setDefaultValues();
164 }
165 
166 /**********************/
167 /**********************/
168 template <class T> inline
170  const Box& a_region,
171  int a_iDir, int a_nComp)
172 {
173  setDefaultValues();
174  define(a_ebisBox, a_region, a_iDir, a_nComp);
175 }
176 
177 /**********************/
178 /**********************/
179 template <class T> inline
180 void
182  const Box& a_region,
183  int a_iDir, int a_nComp)
184 {
185  clear();
186  m_isDefined = true;
187  CH_assert(a_region.cellCentered());
188  CH_assert(!a_region.isEmpty());
189  CH_assert(a_nComp > 0);
190  CH_assert((a_iDir >= 0) && (a_iDir < SpaceDim));
191 
192  m_ebisBox = a_ebisBox;
193  m_region = a_region;
194  m_region &= a_ebisBox.getDomain().domainBox();
195  CH_assert(!m_region.isEmpty());
196  //if this fails, you need an ebisbox with more ghost cells
197  CH_assert(a_ebisBox.getRegion().contains(m_region));
198 
199  m_nComp = a_nComp;
200  m_iDir = a_iDir;
201  m_regionFace= surroundingNodes(m_region, a_iDir);
202  Box grownRegion = m_region;
203  grownRegion.grow(a_iDir, 1);
204  grownRegion &= a_ebisBox.getDomain().domainBox();
205  //if this fails, you need an ebisbox with more ghost cells
206  CH_assert(a_ebisBox.getRegion().contains(grownRegion));
207 
208  m_regFAB.resize(m_regionFace, m_nComp);
209 
210  m_irrFAB.define(a_region, m_ebisBox.getEBGraph(), m_iDir, m_nComp);
211 }
212 
213 /**********************/
214 /**********************/
215 template <class T> inline
217 {
218  clear();
219 }
220 
221 /**********************/
222 /**********************/
223 template <class T> inline
224 void
226 {
227  m_irrFAB.clear();
228  m_regFAB.clear();
229  m_isDefined = false;
230 }
231 
232 /**********************/
233 /**********************/
234 template <class T> inline
235 void
237 {
238  m_irrFAB.setVal(value);
239  m_regFAB.setVal(value);
240 }
241 
242 /**********************/
243 template <class T> inline
244 void
245 BaseEBFaceFAB<T>::setVal(int ivar, const T& value)
246 {
247  m_irrFAB.setVal(ivar, value);
248  m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
249 }
250 
251 /**********************/
252 /**********************/
253 template <class T> inline
254 bool
256 {
257  return (m_isDefined);
258 }
259 
260 /**********************/
261 /**********************/
262 template <class T> inline
263 int
265 {
266  CH_assert(isDefined());
267  return m_nComp;
268 }
269 
270 /**********************/
271 /**********************/
272 template <class T> inline
273 const MiniIFFAB<T>&
275 {
276  CH_assert(isDefined());
277  return m_irrFAB;
278 }
279 
280 /**********************/
281 /**********************/
282 template <class T> inline
285 {
286  CH_assert(isDefined());
287  return m_irrFAB;
288 }
289 
290 /**********************/
291 /**********************/
292 template <class T> inline
293 const BaseFab<T>&
295 {
296  CH_assert(isDefined());
297  return m_regFAB;
298 }
299 
300 /**********************/
301 /**********************/
302 template <class T> inline
303 BaseFab<T>&
305 {
306  CH_assert(isDefined());
307  return m_regFAB;
308 }
309 
310 /**********************/
311 /**********************/
312 template <class T> inline
313 int
315 {
316  CH_assert(isDefined());
317  return m_iDir;
318 }
319 
320 /**********************/
321 /**********************/
322 template <class T> inline
323 const Box&
325 {
326  CH_assert(isDefined());
327  return m_regionFace;
328 }
329 /**********************/
330 /**********************/
331 template <class T> inline
332 const Box&
334 {
335  CH_assert(isDefined());
336  return m_region;
337 }
338 
339 /**********************/
340 /**********************/
341 template <class T> inline
342 T&
343 BaseEBFaceFAB<T>::operator()(const FaceIndex& a_facein, int a_nCompLoc)
344 {
345  CH_assert(isDefined());
346  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
347  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
348  CH_assert(m_regionFace.contains(ivhi));
349 
350  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
351  T* returnval;
352 
353  bool isFaceHere = false;
354  for (int iface = 0; iface< multiFaces.size(); iface++)
355  {
356  const FaceIndex& face = multiFaces[iface];
357  if (face == a_facein)
358  {
359  isFaceHere = true;
360  }
361  }
362  if (isFaceHere)
363  {
364  returnval = &m_irrFAB(a_facein, a_nCompLoc);
365  }
366  else
367  {
368  returnval = &m_regFAB(ivhi, a_nCompLoc);
369  }
370  return *returnval;
371 }
372 
373 /**********************/
374 /**********************/
375 template <class T> inline
376 const T&
377 BaseEBFaceFAB<T>::operator() (const FaceIndex& a_facein, int a_nCompLoc) const
378 {
379  CH_assert(isDefined());
380  CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
381  const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
382  CH_assert(m_regionFace.contains(ivhi));
383 
384  const Vector<FaceIndex>& multiFaces = m_irrFAB.getFaces();
385  const T* returnval;
386 
387  bool isFaceHere = false;
388  for (int iface = 0; iface< multiFaces.size(); iface++)
389  {
390  const FaceIndex& face = multiFaces[iface];
391  if (face == a_facein)
392  {
393  isFaceHere = true;
394  }
395  }
396  if (isFaceHere)
397  {
398  returnval = &m_irrFAB(a_facein, a_nCompLoc);
399  }
400  else
401  {
402  returnval = &m_regFAB(ivhi, a_nCompLoc);
403  }
404  return *returnval;
405 }
406 
407 /**********************/
408 /**********************/
409 template <class T> inline
410 void
412 {
413  m_isDefined = false;
414  m_nComp = -1;
415  m_iDir = -1;
416 }
417 
418 #include "NamespaceFooter.H"
419 #endif
int m_nComp
number of data values at each face in BaseEBFaceFAB
Definition: BaseEBFaceFAB.H:255
void clear()
Definition: BaseEBFaceFABI.H:225
bool ok()
Definition: BoxIterator.H:215
const Box & getRegion() const
Definition: BaseEBFaceFABI.H:324
void setVal(const T &value)
Definition: BaseEBFaceFABI.H:236
bool ok() const
#define CH_assert(cond)
Definition: CHArray.H:37
int nComp() const
Definition: BaseEBFaceFABI.H:264
bool cellCentered() const
Definition: Box.H:1940
void setCoveredFaceVal(const T &a_val, const int &a_comp, const bool &a_doMulti=true)
Definition: BaseEBFaceFABI.H:23
Definition: FaceIndex.H:28
const ProblemDomain & getDomain() const
int size() const
Definition: Interval.H:64
int begin() const
Definition: Interval.H:86
Box m_region
the cell-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:264
Definition: EBISBox.H:46
bool contains(const IntVect &p) const
Definition: Box.H:1888
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:343
const int SpaceDim
Definition: SPACE.H:39
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:76
virtual ~BaseEBFaceFAB()
Definition: BaseEBFaceFABI.H:216
BaseFab< T > m_regFAB
data at faces between two single-valued cells
Definition: BaseEBFaceFAB.H:252
Structure for passing component ranges in code.
Definition: Interval.H:23
int sign(const Side::LoHiSide &a_side)
MiniIFFAB< T > m_irrFAB
data at faces which abut multi-valued cells
Definition: BaseEBFaceFAB.H:250
void copy(const Box &RegionFrom, const Interval &destInt, const Box &RegionTo, const BaseEBFaceFAB< T > &source, const Interval &srcInt)
Definition: BaseEBFaceFABI.H:127
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2166
const Box & getCellRegion() const
Definition: BaseEBFaceFABI.H:333
const EBISBox & getEBISBox() const
Definition: BaseEBFaceFABI.H:100
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseEBFaceFABI.H:88
size_t size() const
Definition: Vector.H:177
int size(const Box &R, const Interval &comps) const
Definition: BaseEBFaceFABI.H:64
Definition: BaseFab.H:76
const BaseFab< T > & getSingleValuedFAB() const
Definition: BaseEBFaceFABI.H:294
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:161
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Box & grow(int i)
grow functions
Definition: Box.H:2268
int end() const
Definition: Interval.H:91
Box m_regionFace
the face-centered region over which the BaseEBFaceFAB lives
Definition: BaseEBFaceFAB.H:261
const Box & domainBox() const
Returns the logical computational domain.
Definition: ProblemDomain.H:868
int direction() const
Definition: BaseEBFaceFABI.H:314
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1863
virtual void define(const EBISBox &a_ebisBox, const Box &a_region, int a_iDir, int a_nVar)
Definition: BaseEBFaceFABI.H:181
void setDefaultValues()
Definition: BaseEBFaceFABI.H:411
int m_iDir
Definition: BaseEBFaceFAB.H:258
const MiniIFFAB< T > & getMultiValuedFAB() const
Definition: BaseEBFaceFABI.H:274
bool isDefined() const
Definition: BaseEBFaceFABI.H:255