Chombo + EB + MF  3.2
BaseIVFABI.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 _BASEIVFABI_H_
12 #define _BASEIVFABI_H_
13 #include "MayDay.H"
14 #include "IntVectSet.H"
15 #include "VoFIterator.H"
16 #include "parstream.H"
17 #include "SPMD.H"
18 #include "DebugOut.H"
19 #include "EBDebugOut.H"
20 #include "SPMD.H"
21 #include "NamespaceHeader.H"
22 
23 template <class T>
24 bool BaseIVFAB<T>::s_verbose = false;
25 
26 template <class T>
27 void
28 BaseIVFAB<T>::setVerbose(bool a_verbose)
29 {
30  s_verbose = a_verbose;
31 }
32 template <class T>
33 bool BaseIVFAB<T>::s_verboseDebug = false;
34 
35 template <class T>
36 void
37 BaseIVFAB<T>::setVerboseDebug(bool a_verboseDebug)
38 {
39  s_verboseDebug = a_verboseDebug;
40 }
41 /******************/
42 template <class T> inline
43 const EBGraph&
45 {
46  return m_ebgraph;
47 }
48 /*************/
49 template <class T> inline
50 const IntVectSet&
52 {
53  return m_ivs;
54 }
55 /******************/
56 template <class T> inline
58 {
59  setDefaultValues();
60 }
61 /******************/
62 template <class T> inline
64 {
65  clear();
66 }
67 /******************/
68 template <class T> inline
70  const EBGraph& a_ebgraph,
71  const int& a_nvarin)
72 {
73  setDefaultValues();
74  define(a_ivsin, a_ebgraph, a_nvarin);
75 }
76 /******************/
77 #if defined(__ICC) || defined(__INTEL_COMPILER)
78 #pragma intel optimization_level 0
79 #endif
80 template <class T> inline
81 void
83  const EBGraph& a_ebGraph,
84  const int& a_nvarin)
85 {
86  clear();
87  m_isDefined = true;
88  CH_assert(a_nvarin > 0);
89 
90  m_ivs = a_ivsin;
91  m_nComp = a_nvarin;
92  m_ebgraph = a_ebGraph;
93  m_nVoFs = 0;
94 
95  if (!a_ivsin.isEmpty())
96  {
97  Box minbox = a_ivsin.minBox();
98  m_fab.resize(minbox, 1);
99  m_fab.setVal(NULL);
100 
101  //figure out how long vector has to be
102  IVSIterator ivsit(m_ivs);
103  for (ivsit.reset(); ivsit.ok(); ++ivsit)
104  {
105  m_nVoFs += m_ebgraph.numVoFs(ivsit());
106  }
107  //now allocate the vector set the fab to go into
108  //the pool of data at the first component of the first
109  //vof
110  if (m_nVoFs > 0)
111  {
112  // Note: clear() was called above so this isn't a memory leak
113  //m_data = new T[m_nVoFs*m_nComp];
114  m_data.resize(m_nVoFs*m_nComp);
115  T* currentLoc = &m_data[0];
116  for (ivsit.reset(); ivsit.ok(); ++ivsit)
117  {
118  int numVoFs = m_ebgraph.numVoFs(ivsit());
119  m_fab(ivsit(), 0) = currentLoc;
120  currentLoc += numVoFs;
121  }
122  }
123  }
124 }
125 /******************/
126 template <class T> inline
127 void
128 BaseIVFAB<T>::setVal(const T& a_value)
129 {
130  for (int ivec = 0; ivec < m_nVoFs*m_nComp; ivec++)
131  {
132  m_data[ivec] = a_value;
133  }
134 }
135 
136 /******************/
137 template <class T> inline
138 void
139 BaseIVFAB<T>::setVal(int ivar, const T& a_value)
140 {
141  CH_assert(isDefined());
142  CH_assert(ivar >= 0);
143  CH_assert(ivar < m_nComp);
144  int ioffset = ivar*m_nVoFs;
145  for (int ivec = 0; ivec < m_nVoFs; ivec ++)
146  {
147  m_data[ivec+ioffset] = a_value;
148  }
149 }
150 /******************/
151 template <class T> inline
152 void
153 BaseIVFAB<T>::setVal(const T& a_value,
154  const Box& a_box,
155  int a_nstart,
156  int a_numcomp)
157 
158 {
159  CH_assert(isDefined());
160 
161  if ( !m_ivs.isEmpty() )
162  {
163  IntVectSet ivsIntersect = m_ivs;
164  ivsIntersect &= a_box;
165  BaseIVFAB<T>& thisFAB = *this;
166  for (VoFIterator vofit(ivsIntersect, m_ebgraph); vofit.ok(); ++vofit)
167  {
168  const VolIndex& vof = vofit();
169  for (int icomp = a_nstart; icomp < a_numcomp; icomp++)
170  {
171  thisFAB(vof, icomp) = a_value;
172  }
173  }
174  }
175 }
176 /******************/
177 template <class T> inline
178 void
179 BaseIVFAB<T>::copy(const Box& a_fromBox,
180  const Interval& a_dstInterval,
181  const Box& a_toBox,
182  const BaseIVFAB<T>& a_src,
183  const Interval& a_srcInterval)
184 {
185  CH_assert(isDefined());
186  CH_assert(a_src.isDefined());
187  CH_assert(a_srcInterval.size() == a_dstInterval.size());
188  CH_assert(a_dstInterval.begin() >= 0);
189  CH_assert(a_srcInterval.begin() >= 0);
190  CH_assert(a_dstInterval.end() < m_nComp);
191  CH_assert(a_srcInterval.end() < a_src.m_nComp);
192 
193  if ((!m_ivs.isEmpty()) && (!a_src.m_ivs.isEmpty()))
194  {
195  CH_assert( (a_fromBox == a_toBox) || m_ebgraph.getDomain().isPeriodic() );
196  Box intBox = a_fromBox;
197  IntVectSet ivsIntersect = m_ivs;
198  ivsIntersect &= a_src.m_ivs; //how did this ever work without this line?
199  ivsIntersect &= intBox; //
200  BaseIVFAB<T>& thisFAB = *this;
201  int compSize = a_srcInterval.size();
202  for (VoFIterator vofit(ivsIntersect, m_ebgraph); vofit.ok(); ++vofit)
203  {
204  const VolIndex& vof = vofit();
205  for (int icomp = 0; icomp < compSize; icomp++)
206  {
207  int isrccomp = a_srcInterval.begin() + icomp;
208  int idstcomp = a_dstInterval.begin() + icomp;
209  thisFAB(vof, idstcomp) = a_src(vof, isrccomp);
210  }
211  }
212  }
213 }
214 /******************/
215 template <class T> inline
216 int BaseIVFAB<T>::size(const Box& a_region,
217  const Interval& a_comps) const
218 {
219  CH_assert(isDefined());
220 
221 
222  //create set of cells in fab that are also in the input region
223  IntVectSet subIVS = m_ivs;
224  subIVS &= a_region;
225 
226  VoFIterator vofit(subIVS, m_ebgraph);
227 
228  const Vector<VolIndex>& vofs = vofit.getVector();
229  //account for vof list
230  int vofsize = linearListSize(vofs);
231 
232  //add for each data point
233  int datasize = 0;
234  for (unsigned int ivof = 0; ivof < vofs.size(); ivof++)
235  {
236  if (s_verboseDebug)
237  {
238  IntVect iv = vofs[ivof].gridIndex();
239  pout() << "BaseIVFAB::size vof " << vofs[ivof] << " Is irregular? " << m_ebgraph.isIrregular(iv) << endl;
240  }
241  for (int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
242  {
243  const T& dataPt = (*this)(vofs[ivof], icomp);
244  int pointsize = CH_XD::linearSize(dataPt);
245  datasize += pointsize;
246  }
247 
248  }
249 
250  int retval = vofsize + datasize;
251  if (s_verboseDebug)
252  {
253  pout() << "BaseIVFAB::size " << retval << endl;
254  }
255  return retval;
256 }
257 /********************/
258 template <class T> inline
259 void BaseIVFAB<T>::linearOut(void* a_buf,
260  const Box& a_region,
261  const Interval& a_comps) const
262 {
263  CH_assert(isDefined());
264  CH_TIME("BaseIVFAB::linearout");
265  if (s_verboseDebug)
266  {
267  pout() << "" << endl;
268  pout() << "BaseIVFAB<T>::linearOut " << " for box " << a_region << endl;
269  }
270 
271  //create set of cells in fab that are also in the input region
272  IntVectSet subIVS = m_ivs;
273  subIVS &= a_region;
274 
275  VoFIterator vofit(subIVS, m_ebgraph);
276  const Vector<VolIndex>& vofs = vofit.getVector();
277  //output the vofs.
278  unsigned char* charbuffer = (unsigned char *) a_buf;
279  linearListOut(charbuffer, vofs);
280  charbuffer += linearListSize(vofs);
281 
282  //output the data
283  for (unsigned int ivof = 0; ivof < vofs.size(); ivof++)
284  {
285  const VolIndex& vof = vofs[ivof];
286  if (s_verboseDebug)
287  {
288  pout() << "vof " << vof << endl;
289  }
290  for (int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
291  {
292  const T& dataPt = (*this)(vof, icomp);
293  CH_XD::linearOut(charbuffer, dataPt);
294  //increment the buffer offset
295  charbuffer += linearSize(dataPt);
296  }
297  }
298 }
299 /********************/
300 template <class T> inline
301 void BaseIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
302 {
303  CH_assert(isDefined());
304  CH_TIME("BaseIVFAB::linearin");
305  //input the vofs
306 
307  if (s_verboseDebug)
308  {
309  pout() << "" << endl;
310  pout() << "BaseIVFAB<T>::linearIn " << " for box " << a_region << endl;
311  }
312  Vector<VolIndex> vofs;
313  unsigned char* charbuffer = (unsigned char *) a_buf;
314  linearListIn(vofs, charbuffer);
315  charbuffer += linearListSize(vofs);
316 
317  //input the data
318  for (unsigned int ivof = 0; ivof < vofs.size(); ivof++)
319  {
320  const VolIndex& vof = vofs[ivof];
321  if (s_verboseDebug)
322  {
323  pout() << "vof " << vof << endl;
324  }
325  for (int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
326  {
327  T& dataPt = (*this)(vof, icomp);
328  CH_XD::linearIn(dataPt, charbuffer) ;
329  //increment the buffer offset
330  charbuffer += linearSize(dataPt);
331  }
332  }
333 }
334 /********************/
335 template <class T> inline
336 T*
337 BaseIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
338 {
339  CH_assert(isDefined());
340  CH_assert(m_ivs.contains(a_vof.gridIndex()));
341  CH_assert((a_comp >= 0) && (a_comp < m_nComp));
342 
343  T* dataPtr = (T*)(m_fab(a_vof.gridIndex(), 0));
344  dataPtr += a_vof.cellIndex();
345  dataPtr += a_comp*m_nVoFs;
346  return dataPtr;
347 }
348 /********************/
349 template <class T> inline
350 void
352 {
353  m_nComp = 0;
354  m_nVoFs = 0;
355  m_ivs.makeEmpty();
356  m_fab.clear();
357  //if (m_data != NULL)
358  // {
359  // delete[] m_data;
360  // m_data = NULL;
361  // }
362  m_isDefined = false;
363 }
364 /*************************/
365 template <class T> inline
366 bool
368 {
369  return (m_isDefined);
370 }
371 /*************************/
372 template <class T> inline
373 int
375 {
376  return m_nVoFs;
377 }
378 /*************************/
379 template <class T> inline
380 T*
381 BaseIVFAB<T>::dataPtr(const int& a_comp)
382 {
383  CH_assert(a_comp >= 0);
384  CH_assert(a_comp <= m_nComp);
385  static T* dummy = NULL;
386  if (m_nVoFs == 0) return dummy;
387  // T* retval = m_data + a_comp*m_nVoFs;
388  T* retval = &(m_data[a_comp*m_nVoFs]);
389  return retval;
390 }
391 /*************************/
392 template <class T> inline
393 const T*
394 BaseIVFAB<T>::dataPtr(const int& a_comp) const
395 {
396  CH_assert(a_comp >= 0);
397  CH_assert(a_comp <= m_nComp);
398  static T* dummy = NULL;
399  if (m_nVoFs == 0) return dummy;
400  const T* retval = &(m_data[a_comp*m_nVoFs]);
401  // const T* retval = m_data + a_comp*m_nVoFs;
402  return retval;
403 }
404 /*************************/
405 template <class T> inline
406 int
408 {
409  return m_nComp;
410 }
411 /*************************/
412 template <class T> inline
413 T&
415  const int& a_comp)
416 {
417  CH_assert(isDefined());
418  CH_assert(a_comp >= 0);
419  CH_assert(a_comp < m_nComp);
420  T* dataPtr = getIndex(a_ndin, a_comp);
421  return(*dataPtr);
422 }
423 /**************************/
424 template <class T> inline
425 const T&
427  const int& a_comp) const
428 {
429  CH_assert(isDefined());
430  CH_assert(a_comp >= 0);
431  CH_assert(a_comp < m_nComp);
432 
433  T* dataPtr = getIndex(a_ndin, a_comp);
434  return(*dataPtr);
435 }
436 /******************/
437 template <class T> inline
438 void
440 {
441  m_isDefined = false;
442  m_nVoFs = 0;
443  m_nComp = 0;
444  //m_data = NULL;
445  m_data.resize(0);
446 }
447 
448 #include "NamespaceFooter.H"
449 #endif
450 
std::ostream & pout()
Use this in place of std::cout for program output.
const IntVectSet & getIVS() const
Definition: BaseIVFABI.H:51
static void setVerbose(bool a_verbose)
Definition: BaseIVFABI.H:28
virtual ~BaseIVFAB()
Definition: BaseIVFABI.H:63
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
#define CH_assert(cond)
Definition: CHArray.H:37
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
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
void linearListOut(void *const a_outBuf, const Vector< T > &a_inputT)
Definition: SPMDI.H:258
void setVal(const T &value)
Definition: BaseIVFABI.H:128
bool ok() const
bool ok() const
returns true if this iterator is still in its IntVectSet
Definition: IntVectSet.H:711
static void setVerboseDebug(bool a_verboseDebug)
Definition: BaseIVFABI.H:37
void reset()
same as begin()
Definition: IntVectSet.H:722
int size() const
Definition: Interval.H:75
Geometric description within a box.
Definition: EBGraph.H:427
bool isDefined() const
Definition: BaseIVFABI.H:367
const Box & minBox() const
Returns the minimum enclosing box of this IntVectSet.
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: BaseIVFABI.H:259
int cellIndex() const
Definition: VolIndex.H:133
const EBGraph & getEBGraph() const
Definition: BaseIVFABI.H:44
const Vector< VolIndex > getVector() const
const IntVect & gridIndex() const
Definition: VolIndex.H:125
#define CH_TIME(name)
Definition: CH_Timer.H:82
Structure for passing component ranges in code.
Definition: Interval.H:23
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:33
bool isEmpty() const
Returns true if no IntVects are in this IntVectSet.
int linearSize(const T &inputT)
Definition: SPMDI.H:21
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
int begin() const
Definition: Interval.H:99
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
int m_nComp
Definition: BaseIVFAB.H:254
void linearListIn(Vector< T > &a_outputT, const void *const a_inBuf)
Definition: SPMDI.H:229
Iterator for all vofs within an IntVectSet and an Ebgraph.
Definition: VoFIterator.H:27
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: BaseIVFABI.H:301
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
int linearListSize(const Vector< T > &a_input)
Definition: SPMDI.H:290
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
size_t size() const
Definition: Vector.H:192
Volume of Fluid Index.
Definition: VolIndex.H:31
int end() const
Definition: Interval.H:104
Iterator for an IntVectSet.
Definition: IntVectSet.H:640
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:27
int size(const Box &R, const Interval &comps) const
Definition: BaseIVFABI.H:216
virtual T * getIndex(const VolIndex &a_vof, const int &a_comp) const
get index into vector
Definition: BaseIVFABI.H:337
Definition: BaseIVFAB.H:32