Chombo + EB  3.0
BaseEBCellFAB.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 _BASEEBCELLFAB_H_
14 #define _BASEEBCELLFAB_H_
15 
16 #include <cmath>
17 #include <cstdlib>
18 #include "Vector.H"
19 #include "EBISBox.H"
20 #include "BaseIVFAB.H"
21 #include "IntVectSet.H"
22 #include "BaseFab.H"
23 #include "MiniIVFAB.H"
24 #include "NamespaceHeader.H"
25 
26 /// Array defined at the VolIndexs of an Box in an EBIS.
27 /**
28  An BaseEBCellFAB is a templated holder for cell-centered
29  data over the intersection of a box and an EbisBox.
30  At every uncovered VolIndex in this intersection,
31  the BaseEBCellFAB contains a specified number of data values.
32  At singly valued cells,
33  the data is stored internally in a BaseFab. At multiply-valued
34  cells, the data is stored internally in an BaseIVFAB.
35  BaseEBCellFAB provides indexing by VolIndex.
36  This class does not provide a copy constructor or assignment operator
37  for all the usual reasons.
38 */
39 template <class T>
41 {
42 public:
43 
44  /// for AggStencil
45  int numDataTypes() const
46  {
47  return 2;
48  }
49 
50  /// for AggStencil
51  int dataType(const BaseIndex& a_baseInd) const
52  {
53  const VolIndex* vofPtr = dynamic_cast<const VolIndex *>(&a_baseInd);
54  if (vofPtr == NULL) MayDay::Error("Trying to index into an EBCellFAB with something that is not a VolIndex");
55  int retval = 0;
56  if (m_multiCells.contains(vofPtr->gridIndex()))
57  {
58  retval = 1;
59  }
60  return retval;
61  }
62 
63  ///for AggStencil
64  long offset(const BaseIndex& a_baseInd, const int a_ivar) const
65  {
66  const VolIndex* vofPtr = dynamic_cast<const VolIndex *>(&a_baseInd);
67  if (vofPtr == NULL) MayDay::Error("Trying to index into an EBCellFAB with something that is not a VolIndex");
68  long retval = 0;
69  if (m_multiCells.contains(vofPtr->gridIndex()))
70  {
71  retval = m_irrFAB.offset(*vofPtr, a_ivar);
72  }
73  else
74  {
75  retval = m_regFAB.offset(vofPtr->gridIndex(), a_ivar);
76  }
77  return retval;
78  }
79 
80  ///for AggStencil
81  T* dataPtr(int a_dataType, int a_ivar)
82  {
83  if (a_dataType == 0)
84  {
85  return m_regFAB.dataPtr(a_ivar);
86  }
87  else if (a_dataType == 1)
88  {
89  return m_irrFAB.dataPtr(a_ivar);
90  }
91  else
92  {
93  MayDay::Error("bogus datatype input into dataPtr");
94  }
95  return NULL; //just avoiding compiler warnings with this
96  }
97  ///for AggStencil
98  const T* dataPtr(int a_dataType, int a_ivar) const
99  {
100  if (a_dataType == 0)
101  {
102  return m_regFAB.dataPtr(a_ivar);
103  }
104  else if (a_dataType == 1)
105  {
106  return m_irrFAB.dataPtr(a_ivar);
107  }
108  else
109  {
110  MayDay::Error("bogus datatype input into dataPtr");
111  }
112  return NULL; //just avoiding compiler warnings with this
113  }
114 
115  ///
116  BaseEBCellFAB();
117 
118  ///
119  BaseEBCellFAB(const EBISBox& a_ebisBox, const Box& a_region, int a_nVar);
120 
121  ///
122  virtual void define(const EBISBox& a_ebisBox, const Box& a_region, int a_nVar);
123 
124  /// aliasing copy-ish constructor. Used when the 'alias' function is invoked on LevelData
125  /**
126  Constructs an 'aliased' BaseEBCellFab of the requested interval of the
127  argument BaseEBCellFab. This BaseEBCellFab does not allocate any memory, but
128  sets its data pointer into the memory pointed to by the argument
129  BaseEBCellFab. It is the users responsiblity to ensure this aliased
130  BaseEBCellFab is not used after the original BaseEBCellFab has deleted its data ptr
131  (resize, define(..) called, or destruction, etc.).
132 
133  This aliased BaseEBCellFab will also generate side effects (modifying the values
134  of data in one will modify the other's data).
135 
136  This aliased BaseFab will have a_comps.size() components, starting at zero.
137  */
138  BaseEBCellFAB(const Interval& a_comps,
139  BaseEBCellFAB<T>& a_original);
140 
141  ///
142  virtual ~BaseEBCellFAB();
143 
144  ///
145  void clear();
146 
147  ///
148  void setVal(const T& value);
149 
150  ///
151  void setVal(int ivar,const T& value);
152 
153  ///
154  void setVal(const T& value,
155  const Box& a_box,
156  int a_nstart,
157  int a_numcomp);
158 
159  ///
160  bool isDefined() const;
161 
162  ///
163  int nComp() const ;
164 
165  ///
166  const Box& getRegion() const ;
167 
168  ///
169  const Box& box() const ;
170 
171  ///
172  const IntVectSet& getMultiCells() const ;
173 
174  ///
175  const BaseIVFAB<T>& getMultiValuedFAB() const;
176 
177  ///
179 
180  ///
181  const BaseFab<T>& getSingleValuedFAB() const;
182 
183  ///
185 
186  /**
187  Arg a_isKnownMultiValued should be set to:
188  -1 if arg a_ndin is known to be in a single-valued cell;
189  +1 if arg a_ndin is known to be in a multi-valued cell;
190  0 if you're not sure (in which case the expensive IntVectSet::contains()
191  function gets called.
192 
193  Note: BVS says third arg is a wart that makes this operator look less like
194  a logical array access.
195  */
196  const T& operator() (const VolIndex& a_ndin, int a_nVarLoc,
197  int a_isKnownMultiValued=0) const;
198 
199  /**
200  Arg a_isKnownMultiValued should be set to:
201  -1 if arg a_ndin is known to be in a single-valued cell;
202  +1 if arg a_ndin is known to be in a multi-valued cell;
203  0 if you're not sure (in which case the expensive IntVectSet::contains()
204  function gets called.
205  */
206  T& operator() (const VolIndex& a_ndin,int a_nVarLoc,
207  int a_isKnownMultiValued=0);
208 
209  void fill(T* array, const VolIndex& a_ndin, const Interval& a_comps) const;
210 
211  void assign(const T* array, const VolIndex& a_ndin, const Interval& a_comps);
212  ///
213  void copy(const Box& RegionFrom,
214  const Interval& destInt,
215  const Box& RegionTo,
216  const BaseEBCellFAB<T>& source,
217  const Interval& srcInt);
218 
219  ///
220  BaseEBCellFAB<T>& copy(const BaseEBCellFAB<T>& source);
221 
222  ///
223  /**
224  This stuff required by LevelData in parallel:
225  */
226  static int preAllocatable()
227  {
228  return 1; // symmetric messaging
229  }
230 
231  ///
232  int size(const Box& R, const Interval& comps) const ;
233 
234  ///
235  void linearOut(void* buf, const Box& R, const Interval& comps) const ;
236 
237  ///
238  void linearIn(void* buf, const Box& R, const Interval& comps);
239 
240  ///invalid but necessary for leveldata to compile
241  BaseEBCellFAB(const Box& a_region, int a_nVar)
242  {
243  MayDay::Error("invalid constructor called for baseebcellfab");
244  }
245 
246  ///
247  const EBISBox& getEBISBox() const;
248 
249  ///
250  void
251  setCoveredCellVal(const T& a_val,
252  const int& a_comp,
253  const bool& a_doMulti=true);
254 
255 protected:
256 
257  ///data at multi-valued cells
258  //BaseIVFAB<T> m_irrFAB;
260 
261  ///data at single-valued cells
263 
265  //number of data values at each VolIndex
266  int m_nComp;
267 
268  ///region over which the BaseEBCellFAB exists
270 
271  ///whether each given cell is multi-valued
273 
274  ///is m_multiCells not empty?
276 
277  ///has full define function been called?
279 
280 protected:
281  void
283 
284 private:
285  //disallowed for perfomance reasons
286  void operator= (const BaseEBCellFAB<T>& ebcin)
287  {
288  MayDay::Error("operator= for baseebcellfab undefined");
289  }
291  {
292  MayDay::Error("copy constructor for baseebcellfab undefined");
293  }
294 };
295 
296 #include "NamespaceFooter.H"
297 
298 #ifndef CH_EXPLICIT_TEMPLATES
299 #include "BaseEBCellFABI.H"
300 #endif // CH_EXPLICIT_TEMPLATES
301 
302 #endif
bool m_hasMultiCells
is m_multiCells not empty?
Definition: BaseEBCellFAB.H:275
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseEBCellFABI.H:172
EBISBox m_ebisBox
Definition: BaseEBCellFAB.H:264
const EBISBox & getEBISBox() const
Definition: BaseEBCellFABI.H:539
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
T * dataPtr(int a_dataType, int a_ivar)
for AggStencil
Definition: BaseEBCellFAB.H:81
Definition: EBISBox.H:46
void operator=(const BaseEBCellFAB< T > &ebcin)
Definition: BaseEBCellFAB.H:286
void copy(const Box &RegionFrom, const Interval &destInt, const Box &RegionTo, const BaseEBCellFAB< T > &source, const Interval &srcInt)
Definition: BaseEBCellFABI.H:110
index for other indicies to inherit
Definition: BaseIndex.H:26
int dataType(const BaseIndex &a_baseInd) const
for AggStencil
Definition: BaseEBCellFAB.H:51
const T * dataPtr(int a_dataType, int a_ivar) const
for AggStencil
Definition: BaseEBCellFAB.H:98
const Box & getRegion() const
Definition: BaseEBCellFABI.H:315
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 IntVect & gridIndex() const
Definition: VolIndex.H:119
const IntVectSet & getMultiCells() const
Definition: BaseEBCellFABI.H:184
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
void setVal(const T &value)
Definition: BaseEBCellFABI.H:264
long offset(const BaseIndex &a_baseInd, const int a_ivar) const
for AggStencil
Definition: BaseEBCellFAB.H:64
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.
static int preAllocatable()
Definition: BaseEBCellFAB.H:226
Definition: BaseFab.H:76
BaseEBCellFAB(const Box &a_region, int a_nVar)
invalid but necessary for leveldata to compile
Definition: BaseEBCellFAB.H:241
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
bool m_isDefined
has full define function been called?
Definition: BaseEBCellFAB.H:278
const BaseFab< T > & getSingleValuedFAB() const
Definition: BaseEBCellFABI.H:354
void setDefaultValues()
Definition: BaseEBCellFABI.H:530
void clear()
Definition: BaseEBCellFABI.H:252
BaseEBCellFAB()
Definition: BaseEBCellFABI.H:193
Volume of Fluid Index.
Definition: VolIndex.H:31
IntVectSet m_multiCells
whether each given cell is multi-valued
Definition: BaseEBCellFAB.H:272
BaseEBCellFAB(const BaseEBCellFAB< T > &ebcin)
Definition: BaseEBCellFAB.H:290
bool contains(const IntVect &iv) const
Returns true if this IntVectSet contains iv.
int numDataTypes() const
for AggStencil
Definition: BaseEBCellFAB.H:45
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
Definition: MiniIVFAB.H:36
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