Proto  3.2
Proto_MBLevelBoxData.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_MB_LEVEL_DATA_
3 #define _PROTO_MB_LEVEL_DATA_
4 
6 #include "Proto_MBBoundaryData.H"
7 #include "Proto_MBDataPoint.H"
8 
9 namespace Proto
10 {
11 #ifdef PR_AMR
12  template<typename T, unsigned int C, MemType MEM, Centering CTR>
13  class MBAMRData;
14 #endif
15  // Forward Declaration
16  template<typename T, unsigned int C, MemType MEM, Centering CTR>
18  template<typename MAP, MemType MEM>
19  class MBLevelMap;
20 
22 
23  /// Level Copier Operator
24  template<typename T, unsigned int C, MemType SRC_MEM, MemType DST_MEM, Centering CTR>
26  {
27  public:
30 
31  inline MBLevelCopierOp(){};
32  inline MBLevelCopierOp(
35  inline uint64_t linearSize(const Box& a_bx, const MBIndex a_index) const;
36  inline void linearOut(void* a_buffer, const MBMotionItem& a_info) const;
37  inline void linearIn(void* a_buffer, const MBMotionItem& a_info) const;
38  inline void localCopy(const MBMotionItem& a_info) const;
39  };
40 
41  /// Level Copier
42  template<typename T, unsigned int C, MemType SRC_MEM, MemType DST_MEM, Centering CTR>
44  : public Copier
45  <MBLevelCopierOp<T, C, SRC_MEM, DST_MEM, CTR>, MBBoxPartition, MBBoxPartition, SRC_MEM, DST_MEM>
46  {
47  public:
48  inline MBLevelCopier(){};
49  inline void buildMotionPlans(
51  };
52 
53 #if 1
54  /// Full Level Copier Operator (Includes all ghost cells)
55  template<typename T, unsigned int C, MemType SRC_MEM, MemType DST_MEM, Centering CTR>
57  {
58  public:
61 
62  inline MBLevelFullCopierOp(){};
63  inline MBLevelFullCopierOp(
66  inline uint64_t linearSize(const Box& a_bx, const MBIndex a_index) const;
67  inline void linearOut(void* a_buffer, const MBMotionItem& a_info) const;
68  inline void linearIn(void* a_buffer, const MBMotionItem& a_info) const;
69  inline void localCopy(const MBMotionItem& a_info) const;
70  };
71 
72  /// Full Level Copier (Includes all ghost cells)
73  template<typename T, unsigned int C, MemType SRC_MEM, MemType DST_MEM, Centering CTR>
75  : public Copier
76  <MBLevelFullCopierOp<T, C, SRC_MEM, DST_MEM, CTR>, MBBoxPartition, MBBoxPartition, SRC_MEM, DST_MEM>
77  {
78  public:
79  inline MBLevelFullCopier(){};
80  inline void buildMotionPlans(
82  };
83 #endif
84  /// Exchange Copier Operator
85  template<typename T, unsigned int C, MemType MEM, Centering CTR>
87  {
88  public:
90 
93  inline uint64_t linearSize(
94  const Box& a_bx,
95  const MBIndex& a_index) const;
96  inline void linearOut(void* a_buffer, const MBMotionItem& a_info) const;
97 
98  inline void linearIn(void* a_buffer, const MBMotionItem& a_info) const;
99 
100  inline void localCopy(const MBMotionItem& a_info) const;
101  };
102 
103  /// Exchange Copier
104  template<typename T, unsigned int C, MemType MEM, Centering CTR>
106  : public Copier<MBLevelExchangeCopierOp<T, C, MEM, CTR>, MBBoxPartition, MBBoxPartition, MEM, MEM>
107  {
108  public:
110  inline void buildMotionPlans(MBLevelExchangeCopierOp<T, C, MEM, CTR>& a_op);
111  };
112 
113  /// Multiblock Level Box Data
114  /** This class is the analog of LevelBoxData in the context of mapped multiblock applications.
115  * The most critical differences between this object and the single block version are the
116  * presence of additional data buffers allocated at block boundaries which are utilized for
117  * block boundary interpolation.
118  */
119  template<typename T, unsigned int C, MemType MEM, Centering CTR=PR_CELL>
120  class MBLevelBoxData
121  {
122  public:
123  // PatchID, BlockID, Dir
124  typedef std::tuple<Point, BlockIndex, Point> boundsKey_t;
126  // Friends
127  template<typename _T, unsigned int _C, MemType _MEM, Centering _CTR>
128  friend class MBAMRData;
129 
130  inline MBLevelBoxData();
131 
132  /// Main Constructor
133  /** Creates and allocates data for an MBLevelBoxData defined on a specified layout and
134  * allocating a specified number of ghost cells.
135  *
136  * The ghost input has different semantics from the non-
137  * multiblock context. Here, ghost[0] refers to the number of ghost cells that each patch
138  * will allocate - this is the same as the ghost input used for LevelBoxData.
139  * The additional inputs ghost[n] for n > 0 define the size of the block boundary data
140  * buffers that will be allocated for a block boundary of codimension-n. For 4th order
141  * interpolation at block boundaries, it is recommended that ghost[n] for n>0 be greater
142  * than ghost[0] by at least 2 units in each direction. This recommendation holds even for
143  * cases where ghost[0] is equal to zero in one or more coordinate directions.
144  *
145  * \param a_layout A mapped multiblock layout
146  * \param a_ghost An array of ghost sizes. See the description above.
147  * \param a_boundGhost Additional allocation for block boundary buffers.
148  * Use this if there is a need for block boundary buffers to overlap
149  * with the domain interior. This should remain defaulted unless you
150  * really know what you are doing.
151  */
152  inline MBLevelBoxData(
153  const MBDisjointBoxLayout& a_layout,
154  const Array<Point, DIM+1>& a_ghost,
155  Point a_boundGhost = Point::Zeros());
156 
157  /// Simplified Constructor
158  /** The ghost input for this constructor corresponds to ghost[0] in the general constructor. The boundary
159  * data buffers are constructed conservatively assuming 4th order block-boundary interpolation is desired.
160  */
161  inline MBLevelBoxData(
162  const MBDisjointBoxLayout& a_layout,
163  Point a_ghost,
164  Point a_boundGhost = Point::Zeros());
165 
166 
167  /// Lazy Constructor
168  inline void define(
169  const MBDisjointBoxLayout& a_layout,
170  const Array<Point, DIM+1>& a_ghost,
171  Point a_boundGhost = Point::Zeros());
172 
173  /// Lazy Constructor
174  inline void define(
175  const MBDisjointBoxLayout& a_layout,
176  Point a_ghost,
177  Point a_boundGhost = Point::Zeros());
178 
179  /// Initialize FIXME (NOT CURRENTLY WORKING)
180  /** Initialize the data in this using forall-style syntax. Func should
181  * be a valid forall kernel with the following signature:
182  *
183  * void foo(Point& p, Var<T,C,MEM>& d, unsigned int b, ...);
184  *
185  * p: The point of evaluation
186  * d: A data point in this
187  * b: The block in which foo is being evaluated
188  * ...: Other arguments. These may be MBLevelBoxData, MBLevelMap, or any kind of POD
189  * If MBLevelMap is used as an input, the argument will be converted to an
190  * MBLevelBoxData containing the coordinate variables with the same centering
191  * as *this.
192  */
193  template<typename Func, typename... Srcs>
194  inline void initialize(Func& a_func, Srcs&... a_srcs);
195 
196  /// Constant Initialization
197  inline void setVal(T a_value);
198 
199  /// Initialize Boundary Ghost Cells
200  inline void setBoundary(T a_val, int a_comp = -1);
201 
202  /// Initialize with Random Noise
203  inline void setRandom(T a_low, T a_high);
204 
205  /// FIXME (NOT CURRENTLY WORKING)
206  template<typename Func, typename... Srcs>
207  inline void initConvolve(Func& a_func, Srcs&... a_srcs);
209  /// Exchange Ghost Data
210  /** Executes the parallel copy necessary to fill ghost regions.This includes exchanging data
211  * between patches inside of the same block as well as filling block boundary buffers. In
212  * order to fill ghost cells which lie on a block boundary, an MBInterpOp operation must be
213  * applied after this function is called.
214  */
215  inline void exchange();
216 
217  /// Parallel Data Copy
218  /** Executes a parallel copy between two compatible MBLevelBoxData. Only copies valid data;
219  * ghost data will need to be initialized afterwards by calling exchange().
220  * TODO: exchange might actually be copied as well, but I need to test this -CLG
221  */
222  template<MemType DST_MEM>
223  inline void copyTo(MBLevelBoxData<T,C,DST_MEM,CTR>& a_rhs) const;
224 
225  template<MemType DST_MEM>
226  inline void copyToFull(MBLevelBoxData<T,C,DST_MEM,CTR>& a_rhs) const;
227 
228  /// Get Ghost Size Array
229  Array<Point, DIM+1> ghost() const;
230 
231  /// Get Patch Reference
232  inline BoxData<T, C, MEM>& operator[](MBIndex a_index);
233 
234  /// Get Patch Reference (Const Overload)
235  inline const BoxData<T, C, MEM>& operator[](MBIndex a_index) const;
236 
237  /// Increment
238  inline void increment(const MBLevelBoxData<T,C,MEM,CTR>& a_data, T a_scale = 1.0);
239 
240  /// Get Block Data
241  /** Returns the normal LevelBoxData associated with a specified block */
242  inline LevelBoxData<T, C, MEM, CTR>& getBlock(BlockIndex a_block);
243 
244  /// Get Block Data (Const Overload)
245  inline const LevelBoxData<T, C, MEM, CTR>& getBlock(BlockIndex a_block) const;
246 
247  /// Get Layout
248  inline const MBDisjointBoxLayout& layout() const {return m_layout; }
249 
250  /// Get Patch Box
251  /** multiblock analog of LevelBoxData::patchBox. Returns the Box which defines the domain
252  * of a specified patch index, correcting for centering */
253  inline Box patchBox(const MBIndex& a_index) const;
254 
255  /// Get Patch Size
256  /** Multiblock analog of LevelBoxData::patchSize. Returns the number of data points in any
257  * patch within the specified block accounting for centering and ghost size.
258  */
259  inline unsigned int patchSize(BlockIndex a_block) const;
260 
261  /// Linear Size of Patch
262  inline size_t linearSize(const MBIndex& a_index) const;
263 
264  /// Linear Size
265  inline size_t linearSize() const;
266 
267  /// Linear Out
268  inline void linearOut(void* a_buffer, const MBIndex& a_index, const Box& a_box) const;
269 
270  /// Linear Out
271  inline void linearOut(void* a_buffer, const MBIndex& a_index) const;
272 
273  /// Linear Out
274  inline void linearOut(void* a_buffer) const;
275 
276  /// Linear In
277  inline void linearIn(void* a_buffer, const Box& a_box, const MBIndex& a_index);
278  /// Linear In
279  inline void linearIn(void* a_buffer, const MBIndex& a_index);
280  /// Linear In
281  inline void linearIn(void* a_buffer);
282 
283  /// Linear Offset
284  inline size_t offset(unsigned int a_proc) const;
285 
286  /// Get Boundary Buffers
287  /** Returns the block boundary buffers for the block boundary specified by an MBIndex
288  * and a direction in the coordinate system of the block specified by the MBIndex.
289  *
290  * This function is mostly used for debugging and is not recommended for public use.
291  */
292  inline std::vector<MBBoundaryData<T, C, MEM>>& bounds(
293  MBIndex a_index, Point a_dir);
294 
295  /// Get Boundary Buffers (Const Overload)
296  inline const std::vector<MBBoundaryData<T, C, MEM>>& bounds(
297  MBIndex a_index, Point a_dir) const;
298 
299  /// Detect Block Boundary
300  /** Determine if a specified index and direction correspond to a block boundary with a
301  * specified block index */
302  inline bool isBlockBoundary(
303  MBIndex a_index, Point a_dir, BlockIndex a_adjBlock) const;
304 
305  /// Get Block Boundary
306  /** Retrieve the block boundary buffer associated with the specified block boundary
307  * information. This function yields an error if isBlockBoundary is false for these
308  * inputs.
309  */
310  inline MBBoundaryData<T, C, MEM>& bound(
311  MBIndex a_index, Point a_dir, BlockIndex a_adjBlock);
312 
313  /// Get Block Boundary (Const Overload)
314  inline const MBBoundaryData<T, C, MEM>& bound(
315  MBIndex a_index, Point a_dir, BlockIndex a_adjBlock) const;
316 
317  /// Compatibility Check
318  /** This is the same as this->layout().compatible(a_layout) */
319  inline bool compatible(const MBDisjointBoxLayout& a_layout) const;
320 
321  /// Convert MBDataPoint to Var
322  /** Used by interpolation API. Not recommended for public use. */
323  inline Var<T, C, MEM> operator[](const MBDataPoint& a_point);
324 
325  /// Convert MBDataPoint to Var (Const Overload)
326  /** Used by interpolation API. Not recommended for public use. */
327  inline Var<T, C, MEM> operator[](const MBDataPoint& a_point) const;
328 
329  /// Get BoxData containing the destination of the DataPoint
330  /** For points inside of block boundaries, this is the localData variable
331  * of the appropriate MBBoundaryData. Otherwise, this is simply the
332  * patch associated with the index of the DataPoint */
333  //inline BoxData<T,C,MEM>& patch(const MBDataPoint &a_point);
334 
335  /// Get BoxData containing the source of the DataPoint
336  /** For points inside of block boundaries, this is the adjData variable
337  * of the appropriate MBBoundaryData. Otherwise, this is simply the
338  * patch associated with the index of the DataPoint */
339  //inline BoxData<T,C,MEM>& srcPatch(const MBDataPoint &a_point);
340 
341  /// Domain Boundary Check
342  /** Determines which domain boundaries - if any - a specified Point in a specified patch
343  * resides on. The output is a vector of directions which correspond to the domain
344  * boundaries the specified point abuts. If the specified point is not adjacent to a
345  * domain boundary, an empty vector is returned.
346  */
347  inline std::vector<Point> onDomainBoundary(
348  const Point& a_point, const MBIndex& a_index) const;
349 
350  /// Reduction
351  /**
352  */
353  template<Proto::Operation OP>
354  inline T reduce(unsigned int c = 0) const;
355 
356  inline T absMax(unsigned int c = 0) const;
357 
358  inline T max(unsigned int c = 0) const;
360  inline T min(unsigned int c = 0) const;
361 
362  inline T sum(unsigned int c = 0) const;
363 
364  /// Print Boundary Buffer Data
365  /** Prints the contents of the boundary buffers associated with a specified index.
366  */
367  inline void printBounds(const MBIndex& a_index, int a_prec = 4);
368 
369  /// Get Number of Blocks
370  inline unsigned int numBlocks() const { return m_layout.numBlocks(); }
371  inline MBIterator begin();
372  inline MBIterator end();
373  inline const MBIterator begin() const;
374  inline const MBIterator end() const;
375  private:
376 
380  std::vector<std::shared_ptr<LevelBoxData<T, C, MEM, CTR>>> m_data;
381  mutable std::map<boundsKey_t, std::vector<MBBoundaryData<T, C, MEM>>> m_bounds;
382  };
383 
384 #include "implem/Proto_MBLevelBoxDataImplem.H"
385 } // end namespace Proto
386 #endif //end include guard
Level Copier Operator.
Definition: Proto_MBLevelBoxData.H:25
Full Level Copier (Includes all ghost cells)
Definition: Proto_MBLevelBoxData.H:74
void localCopy(const MBMotionItem &a_info) const
Definition: Proto_MBLevelBoxData.H:980
std::tuple< Point, BlockIndex, Point > boundsKey_t
Definition: Proto_MBLevelBoxData.H:124
Exchange Copier.
Definition: Proto_MBLevelBoxData.H:105
std::enable_if< I< sizeof...(LArgs), void >::typecall_mb_level_forall(Func &a_func, MBIndex &a_index, Centering CTR, std::tuple< LArgs... > a_args, FArgs &&... a_fargs){ auto &arg=parse_mb_level_arg(a_index, CTR, std::get< I >a_args));call_mb_level_forall< I+1 >a_func, a_index, CTR, a_args, a_fargs..., arg);}template< typename T, unsigned int C, MemType MEM, Centering CTR >template< typename Func, typename... Srcs >void MBLevelBoxData< T, C, MEM, CTR >::initialize(Func &a_func, Srcs &... a_srcs){ auto srcs=std::tuple< Srcs &... >a_srcs...);for(auto iter :(m_layout)) { auto &patch=(*this)[iter];auto block=layout().block(iter);call_mb_level_forall(a_func, iter, CTR, srcs, patch, block);} }template< typename T, unsigned int C, MemType MEM, Centering CTR >template< typename Func, typename... Srcs >void MBLevelBoxData< T, C, MEM, CTR >::initConvolve(Func &a_func, Srcs &... a_srcs){ auto g=ghost();g[0]=g[0]+Point::Ones();MBLevelBoxData< T, C, MEM, CTR > tmp(m_layout, g);tmp.initialize(a_func, a_srcs...);for(auto iter :m_layout) { auto &tmp_i=tmp[iter];auto &patch=(*this)[iter];Operator::convolve(patch, tmp_i);}}template< typename T, unsigned int C, MemType MEM, Centering CTR >void MBLevelBoxData< T, C, MEM, CTR >::setVal(T a_value){ for(auto data :m_data) { data-> setVal(a_value)
Definition: Proto_MBLevelBoxData.H:208
Multiblock AMR Data.
Definition: Proto_MBAMRData.H:12
Distributed Data Iterator.
Definition: Proto_DataIndex.H:10
std::map< boundsKey_t, std::vector< MBBoundaryData< T, C, MEM > > > m_bounds
Definition: Proto_MBLevelBoxData.H:381
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
Level Copier.
Definition: Proto_MBLevelBoxData.H:43
MBLevelBoxData< T, C, SRC_MEM, CTR > * m_src
Definition: Proto_MBLevelBoxData.H:28
int BlockIndex
Defines what type is used for indexing block entities.
Definition: Proto_MBGraph.H:9
void linearOut(void *a_buffer, const MBMotionItem &a_info) const
Definition: Proto_MBLevelBoxData.H:954
MBLevelBoxData< T, C, DST_MEM, CTR > * m_dst
Definition: Proto_MBLevelBoxData.H:29
Single Level Mapped Multiblock Map.
Definition: Proto_MBLevelBoxData.H:19
MBLevelExchangeCopier< T, C, MEM, CTR > m_exchangeCopier
Definition: Proto_MBLevelBoxData.H:377
Level Box Data.
Definition: Proto_HDF5.H:17
MBLevelExchangeCopier()
Definition: Proto_MBLevelBoxData.H:109
MBLevelFullCopier()
Definition: Proto_MBLevelBoxData.H:79
const MBDisjointBoxLayout & layout() const
Get Layout.
Definition: Proto_MBLevelBoxData.H:248
Multiblock Level Box Data.
Definition: Proto_MBLevelBoxData.H:17
void linearIn(void *a_buffer, const MBMotionItem &a_info) const
Definition: Proto_MBLevelBoxData.H:967
Exchange Copier Operator.
Definition: Proto_MBLevelBoxData.H:86
MotionItem< MBBoxPartition, MBBoxPartition > MBMotionItem
Definition: Proto_MBBoundaryRegister.H:11
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
MBLevelFullCopierOp()
Definition: Proto_MBLevelBoxData.H:62
Array< Point, DIM+1 > m_ghost
Definition: Proto_MBLevelBoxData.H:378
MBLevelBoxData< T, C, SRC_MEM, CTR > * m_src
Definition: Proto_MBLevelBoxData.H:59
MBLevelBoxData< T, C, DST_MEM, CTR > * m_dst
Definition: Proto_MBLevelBoxData.H:60
Definition: Proto_MBBoundaryData.H:11
Full Level Copier Operator (Includes all ghost cells)
Definition: Proto_MBLevelBoxData.H:56
MBLevelCopierOp()
Definition: Proto_MBLevelBoxData.H:31
uint64_t linearSize(const Box &a_bx, const MBIndex a_index) const
Definition: Proto_MBLevelBoxData.H:945
void initConvolve(LevelBoxData< T, C, MEM, CTR > &a_data, Func &a_func, Srcs... a_srcs)
Initialize and Convolve.
Definition: Proto_Operator.H:84
static ACCEL_DECORATION Point Zeros()
Get Zeros.
Definition: Proto_Array.H:17
A templated constant size array object similar to std::array, but with the ability to be used inside ...
Definition: Proto_Array.H:28
unsigned int numBlocks() const
Get Number of Blocks.
Definition: Proto_MBLevelBoxData.H:370
Integer Valued Vector.
Definition: Proto_Point.H:24
Definition: Proto_MBDisjointBoxLayout.H:14
MBLevelBoxData< T, C, MEM, CTR > * m_data
Definition: Proto_MBLevelBoxData.H:89
std::vector< std::shared_ptr< LevelBoxData< T, C, MEM, CTR > > > m_data
Definition: Proto_MBLevelBoxData.H:380
exchange()
MBLevelCopier()
Definition: Proto_MBLevelBoxData.H:48
MBDisjointBoxLayout m_layout
Definition: Proto_MBLevelBoxData.H:379
MBLevelExchangeCopierOp()
Definition: Proto_MBLevelBoxData.H:91
Pointwise Variable.
Definition: Proto_BoxData.H:117
Abstract Generic Parallel Copier.
Definition: Proto_Copier.H:60
Definition: Proto_MBDataPoint.H:10
Definition: Proto_Copier.H:22