Chombo + EB  3.0
IVSFAB.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 _IVSFAB_H_
12 #define _IVSFAB_H_
13 
14 #include <cmath>
15 #include <cstdlib>
16 #include "SPACE.H"
17 #include "Vector.H"
18 #include "IntVectSet.H"
19 #include "IntVect.H"
20 #include "BaseFab.H"
21 #include "LayoutData.H"
22 #include "BoxLayoutData.H"
23 #include "NamespaceHeader.H"
24 
25 
26 ///
27 /**
28  IVSFAB is a templated
29  data holder defined at the Ivs of an irregular domain.
30 */
31 template <class T>
32 class IVSFAB
33 {
34 public:
35  ///
36  /**
37  Default constructor. Constructs an uninitialized IVFAB. You must
38  subsequently call {\bf define} before using this IVFAB.
39  */
40  IVSFAB();
41 
42  ///
43  /**
44  */
45  IVSFAB(const IntVectSet& a_region,
46  const int& a_nvarin);
47 
48  ///
49  ~IVSFAB();
50 
51  ///
52  /**
53  */
54  void define(const IntVectSet& a_region,
55  const int& a_nvarin);
56 
57  ///
58  /**
59  Set a value at every data location.
60  */
61  void setVal(const T& value);
62 
63  ///
64  void copy(const Box& a_fromBox,
65  const Interval& a_destInterval,
66  const Box& a_toBox,
67  const IVSFAB<T>& a_src,
68  const Interval& a_srcInterval);
69 
70  ///
71  /**
72  This stuff required by LevelData in parallel:
73  */
74 
75  static int preAllocatable()
76  {
77  return 1; // symmetric allocatable.
78  }
79 
80  ///
81  int size(const Box& R, const Interval& comps) const ;
82 
83  ///
84  void linearOut(void* buf, const Box& R, const Interval& comps) const;
85 
86  ///
87  void linearIn(void* buf, const Box& R, const Interval& comps);
88 
89  ///
90  /**
91  Remove all data from this IVSFAB.
92  You must call {\bf define} again in order
93  to use it.
94  */
95  void clear();
96 
97  ///
98  /**
99 
100  Tells whether this IVSFAB has been defined, either with a constructor
101  or with {\bf define}. It must be initialized in order to access its data.
102  */
103  bool
104  isDefined() const;
105 
106  ///
107  /**
108  Return the number of Ivs in this IVSFAB.
109  */
110  int numIvs() const;
111 
112  ///
113  /**
114  Return the number of data components of this IVSFAB.
115  */
116  int nComp() const;
117 
118  ///
119  /**
120  Return the irregular domain of the IVSFAB.
121  */
122  const IntVectSet& getIVS() const;
123 
124  ///
125  /**
126  Indexing operator. Return a reference to the contents of this IVFAB,
127  at the specified Iv and data component. The first component is
128  zero, the last is {\em nvar-1}. The returned object is a modifiable
129  lvalue.
130  */
131  T& operator() (const IntVect& a_iv,const int& varlocin);
132  const T& operator() (const IntVect& a_iv,const int& varlocin) const;
133 
134  ///
135  /**
136  Return a const pointer to the internal data storage of this IVFAB. \\
137  */
138  const T* dataPtr(const int& a_comp) const;
139 
140  ///
141  /**
142  Return a pointer to the internal data storage of this IVFAB.
143  */
144  T* dataPtr(const int& a_comp) ;
145 
146  ///invalid but necessary for leveldata to compile
147  IVSFAB(const Box& a_region, int a_nVar)
148  {
149  MayDay::Error("invalid constructor called ");
150  }
151 
152  ///
153  /**
154  Return a fake "lower left corner of the domain" for use with Fortran.
155  */
156  const int* loVect() const;
157 
158  ///
159  /**
160  Return a fake "upper right corner of the domain" for use with Fortran.
161  */
162  const int* hiVect() const;
163 
164  ///
165  static void setVerbose(bool a_verbose);
166 private:
167  void
169 
170 protected:
171  //get index into dataPtr
172  int getIndex(const IntVect& a_iv,const int& a_comp) const;
173  //has to be a pointer because we are planning to ship
174  //the damned thing to fortran.
176  int m_nComp;
177  int m_nIvs;
180 
181  //this is how we map from vof to vector of data.
182  //grab the vof and its intvect tells you the vector<int>
183  //the integer in the vof indexes into the vof.
184  //that tells you the offset into m_dataPtr
185  //you further have to account for the variable number.
186  //the getIndex() function encapsulates the process
190 
191  static bool s_verbose;
192 private:
193  //disallowed for all the usual reasons
194  IVSFAB<T>& operator= (const IVSFAB<T>&);
195  IVSFAB (const IVSFAB<T>&);
196 };
197 
198 
199 /// Factory class to produce IVSFABs.
200 /**
201  Factory class to produce IVSFABs.
202  This is needed for LevelData construction.
203  */
204 template <class T>
206  : public DataFactory< IVSFAB<T> >
207 {
208 public:
209 
210  /// factory function.
211  /**
212  Creates a new baseivfab object
213  and returns a pointer to it. Responsiblitly
214  for calling operator 'delete' on this pointer
215  is passed to the user.
216  Intersects a_sets[a_dit] from construction
217  with input box because leveldata will expect
218  that anyway when it tries to do a copy or a linearization.
219  */
220  virtual IVSFAB<T>* create(const Box& a_box, int a_ncomps,
221  const DataIndex& a_dit) const
222  {
223  //intersects with input box because leveldata will expect
224  //that anyway when it tries to do a copy or a linearization.
225  IntVectSet ivsInter = m_sets[a_dit];
226  ivsInter &= a_box;
227  return new IVSFAB<T>(ivsInter, a_ncomps);
228  }
229 
230  ///
231  /**
232  fills internal data with inputs
233  */
235  {
236  m_sets.define(a_sets.boxLayout());
237  for (DataIterator dit = m_sets.dataIterator(); dit.ok(); ++dit)
238  {
239  m_sets[dit()] = a_sets[dit()];
240  }
241  }
242 
243  ///
244  virtual ~IVSFABFactory()
245  {
246  ;
247  }
248 
249 private:
250 
251  ///
253 
254  //disallowed constructors and all that
256  {
257  MayDay::Error("disallowed constructor");
258  }
260  {
261  MayDay::Error("disallowed constructor");
262  }
263  void operator=(const IVSFABFactory<T>& a_inputs)
264  {
265  MayDay::Error("disallowed constructor");
266  }
267 
268 };
269 
270 #include "NamespaceFooter.H"
271 #include "IVSFABI.H"
272 
273 #endif
static void setVerbose(bool a_verbose)
Definition: IVSFABI.H:27
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
void copy(const Box &a_fromBox, const Interval &a_destInterval, const Box &a_toBox, const IVSFAB< T > &a_src, const Interval &a_srcInterval)
Definition: IVSFABI.H:126
IVSFAB(const Box &a_region, int a_nVar)
invalid but necessary for leveldata to compile
Definition: IVSFAB.H:147
void define(const IntVectSet &a_region, const int &a_nvarin)
Definition: IVSFABI.H:61
IntVect m_loVect
Definition: IVSFAB.H:178
IntVectSet m_ivs
Definition: IVSFAB.H:188
IntVect m_hiVect
Definition: IVSFAB.H:179
T * m_dataPtr
Definition: IVSFAB.H:175
void linearIn(void *buf, const Box &R, const Interval &comps)
Definition: IVSFABI.H:264
int nComp() const
Definition: IVSFABI.H:336
IVSFABFactory(const LayoutData< IntVectSet > &a_sets)
Definition: IVSFAB.H:234
Definition: IVSFAB.H:32
Definition: DataIterator.H:140
int m_nComp
Definition: IVSFAB.H:176
IVSFABFactory()
Definition: IVSFAB.H:259
const T * dataPtr(const int &a_comp) const
Definition: IVSFABI.H:367
bool isDefined() const
Definition: IVSFABI.H:322
void setVal(const T &value)
Definition: IVSFABI.H:117
bool m_isDefined
Definition: IVSFAB.H:189
int size(const Box &R, const Interval &comps) const
Definition: IVSFABI.H:175
static bool s_verbose
Definition: IVSFAB.H:191
int m_nIvs
Definition: IVSFAB.H:177
Structure for passing component ranges in code.
Definition: Interval.H:23
void setDefaultValues()
Definition: IVSFABI.H:401
virtual IVSFAB< T > * create(const Box &a_box, int a_ncomps, const DataIndex &a_dit) const
factory function.
Definition: IVSFAB.H:220
~IVSFAB()
Definition: IVSFABI.H:46
IVSFABFactory(const IVSFABFactory< T > &a_inputs)
Definition: IVSFAB.H:255
virtual ~IVSFABFactory()
Definition: IVSFAB.H:244
T & operator()(const IntVect &a_iv, const int &varlocin)
Definition: IVSFABI.H:343
virtual void define(const BoxLayout &a_dp)
Definition: LayoutDataI.H:108
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.
const BoxLayout & boxLayout() const
Definition: LayoutData.H:108
BaseFab< int > m_ivmap
Definition: IVSFAB.H:187
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
Definition: DataIndex.H:112
void linearOut(void *buf, const Box &R, const Interval &comps) const
Definition: IVSFABI.H:214
IVSFAB< T > & operator=(const IVSFAB< T > &)
Definition: IVSFABI.H:413
const int * loVect() const
Definition: IVSFABI.H:387
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Factory class to produce IVSFABs.
Definition: IVSFAB.H:205
DataIterator dataIterator() const
Definition: LayoutDataI.H:79
Factory object to data members of a BoxLayoutData container.
Definition: BoxLayoutData.H:30
int numIvs() const
Definition: IVSFABI.H:329
LayoutData< IntVectSet > m_sets
Definition: IVSFAB.H:252
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
void clear()
Definition: IVSFABI.H:306
static int preAllocatable()
Definition: IVSFAB.H:75
int getIndex(const IntVect &a_iv, const int &a_comp) const
Definition: IVSFABI.H:290
void operator=(const IVSFABFactory< T > &a_inputs)
Definition: IVSFAB.H:263
const int * hiVect() const
Definition: IVSFABI.H:394
IVSFAB()
Definition: IVSFABI.H:40
const IntVectSet & getIVS() const
Definition: IVSFABI.H:34