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