Chombo + EB  3.2
MiniIVFAB.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 _MINIIVFAB_H_
12 #define _MINIIVFAB_H_
13 
14 #include <cmath>
15 #include <cstdlib>
16 #include <memory>
17 #include "SPACE.H"
18 #include "Vector.H"
19 #include "IntVectSet.H"
20 #include "VolIndex.H"
21 #include "BaseFab.H"
22 #include "EBGraph.H"
23 #include "BaseIVFAB.H"
24 #include "NamespaceHeader.H"
25 
26 ///
27 /**
28  MiniIVFAB is a templated
29  data holder defined at the VoFs of an irregular domain.
30 
31 Implemented as just a raw vector of vofs and data, more optimized
32 for smaller memory footprint and faster linearIn/linearOut. will
33 be more brutal for vof-by-vof indexing.
34 bvs
35 */
36 template <class T>
37 class MiniIVFAB //: public BaseIVFAB<T>
38 {
39 public:
40  ///
41  /**
42  Null constructor.
43  */
44  MiniIVFAB();
45 
46  ///
47  /**
48  Defining constructor. Specifies the irregular domain
49  and the number of data components per VoF. The irregular domain
50  must lie completely within the EBGraph. The
51  contents are uninitialized. Calls full define function.
52  */
53  MiniIVFAB( const IntVectSet& a_region,
54  const EBGraph& a_ebgraph,
55  const int& a_nvarin);
56 
57  ///
58  bool hasVoFs() const
59  {
60  if(m_vofs) return true;
61  return false;
62  }
63  ///
64  /**
65 
66  This aliased MiniIVFAB will have a_comps.size() components, starting at zero.
67  */
68  MiniIVFAB(const Interval& a_comps,
69  MiniIVFAB<T>& a_original);
70 
71 
72  ///
73  virtual ~MiniIVFAB();
74 
75  ///
76  /**
77  Full define function. Specifies the irregular domain and the
78  number of data components per VoF. The irregular domain
79  must lie completely within the EBGraph. The contents
80  are uninitialized. If it has previously been defined, the old definition
81  data is overwritten and lost.
82  */
83  virtual void define(const IntVectSet& a_region,
84  const EBGraph& a_ebgraph,
85  const int& a_nvarin);
86 
87 
88  ///
89  void copy(const Box& a_fromBox,
90  const Interval& a_dstInterval,
91  const Box& a_toBox,
92  const MiniIVFAB<T>& a_src,
93  const Interval& a_srcInterval);
94  ///
95  int size(const Box& R, const Interval& comps) const ;
96 
97  ///
98  void linearOut(void* buf, const Box& R, const Interval& comps) const;
99 
100  ///
101  void linearIn(void* buf, const Box& R, const Interval& comps);
102 
103  Vector<VolIndex> getVoFs() const;
104 
105  inline T* dataPtr(int a_ivar)
106  {
107  if(m_vofs) return m_data+a_ivar*m_vofs->size();
108  return m_data;
109  }
110 
111  const T* dataPtr(int a_ivar) const
112  {
113  if(m_vofs) return m_data+a_ivar*m_vofs->size();
114  return m_data;
115  }
116 
117  void setVal(const T& a_val);
118 
119  void setVal(int a_comp, const T& a_val);
120 
121  void setVal(const T& a_val, const Box& a_box, int a_startcomp, int a_ncomp);
122 
123 
124  ///get index into vector
125  /**
126  needs to be public so that bulk stencils can be constructed
127  */
128  virtual T* getIndex(const VolIndex& a_vof,const int& a_comp) const;
129 
130  ///for AggStencil
131  long offset(const BaseIndex& a_vof, const int& a_ivar) const
132  {
133  const VolIndex* vof = dynamic_cast< const VolIndex* >(&a_vof);
134  if (vof == NULL) MayDay::Error("cast failed:MiniIVFAB only takes vofs for indexing");
135  unsigned int i = 0;
136  for(;i<m_vofs->size(); i++)
137  if(*vof == (*m_vofs)[i]) break;
138  i+=a_ivar*m_vofs->size();
139  return i;
140  }
141 
142  ///
143  T& operator() (const VolIndex& a_vof, int a_comp)
144  { return *(getIndex(a_vof, a_comp));}
145 
146  ///
147  const T& operator() (const VolIndex& a_vof, int a_comp) const
148  {
149  return *(getIndex(a_vof, a_comp));
150  }
151 
152  template <typename F>
153  void forall(const MiniIVFAB& a_src, const Box& a_box, int a_srccomp, int a_destcomp, int a_numcomp, bool sameRegBox, const F& func);
154 
155  int numVoFs() const;
156 
157  int nComp() const {return m_nComp;}
158 private:
159 
160 protected:
161 
162  shared_ptr<Vector<VolIndex> > m_vofs;
163  shared_ptr<Vector<T> > m_Memory;
164  int m_nComp = 0;
165  T* m_data = nullptr;
166 
167 };
168 
169 #include "NamespaceFooter.H"
170 
171 #ifndef CH_EXPLICIT_TEMPLATES
172 #include "MiniIVFABI.H"
173 #endif
174 
175 #endif
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
int size(const Box &R, const Interval &comps) const
Definition: MiniIVFABI.H:128
bool hasVoFs() const
Definition: MiniIVFAB.H:58
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
index for other indicies to inherit
Definition: BaseIndex.H:26
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
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
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
shared_ptr< Vector< VolIndex > > m_vofs
Definition: MiniIVFAB.H:162
T * dataPtr(int a_ivar)
Definition: MiniIVFAB.H:105
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
T * m_data
Definition: MiniIVFAB.H:165
int nComp() const
Definition: MiniIVFAB.H:157
Volume of Fluid Index.
Definition: VolIndex.H:31
long offset(const BaseIndex &a_vof, const int &a_ivar) const
for AggStencil
Definition: MiniIVFAB.H:131
Vector< VolIndex > getVoFs() const
Definition: MiniIVFABI.H:252
T & operator()(const VolIndex &a_vof, int a_comp)
Definition: MiniIVFAB.H:143
shared_ptr< Vector< T > > m_Memory
Definition: MiniIVFAB.H:163
const T * dataPtr(int a_ivar) const
Definition: MiniIVFAB.H:111
Definition: MiniIVFAB.H:37