Chombo + EB + MF  3.2
MiniIVFABI.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 _MINIIVFABI_H_
12 #define _MINIIVFABI_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 
24 /******************/
25 template <class T> inline
26 MiniIVFAB<T>::MiniIVFAB():m_nComp(0),m_data(0)
27 {
28 
29 }
30 /******************/
31 template <class T> inline
33 {
34 
35 }
36 
37 template <class T> inline
39  MiniIVFAB<T>& a_original)
40  :m_vofs(a_original.m_vofs),
41  m_Memory(a_original.m_Memory),
42  m_nComp(a_comps.size()),
43  m_data(a_original.dataPtr(a_comps.begin())){ ; }
44 
45 /******************/
46 template <class T> inline
48  const EBGraph& a_ebgraph,
49  const int& a_nvarin)
50 {
51  define(a_ivsin, a_ebgraph, a_nvarin);
52 }
53 /******************/
54 template <class T> inline
55 void
57  const EBGraph& a_ebGraph,
58  const int& a_nvarin)
59 {
60 
61  CH_assert(a_nvarin > 0);
62 
63  m_nComp=a_nvarin;
64 
65  if (!a_ivsin.isEmpty())
66  {
67  int nVoFs = 0;
68  //figure out how long vector has to be
69  IVSIterator ivsit(a_ivsin);
70  for (ivsit.reset(); ivsit.ok(); ++ivsit)
71  {
72  nVoFs += a_ebGraph.numVoFs(ivsit());
73  }
74  //now allocate the vector set the fab to go into
75  //the pool of data at the first component of the first
76  //vof
77  if (nVoFs > 0)
78  {
79  if(!m_vofs)
80  {
81  m_vofs=shared_ptr<Vector<VolIndex> >(new Vector<VolIndex>(nVoFs));
82  m_Memory= shared_ptr<Vector<T> >(new Vector<T>(nVoFs*a_nvarin));
83  m_data = &(m_Memory->operator[](0));
84 
85  VoFIterator vofit(a_ivsin, a_ebGraph);
86  *m_vofs = vofit.getVector();
87  }
88  }
89  else
90  {
91  m_vofs.reset();
92  }
93  }
94 }
95 
96 template <class T> inline
97 void
98 MiniIVFAB<T>::copy(const Box& a_fromBox,
99  const Interval& a_dstInterval,
100  const Box& a_toBox,
101  const MiniIVFAB<T>& a_src,
102  const Interval& a_srcInterval)
103 {
104  T* to=NULL;
105  if(m_vofs)
106  {
107  to = getIndex((*m_vofs)[0],a_dstInterval.begin());
108  }
109  for(unsigned int i=0; i<m_vofs->size(); i++, to++)
110  {
111  const VolIndex& vof = (*m_vofs)[i];
112  if(a_fromBox.contains(vof.gridIndex()))
113  {
114  const T* from= a_src.getIndex(vof,a_srcInterval.begin());
115  //T* to = getIndex(vof,a_dstInterval.begin());
116  for(unsigned int c=0; c<a_srcInterval.size(); c++)
117  {
118  to[c*m_vofs->size()]=from[c*a_src.m_vofs->size()];
119  }
120  }
121  }
122 }
123 
124 
125  ///
126 /******************/
127 template <class T> inline
128 int MiniIVFAB<T>::size(const Box& a_region,
129  const Interval& a_comps) const
130 {
131  int count = 0;
132  T tmp;
133  //create set of cells in fab that are also in the input region
134  if(m_vofs){
135  for (unsigned int i=0; i<m_vofs->size(); i++)
136  {
137  if (a_region.contains((*m_vofs)[i].gridIndex())) count++;
138  }
139  }
140  if (count > 0)
141  {
142  return sizeof(int) + count*CH_XD::linearSize((*m_vofs)[0]) + count*a_comps.size()*CH_XD::linearSize(tmp);
143  }
144  return sizeof(int);
145 }
146 /********************/
147 template <class T> inline
148 void MiniIVFAB<T>::linearOut(void* a_buf,
149  const Box& a_region,
150  const Interval& a_comps) const
151 {
152  char* buffer = (char*)a_buf;
153  buffer += sizeof(int);
154  int count = 0;
155  if (m_vofs)
156  {
157  const T* ptr = &(this->m_data[0]);
158  for (unsigned int i=0; i<m_vofs->size(); i++, ptr++)
159  {
160  const VolIndex& v = (*m_vofs)[i];
161  if (a_region.contains(v.gridIndex()))
162  {
163  count++;
164  CH_XD::linearOut(buffer, v);
165  buffer+= CH_XD::linearSize(v);
166  for (int c=a_comps.begin(); c<=a_comps.end(); c++)
167  {
168  CH_XD::linearOut(buffer, *(ptr+c*(m_vofs->size())));
169  buffer += CH_XD::linearSize(*ptr);
170  }
171  }
172  }
173  }
174  int* b = (int*)a_buf;
175  *b = count;
176 }
177 /********************/
178 template <class T> inline
179 void MiniIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
180 {
181  int* b = (int*)a_buf;
182  int count = *b;
183  char* buffer = (char*)a_buf;
184  buffer += sizeof(int);
185  for (int i=0; i<count; i++)
186  {
187  VolIndex v;
188  CH_XD::linearIn(v, buffer);
189  buffer += linearSize(v);
190  for (int c=a_comps.begin(); c<=a_comps.end(); c++)
191  {
192  T* ptr = getIndex(v, c);
193  CH_XD::linearIn(*ptr, buffer);
194  buffer+=CH_XD::linearSize(*ptr);
195  }
196  }
197 }
198 /********************/
199 template <class T> inline
200 T*
201 MiniIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
202 {
203 
204  CH_assert((a_comp >= 0) && (a_comp < this->m_nComp));
205 
206  T* dataPtr = (T*)&(this->m_data[0]);
207  for (unsigned int i=0; i<m_vofs->size(); ++i)
208  {
209  if (a_vof == (*m_vofs)[i]) break;
210  dataPtr++;
211  }
212  dataPtr += a_comp*m_vofs->size();
213  return dataPtr;
214 }
215 
216 /********************/
217 template <class T> inline
218 void MiniIVFAB<T>::setVal(const T& a_val)
219 {
220  if(m_vofs)
221  for(int i=0; i<m_vofs->size()*m_nComp; i++) m_data[i]=a_val;
222 }
223 /********************/
224 template <class T> inline
225 void MiniIVFAB<T>::setVal(int a_comp, const T& a_val)
226 {
227  if(m_vofs)
228  for(int i=a_comp*m_nComp; i<m_vofs->size()*(a_comp+1)*m_nComp; i++) m_data[i]=a_val;
229 }
230 
231 /********************/
232 template <class T> inline
233 void MiniIVFAB<T>::setVal(const T& a_val, const Box& a_region, int a_startcomp, int a_ncomp)
234 {
235  if(m_vofs)
236  forall(*this, a_region, a_startcomp, a_startcomp, a_ncomp, false, [a_val](T& d, const T& s){d=a_val;});
237 }
238 
239 
240 
241 /********************/
242 template <class T> inline
244 {
245  if(m_vofs)
246  return m_vofs->size();
247  return 0;
248 }
249 /********************/
250 template <class T> inline
253 {
254  //if this fails, nothing to get
255  if(m_vofs)
256  {
257  return *m_vofs;
258  }
259  else
260  {
261  return Vector<VolIndex>();
262  }
263 }
264 /***********/
265 template <class T>
266 template <typename F>
267 void MiniIVFAB<T>::forall(const MiniIVFAB<T>& a_src, const Box& a_box, int a_srccomp, int a_destcomp,
268  int a_numcomp, bool sameRegBox, const F& func)
269 {
270  if(!m_vofs) return;
271  if (sameRegBox)
272  {
273  Real* l = dataPtr(a_destcomp);
274  const Real* r = a_src.dataPtr(a_srccomp);
275  int nvof = m_vofs->size();
276  for (int i=0; i<a_numcomp*nvof; i++)
277  {
278  func(l[i], r[i]);
279  }
280  }
281  else
282  {
283  const Vector<VolIndex>& vofs = *m_vofs;
284  for(int i=0; i<vofs.size(); i++)
285  {
286  const VolIndex& vof=vofs[i];
287  if(a_box.contains(vof.gridIndex()))
288  {
289  for (int icomp = 0; icomp < a_numcomp; ++icomp)
290  {
291  func(this->operator()(vof, a_destcomp+icomp), a_src(vof, a_srccomp+icomp));
292  }
293  }
294  }
295  }
296 }
297 
298 
299 #include "NamespaceFooter.H"
300 #endif
301 
MiniIVFAB()
Definition: MiniIVFABI.H:26
virtual void define(const IntVectSet &a_region, const EBGraph &a_ebgraph, const int &a_nvarin)
Definition: MiniIVFABI.H:56
virtual ~MiniIVFAB()
Definition: MiniIVFABI.H:32
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
#define CH_assert(cond)
Definition: CHArray.H:37
int size(const Box &R, const Interval &comps) const
Definition: MiniIVFABI.H:128
int size() const
Definition: Interval.H:75
int numVoFs() const
Definition: MiniIVFABI.H:243
void forall(const MiniIVFAB &a_src, const Box &a_box, int a_srccomp, int a_destcomp, int a_numcomp, bool sameRegBox, const F &func)
Definition: MiniIVFABI.H:267
int begin() const
Definition: Interval.H:99
const IntVect & gridIndex() const
Definition: VolIndex.H:125
const Vector< VolIndex > getVector() const
bool contains(const IntVect &p) const
Definition: Box.H:1887
void reset()
same as begin()
Definition: IntVectSet.H:722
void copy(const Box &a_fromBox, const Interval &a_dstInterval, const Box &a_toBox, const MiniIVFAB< T > &a_src, const Interval &a_srcInterval)
Definition: MiniIVFABI.H:98
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
virtual T * getIndex(const VolIndex &a_vof, const int &a_comp) const
get index into vector
Definition: MiniIVFABI.H:201
long long numVoFs(const IntVect &a_iv) const
Definition: EBGraph.H:989
void setVal(const T &a_val)
Definition: MiniIVFABI.H:218
Structure for passing component ranges in code.
Definition: Interval.H:23
int m_nComp
Definition: MiniIVFAB.H:164
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: MiniIVFABI.H:179
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: MiniIVFABI.H:148
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:33
double Real
Definition: REAL.H:33
int linearSize(const T &inputT)
Definition: SPMDI.H:21
size_t size() const
Definition: Vector.H:192
shared_ptr< Vector< VolIndex > > m_vofs
Definition: MiniIVFAB.H:162
T * dataPtr(int a_ivar)
Definition: MiniIVFAB.H:105
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
T * m_data
Definition: MiniIVFAB.H:165
Iterator for all vofs within an IntVectSet and an Ebgraph.
Definition: VoFIterator.H:27
Volume of Fluid Index.
Definition: VolIndex.H:31
Vector< VolIndex > getVoFs() const
Definition: MiniIVFABI.H:252
int end() const
Definition: Interval.H:104
shared_ptr< Vector< T > > m_Memory
Definition: MiniIVFAB.H:163
Iterator for an IntVectSet.
Definition: IntVectSet.H:640
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:27
bool isEmpty() const
Returns true if no IntVects are in this IntVectSet.
Definition: MiniIVFAB.H:37