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