Chombo + EB  3.0
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
27 {
28  setDefaultValues();
29 }
30 /******************/
31 template <class T> inline
33 {
34  clear();
35 }
36 /******************/
37 template <class T> inline
39  const EBGraph& a_ebgraph,
40  const int& a_nvarin)
41 {
42  setDefaultValues();
43  define(a_ivsin, a_ebgraph, a_nvarin);
44 }
45 /******************/
46 template <class T> inline
47 void
49  const EBGraph& a_ebGraph,
50  const int& a_nvarin)
51 {
52  clear();
53  this->m_isDefined = true;
54  CH_assert(a_nvarin > 0);
55 
56  this->m_ivs = a_ivsin;
57  this->m_nComp = a_nvarin;
58  this->m_ebgraph = a_ebGraph;
59  this->m_nVoFs = 0;
60 
61  if (!a_ivsin.isEmpty())
62  {
63  //figure out how long vector has to be
64  IVSIterator ivsit(this->m_ivs);
65  for (ivsit.reset(); ivsit.ok(); ++ivsit)
66  {
67  this->m_nVoFs += this->m_ebgraph.numVoFs(ivsit());
68  }
69  //now allocate the vector set the fab to go into
70  //the pool of data at the first component of the first
71  //vof
72  if (this->m_nVoFs > 0)
73  {
74  //this->m_data = new T[this->m_nVoFs*this->m_nComp];
75  this->m_data.resize(this->m_nVoFs*this->m_nComp);
76  VoFIterator vofit(this->m_ivs, this->m_ebgraph);
77  m_vofs = vofit.getVector();
78  }
79  }
80 }
81 
82 
83 /******************/
84 template <class T> inline
85 int MiniIVFAB<T>::size(const Box& a_region,
86  const Interval& a_comps) const
87 {
88  CH_assert(this->isDefined());
89  int count = 0;
90  T tmp;
91  //create set of cells in fab that are also in the input region
92  for (int i=0; i<m_vofs.size(); i++)
93  {
94  if (a_region.contains(m_vofs[i].gridIndex())) count++;
95  }
96  if (count > 0)
97  {
98  return sizeof(int) + count*CH_XD::linearSize(m_vofs[0]) + count*a_comps.size()*CH_XD::linearSize(tmp);
99  }
100  return sizeof(int);
101 }
102 /********************/
103 template <class T> inline
104 void MiniIVFAB<T>::linearOut(void* a_buf,
105  const Box& a_region,
106  const Interval& a_comps) const
107 {
108  CH_assert(this->isDefined());
109  char* buffer = (char*)a_buf;
110  buffer += sizeof(int);
111  int count = 0;
112  if (m_vofs.size()>0)
113  {
114  const T* ptr = &(this->m_data[0]);
115  for (int i=0; i<m_vofs.size(); i++, ptr++)
116  {
117  const VolIndex& v = m_vofs[i];
118  if (a_region.contains(v.gridIndex()))
119  {
120  count++;
121  CH_XD::linearOut(buffer, v);
122  buffer+= CH_XD::linearSize(v);
123  for (int c=a_comps.begin(); c<=a_comps.end(); c++)
124  {
125  CH_XD::linearOut(buffer, *(ptr+c*(this->m_nVoFs)));
126  buffer += CH_XD::linearSize(*ptr);
127  }
128  }
129  }
130  }
131  int* b = (int*)a_buf;
132  *b = count;
133 }
134 /********************/
135 template <class T> inline
136 void MiniIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
137 {
138  CH_assert(this->isDefined());
139  int* b = (int*)a_buf;
140  int count = *b;
141  char* buffer = (char*)a_buf;
142  buffer += sizeof(int);
143  for (int i=0; i<count; i++)
144  {
145  VolIndex v;
146  CH_XD::linearIn(v, buffer);
147  buffer += linearSize(v);
148  for (int c=a_comps.begin(); c<=a_comps.end(); c++)
149  {
150  T* ptr = getIndex(v, c);
151  CH_XD::linearIn(*ptr, buffer);
152  buffer+=CH_XD::linearSize(*ptr);
153  }
154  }
155 }
156 /********************/
157 template <class T> inline
158 T*
159 MiniIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
160 {
161  CH_assert(this->isDefined());
162  CH_assert(this->m_ivs.contains(a_vof.gridIndex()));
163  CH_assert((a_comp >= 0) && (a_comp < this->m_nComp));
164 
165  T* dataPtr = (T*)&(this->m_data[0]);
166  for (int i=0; i<m_vofs.size(); ++i)
167  {
168  if (a_vof == m_vofs[i]) break;
169  dataPtr++;
170  }
171  dataPtr += a_comp*this->m_nVoFs;
172  return dataPtr;
173 }
174 /********************/
175 template <class T> inline
176 void
178 {
179  m_vofs.resize(0);
181 }
182 
183 
184 
185 /********************/
186 template <class T> inline
187 const Vector<VolIndex>&
189 {
190  return m_vofs;
191 }
192 
193 
194 /******************/
195 template <class T> inline
196 void
198 {
200  m_vofs.resize(0);
201 }
202 
203 #include "NamespaceFooter.H"
204 #endif
205 
MiniIVFAB()
Definition: MiniIVFABI.H:26
virtual void define(const IntVectSet &a_region, const EBGraph &a_ebgraph, const int &a_nvarin)
Definition: MiniIVFABI.H:48
virtual void clear()
Definition: MiniIVFABI.H:177
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:85
virtual void setDefaultValues()
Definition: BaseIVFABI.H:435
int size() const
Definition: Interval.H:64
int begin() const
Definition: Interval.H:86
const IntVect & gridIndex() const
Definition: VolIndex.H:119
const Vector< VolIndex > getVector() const
bool contains(const IntVect &p) const
Definition: Box.H:1888
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:432
virtual T * getIndex(const VolIndex &a_vof, const int &a_comp) const
get index into vector
Definition: MiniIVFABI.H:159
Structure for passing component ranges in code.
Definition: Interval.H:23
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: MiniIVFABI.H:136
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: MiniIVFABI.H:104
const Vector< VolIndex > & getVoFs() const
Definition: MiniIVFABI.H:188
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:32
int linearSize(const T &inputT)
Definition: SPMDI.H:20
virtual void clear()
Definition: BaseIVFABI.H:347
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
Iterator for all vofs within an IntVectSet and an Ebgraph.
Definition: VoFIterator.H:27
Volume of Fluid Index.
Definition: VolIndex.H:31
int end() const
Definition: Interval.H:91
virtual void setDefaultValues()
Definition: MiniIVFABI.H:197
Iterator for an IntVectSet.
Definition: IntVectSet.H:640
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:26
bool isEmpty() const
Returns true if no IntVects are in this IntVectSet.