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