Chombo + EB  3.0
LevelData.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 _LEVELDATA_H_
12 #define _LEVELDATA_H_
13 
14 #include "IntVect.H"
15 #include "BoxLayoutData.H"
16 #include "DisjointBoxLayout.H"
17 #include "Copier.H"
18 #include "SPMD.H"
19 #include "NamespaceHeader.H"
20 
21 ///Data over a disjoint union of rectangles
22 
23 /**
24  LevelData is-a BoxLayoutData. It is built from a DisjointBoxLayout
25  instead though, thus making the data in a DisjointBoxLayout uniquely
26  defined for all spatial indices defined by the underlying
27  DisjointBoxLayout. It carries within it an inherent concept of
28  ghost cells (which the user can choose to be empty).
29 
30  Since LevelData is-a BoxLayoutData, all the methods
31  required of the template class T for BoxLayoutData are also
32  required for LevelData. LevelData does not have any extra requirements.
33 */
34 
35 template <class T>
36 void aliasLevelData(LevelData<T>& a_alias,
37  LevelData<T>* a_original,
38  const Interval& a_interval);
39 
40 template<class T> class LevelData : public BoxLayoutData<T>
41 {
42 public:
43 
44  ///
45  LevelData();
46 
47  ///
48  LevelData(const DisjointBoxLayout& dp, int comps,
49  const IntVect& ghost = IntVect::Zero,
50  const DataFactory<T>& a_factory = DefaultDataFactory<T>());
51 
52  ///
53  virtual ~LevelData();
54 
55  ///
56  virtual void define(const DisjointBoxLayout& dp, int comps,
57  const IntVect& ghost = IntVect::Zero,
58  const DataFactory<T>& a_factory = DefaultDataFactory<T>());
59 
60  ///
61  /**
62  copy definer. this LevelData thrown away and da's LevelData copied
63  */
64  virtual void define(const LevelData<T>& da,
65  const DataFactory<T>& a_factory = DefaultDataFactory<T>());
66 
67  ///
68  /**
69  Copy definer. 'this' LevelData thrown away and da's LevelData copied.
70  This LevelData is now defined for the range [0, comps.size()] and filled
71  with the data in da from [comps.begin(), comps.end()]
72  */
73  virtual void define(const LevelData<T>& da, const Interval& comps,
74  const DataFactory<T>& a_factory = DefaultDataFactory<T>());
75 
76  ///
77  virtual void copyTo(const Interval& srcComps,
78  BoxLayoutData<T>& dest,
79  const Interval& destComps) const;
80 
81  /// Simplest case -- assumes source and dest have same interval
82  virtual void copyTo(BoxLayoutData<T>& dest) const;
83 
84  /*
85  ///
86  virtual void copyTo(const Interval& srcComps,
87  BoxLayoutData<T>& dest,
88  const Interval& destComps,
89  const Copier& copier) const;
90 
91  /// Simplest case -- assumes source and dest have same interval
92  virtual void copyTo(BoxLayoutData<T>& dest,
93  const Copier& copier) const;
94  */
95  ////////////////////////////// FM MOD START //////////////////////////
96  ///
97  /** same as copyTo that takes a BoxLayoutData, except that it fills the
98  ghost cells of 'dest' with data from 'this' also. USer passes in
99  a prebuilt Copier object*/
100  virtual void copyTo(const Interval& srcComps,
101  BoxLayoutData<T>& dest,
102  const Interval& destComps,
103  const Copier& copier,
104  const LDOperator<T>& a_op = LDOperator<T>()) const;
105 
106  /// Simplest case -- assumes source and dest have same interval
107  virtual void copyTo(BoxLayoutData<T>& dest,
108  const Copier& copier,
109  const LDOperator<T>& a_op = LDOperator<T>()) const;
110 
111  ////////////////////////////// FM MOD. END ////////////////////////////
112  ///
113  /** same as copyTo that takes a BoxLayoutData, except that it fills the
114  ghost cells of 'dest' with data from 'this' also. */
115  virtual void copyTo(const Interval& srcComps,
116  LevelData<T>& dest,
117  const Interval& destComps) const;
118 
119  /// Simplest case -- assumes source and dest have same interval
120  virtual void copyTo(LevelData<T>& dest) const;
121 
122  ///
123  /** same as copyTo that takes a BoxLayoutData, except that it fills the
124  ghost cells of 'dest' with data from 'this' also. USer passes in
125  a prebuilt Copier object*/
126  virtual void copyTo(const Interval& srcComps,
127  LevelData<T>& dest,
128  const Interval& destComps,
129  const Copier& copier,
130  const LDOperator<T>& a_op = LDOperator<T>()) const;
131 
132  /// Simplest case -- assumes source and dest have same interval
133  virtual void copyTo(LevelData<T>& dest,
134  const Copier& copier,
135  const LDOperator<T>& a_op = LDOperator<T>()) const;
136  ///
137  virtual void exchange(const Interval& comps);
138 
139  /// Simplest case -- do all components
140  virtual void exchange(void);
141 
142  ///
143  virtual void exchange(const Interval& comps,
144  const Copier& copier);
145 
146  /// Simplest case -- do all components
147  virtual void exchange(const Copier& copier);
148 
149  /// asynchronous exchange start. load and fire off messages.
150  virtual void exchangeBegin(const Copier& copier);
151  /// finish asynchronous exchange
152  virtual void exchangeEnd();
153 
154  virtual void exchangeNoOverlap(const Copier& copier);
155 
156  ///
157  const IntVect& ghostVect() const
158  {
159  return m_ghost;
160  }
161 
162  /**
163  \name overidden virtual functions
164 
165  These functions will invoke error messages when invoked.
166  C++ will ensure that constructors are not called for the
167  base class by a user, but a 'define' function has no such protection,
168  hence the need to prevent such usage. A runtime error is not
169  a perfect solution...(strong construction gets around this *sigh*).
170  classes that derive from LevelData will have to turn its valid
171  defines into runtime errors also and make its own defines. Thus
172  taking over the job of the compiler.
173  */
174  /*@{*/
175  virtual void define(const BoxLayout& dp, int comps,
176  const DataFactory<T>& factory);
177 
178  ///
179  virtual void define(const BoxLayoutData<T>& da,
180  const DataFactory<T>& factory = DefaultDataFactory<T>());
181 
182  ///
183  virtual void define(const BoxLayoutData<T>& da, const Interval& comps,
184  const DataFactory<T>& factory = DefaultDataFactory<T>());
185 
186  virtual void define(const BoxLayout& deadFunction);
187  /*@}*/
188 
189  ///
191  {
192  return m_disjointBoxLayout;
193  }
194 
195  ///
197  {
198  return m_disjointBoxLayout;
199  }
200 
201  ///
202  /** User writes a function with the signature:
203 
204  \code
205  void myfunction(const Box& box, int n_comps, T& t)
206  {
207  your code here;
208  }
209  \endcode
210 
211  They can then hand this off to LayoutData::apply, which invokes this
212  function for every T. The argument "box" is the Box (as known to the
213  DisjointBoxLayout here) associated with that T and the argument "n_comps"
214  is the number of components in this LevelData.
215 
216  Your function must not be inline.
217 
218  For example:
219  \code
220  LevelData<FArrayBox> data(layout, 3, IntVect::Unit);
221  struct val
222  {
223  static void set1(const Box& box, int n_comps, const FArrayBox& fab)
224  {
225  fab.setVal( box.smallEnd(0), box, 0, n_comps );
226  }
227  };
228 
229  data.apply(val::set1);
230  \endcode
231 */
232  virtual void apply( void (*a_Function)(const Box&, int, T&) );
233 
234 
235  /** For use with apply( const ApplyFunctor& ) */
237  {
238  virtual ~ApplyFunctor()
239  {
240  }
241 
242  virtual void operator()( const Box&, int, T& ) const = 0;
243  };
244 
245 /** Like the other apply(), but here the argument is an instance of a class
246  derived from LevelData::ApplyFunctor, and which implements ApplyFunctor's
247  pure virtual void operator()(const Box& box, int n_comps, T& t) const.
248 
249  Going with an instance of such a class is more convenient if you want
250  the thing you pass to apply() to have state.
251 
252  For example:
253  \code
254  class MyFunctor : public LevelData<FArrayBox>::ApplyFunctor
255  {
256  public:
257  MyFunctor( Real x ) : m_x(x)
258  {
259  ...
260  }
261  virtual void operator()(const Box& box, int n_comps, FArrayBox& fab) const
262  {
263  fab.setVal( m_x, box, 0, n_comps );
264  }
265  private:
266  const Real m_x;
267  }
268 
269  LevelData<FArrayBox> data(layout, 3, IntVect::Unit);
270  data.apply( MyFunctor(3.14, 0) );
271 
272  \endcode
273 
274 */
275  virtual void apply( const ApplyFunctor& );
276 
277  void degenerate( LevelData<T>& a_to, const SliceSpec& a_ss ) const;
278 
279 protected:
281 
283 
284  friend void aliasLevelData<T>(LevelData<T>& a_alias,
285  LevelData<T>* a_original,
286  const Interval& a_interval);
287 
289 };
290 
291 /// LevelData aliasing function
292 /**
293  @param a_alias aliased LevelData<T> object. original data in a_alias is destroyed and new aliasing role assumed.
294  @param a_original pointer to LevelData<T> that will be aliased.
295  @param a_interval range of components of each T in a_original that will be created in the a_alias argument.
296 
297 \code
298 
299 LevelData<FArrayBox> original(dbl, 4, 2*IntVect::Unit);
300 Interval subcomps(2, 3);
301 LevelData<FArrayBox> alias;
302 aliasLevelData<FArrayBox>(alias, &original, subcomps);
303 // component 0 of every FArrayBox in alias references the same data as
304 // component 2 in original
305 \endcode
306 
307 The template class T must have an 'alias' constructor
308 
309 \code
310 class A
311  {
312 public:
313  A(const Interval& subcomps, A& original);// alias constructor
314  ...
315  };
316 
317  \endcode
318  */
319 template <class T>
320 void aliasLevelData(LevelData<T>& a_alias, LevelData<T>* a_original,
321  const Interval& a_interval)
322 {
323  AliasDataFactory<T> factory(a_original, a_interval);
324  a_alias.define(a_original->disjointBoxLayout(), a_interval.size(), a_original->ghostVect(), factory);
325 }
326 
327 // ====== inlined function definitions ================
328 
329 // As with the BoxLayoutData implementation file. This file
330 // just gives the interface and the inline implmentations
331 // are given in LevelDataI.H
332 
333 #include "NamespaceFooter.H"
334 #include "LevelDataI.H"
335 
336 #endif
virtual void operator()(const Box &, int, T &) const =0
void degenerate(LevelData< T > &a_to, const SliceSpec &a_ss) const
Definition: LevelDataI.H:445
LevelData()
Definition: LevelDataI.H:25
DisjointBoxLayout m_disjointBoxLayout
Definition: LevelData.H:280
Definition: LevelData.H:236
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
int size() const
Definition: Interval.H:64
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:137
friend void aliasLevelData(LevelData< T > &a_alias, LevelData< T > *a_original, const Interval &a_interval)
Data over a disjoint union of rectangles.
Definition: LevelData.H:320
Definition: SliceSpec.H:42
IntVect m_ghost
Definition: LevelData.H:282
Copier m_exchangeCopier
Definition: LevelData.H:288
void aliasLevelData(LevelData< T > &a_alias, LevelData< T > *a_original, const Interval &a_interval)
Data over a disjoint union of rectangles.
Definition: LevelData.H:320
virtual void exchange(void)
Simplest case – do all components.
Definition: LevelDataI.H:324
virtual void exchangeBegin(const Copier &copier)
asynchronous exchange start. load and fire off messages.
Definition: LevelDataI.H:368
Factory object to data members of a BoxLayoutData container.
Definition: BoxLayoutData.H:64
virtual void apply(void(*a_Function)(const Box &, int, T &))
Structure for passing component ranges in code.
Definition: Interval.H:23
Definition: BoxLayoutData.H:136
Data on a BoxLayout.
Definition: BoxLayoutData.H:91
virtual void define(const DisjointBoxLayout &dp, int comps, const IntVect &ghost=IntVect::Zero, const DataFactory< T > &a_factory=DefaultDataFactory< T >())
Definition: LevelDataI.H:70
virtual void copyTo(const Interval &srcComps, BoxLayoutData< T > &dest, const Interval &destComps) const
Definition: LevelDataI.H:164
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
const DisjointBoxLayout & getBoxes() const
Definition: LevelData.H:190
const IntVect & ghostVect() const
Definition: LevelData.H:157
virtual ~ApplyFunctor()
Definition: LevelData.H:238
static const IntVect Zero
Definition: IntVect.H:627
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
const DisjointBoxLayout & disjointBoxLayout() const
Definition: LevelData.H:196
Definition: BoxLayoutData.H:94
virtual ~LevelData()
Definition: LevelDataI.H:32
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Factory object to data members of a BoxLayoutData container.
Definition: BoxLayoutData.H:30
Definition: BoxLayoutData.H:139
virtual void exchangeEnd()
finish asynchronous exchange
Definition: LevelDataI.H:378
virtual void exchangeNoOverlap(const Copier &copier)
Definition: LevelDataI.H:356