Chombo + EB + MF  3.2
BaseIVFAB.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 #ifndef _BASEIVFAB_H_
12 #define _BASEIVFAB_H_
13 
14 #include <cmath>
15 #include <cstdlib>
16 #include "SPACE.H"
17 #include "Vector.H"
18 #include "IntVectSet.H"
19 #include "VolIndex.H"
20 #include "BaseIndex.H"
21 #include "BaseFab.H"
22 #include "EBGraph.H"
23 #include "NamespaceHeader.H"
24 
25 
26 ///
27 /**
28  BaseIVFAB is a templated
29  data holder defined at the VoFs of an irregular domain.
30 */
31 template <class T>
32 class BaseIVFAB
33 {
34 public:
35  ///
36  /**
37  Default constructor. Constructs an uninitialized IVFAB. You must
38  subsequently call {\bf define} before using this IVFAB.
39  */
40  BaseIVFAB();
41 
42  ///
43  /**
44  Defining constructor. Specifies the irregular domain
45  and the number of data components per VoF. The irregular domain
46  must lie completely within the EBGraph. The
47  contents are uninitialized. Calls full define function.
48  */
49  BaseIVFAB(const IntVectSet& a_region,
50  const EBGraph& a_ebgraph,
51  const int& a_nvarin);
52 
53  /// for AggStencil
54  int numDataTypes() const
55  {
56  return 1;
57  }
58  /// for AggStencil
59  int dataType(const BaseIndex& a_baseInd) const
60  {
61  return 0;
62  }
63 
64  T* dataPtr(int a_dataType, int a_ivar)
65  {
66  return dataPtr(a_ivar);
67  }
68 
69  const T* dataPtr(int a_dataType, int a_ivar) const
70  {
71  return dataPtr(a_ivar);
72  }
73 
74 
75 
76  ///
77  /**
78  Constructs an 'aliased' BaseIVFAB of the requested interval of the
79  argument BaseIVFAB. This BaseIVFAB does not allocate any memory, but
80  sets its data pointer into the memory pointed to by the argument
81  BaseIVFAB. It is the users responsiblity to ensure this aliased
82  BaseIVFAB is not used after the original BaseIVFAB has deleted its data ptr
83  (resize, define(..) called, or destruction, etc.).
84 
85  This aliased BaseIVFAB will also generate side effects (modifying the values
86  of data in one will modify the other's data).
87 
88  This aliased BaseIVFAB will have a_comps.size() components, starting at zero.
89  */
90  BaseIVFAB(const Interval& a_comps,
91  BaseIVFAB<T>& a_original);
92 
93 
94  ///
95  virtual ~BaseIVFAB();
96 
97  ///
98  /**
99  Full define function. Specifies the irregular domain and the
100  number of data components per VoF. The irregular domain
101  must lie completely within the EBGraph. The contents
102  are uninitialized. If it has previously been defined, the old definition
103  data is overwritten and lost.
104  */
105  virtual void define(const IntVectSet& a_region,
106  const EBGraph& a_ebgraph,
107  const int& a_nvarin);
108 
109  ///
110  /**
111  Set a value at every data location.
112  */
113  void setVal(const T& value);
114 
115  ///
116  /**
117  Set a value at every data location.
118  */
119  void setVal(int ivar, const T& value);
120 
121  ///
122  /**
123  Set a value at every data location within a_box
124  */
125  void setVal(const T& a_value,
126  const Box& a_box,
127  int a_nstart,
128  int a_numcomp);
129  ///
130  void copy(const Box& a_fromBox,
131  const Interval& a_destInterval,
132  const Box& a_toBox,
133  const BaseIVFAB<T>& a_src,
134  const Interval& a_srcInterval);
135 
136  ///
137  /**
138  This stuff required by LevelData in parallel:
139  */
140 
141  static int preAllocatable()
142  {
143  return 2; // default: NOT symmetric allocatable.
144  }
145 
146  ///
147  int size(const Box& R, const Interval& comps) const ;
148 
149  ///
150  void linearOut(void* buf, const Box& R, const Interval& comps) const;
151 
152  ///
153  void linearIn(void* buf, const Box& R, const Interval& comps);
154 
155  ///
156  /**
157  Remove all data from this BaseIVFAB.
158  You must call {\bf define} again in order
159  to use it.
160  */
161  virtual void clear();
162 
163  ///
164  /**
165 
166  Tells whether this BaseIVFAB has been defined, either with a constructor
167  or with {\bf define}. It must be initialized in order to access its data.
168  */
169  bool
170  isDefined() const;
171 
172  ///
173  /**
174  Return the number of VoFs in this BaseIVFAB.
175  */
176  int numVoFs() const;
177 
178  ///
179  /**
180  Return the number of data components of this BaseIVFAB.
181  */
182  int nComp() const;
183 
184  ///
185  /**
186  Return the irregular domain of the BaseIVFAB.
187  */
188  const IntVectSet& getIVS() const;
189 
190  ///
191  const EBGraph& getEBGraph() const;
192 
193  ///
194  /**
195  Indexing operator. Return a reference to the contents of this IVFAB,
196  at the specified VoF and data component. The first component is
197  zero, the last is {\em nvar-1}. The returned object is a modifiable
198  lvalue.
199  */
200  T& operator() (const VolIndex& a_vof,const int& varlocin);
201  const T& operator() (const VolIndex& a_vof,const int& varlocin) const;
202 
203 
204  ///invalid but necessary for leveldata to compile
205  BaseIVFAB(const Box& a_region, int a_nVar)
206  {
207  MayDay::Error("invalid constructor called for baseebcellfab");
208  }
209 
210  ///
211  static void setVerbose(bool a_verbose);
212 
213  ///
214  static void setVerboseDebug(bool a_verboseDebug);
215 
216  ///
217  T* dataPtr(const int& a_comp);
218 
219  ///
220  const T* dataPtr(const int& a_comp) const;
221 
222  ///get index into vector
223  /**
224  needs to be public so that bulk stencils can be constructed
225  */
226  virtual T* getIndex(const VolIndex& a_vof,const int& a_comp) const;
227 
228  ///for AggStencil
229  long offset(const BaseIndex& a_vof, const int& a_ivar) const
230  {
231  const VolIndex* vof = dynamic_cast< const VolIndex* >(&a_vof);
232  if (vof == NULL) MayDay::Error("cast failed:BaseIVFAB only takes vofs for indexing");
233 
234  const T& conval = (*this)(*vof, a_ivar);
235  const T* conptr = &conval;
236  const T* srtptr = dataPtr(0);
237  long roffset = (long)(conptr - srtptr);
238  return roffset;
239  }
240  static bool s_verboseDebug;
241 
242 private:
243 
244 
245 protected:
246 
247  virtual void
249 
250  //has to be this in case someone does a bool
251  //T* m_data;
253 
254  int m_nComp;
255  int m_nVoFs;
256 
258 
259  //object to store pointers to facilitate fast indexing
263 
264  static bool s_verbose;
265 private:
266  //disallowed for all the usual reasons
267  void operator= (const BaseIVFAB<T>& a_input)
268  {
269  MayDay::Error("BaseIVFAB operator = not defined");
270  }
271  BaseIVFAB(const BaseIVFAB<T>& a_input)
272  {
273  MayDay::Error("invalid operator");
274  }
275 };
276 
277 #include "NamespaceFooter.H"
278 
279 #ifndef CH_EXPLICIT_TEMPLATES
280 #include "BaseIVFABI.H"
281 #endif
282 
283 #endif
const IntVectSet & getIVS() const
Definition: BaseIVFABI.H:51
static void setVerbose(bool a_verbose)
Definition: BaseIVFABI.H:28
int m_nVoFs
Definition: BaseIVFAB.H:255
static bool s_verboseDebug
Definition: BaseIVFAB.H:240
virtual ~BaseIVFAB()
Definition: BaseIVFABI.H:63
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
IntVectSet m_ivs
Definition: BaseIVFAB.H:261
int nComp() const
Definition: BaseIVFABI.H:407
BaseIVFAB()
Definition: BaseIVFABI.H:57
virtual void setDefaultValues()
Definition: BaseIVFABI.H:439
bool m_isDefined
Definition: BaseIVFAB.H:262
void copy(const Box &a_fromBox, const Interval &a_destInterval, const Box &a_toBox, const BaseIVFAB< T > &a_src, const Interval &a_srcInterval)
Definition: BaseIVFABI.H:179
one dimensional dynamic array
Definition: Vector.H:53
void setVal(const T &value)
Definition: BaseIVFABI.H:128
long offset(const BaseIndex &a_vof, const int &a_ivar) const
for AggStencil
Definition: BaseIVFAB.H:229
index for other indicies to inherit
Definition: BaseIndex.H:26
static void setVerboseDebug(bool a_verboseDebug)
Definition: BaseIVFABI.H:37
int dataType(const BaseIndex &a_baseInd) const
for AggStencil
Definition: BaseIVFAB.H:59
Geometric description within a box.
Definition: EBGraph.H:427
bool isDefined() const
Definition: BaseIVFABI.H:367
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseIVFABI.H:259
BaseIVFAB(const Box &a_region, int a_nVar)
invalid but necessary for leveldata to compile
Definition: BaseIVFAB.H:205
const T * dataPtr(int a_dataType, int a_ivar) const
Definition: BaseIVFAB.H:69
const EBGraph & getEBGraph() const
Definition: BaseIVFABI.H:44
BaseFab< T * > m_fab
Definition: BaseIVFAB.H:260
static bool s_verbose
Definition: BaseIVFAB.H:264
Structure for passing component ranges in code.
Definition: Interval.H:23
Vector< T > m_data
Definition: BaseIVFAB.H:252
virtual void clear()
Definition: BaseIVFABI.H:351
virtual void define(const IntVectSet &a_region, const EBGraph &a_ebgraph, const int &a_nvarin)
Definition: BaseIVFABI.H:82
int numVoFs() const
Definition: BaseIVFABI.H:374
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.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
BaseIVFAB(const BaseIVFAB< T > &a_input)
Definition: BaseIVFAB.H:271
int m_nComp
Definition: BaseIVFAB.H:254
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseIVFABI.H:301
EBGraph m_ebgraph
Definition: BaseIVFAB.H:257
T * dataPtr(int a_dataType, int a_ivar)
Definition: BaseIVFAB.H:64
T & operator()(const VolIndex &a_vof, const int &varlocin)
Definition: BaseIVFABI.H:414
Volume of Fluid Index.
Definition: VolIndex.H:31
static int preAllocatable()
Definition: BaseIVFAB.H:141
void operator=(const BaseIVFAB< T > &a_input)
Definition: BaseIVFAB.H:267
int size(const Box &R, const Interval &comps) const
Definition: BaseIVFABI.H:216
int numDataTypes() const
for AggStencil
Definition: BaseIVFAB.H:54
virtual T * getIndex(const VolIndex &a_vof, const int &a_comp) const
get index into vector
Definition: BaseIVFABI.H:337
Definition: BaseIVFAB.H:32