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