Proto
Proto_LevelBoxData.H
1 #pragma once
2 #ifndef _PROTO_LEVELBOXDATA_H_
3 #define _PROTO_LEVELBOXDATA_H_
4 
5 #include "Proto_MemType.H"
6 #include "Proto_Point.H"
7 #include "Proto_Box.H"
8 #include "Proto_Copier.H"
9 #include "Proto_DisjointBoxLayout.H"
10 #include "Proto_LevelIterators.H"
11 #include "Proto_WriteBoxData.H"
12 #include "Proto_MayDay.H"
13 #include "Proto_SPMD.H"
14 #include <cstdlib> //for size_t
15 #include <iostream>
16 #include <cstring> // for Writing data to .vtk files.
17 #define LBD LevelBoxData<T, C, MEM, CTR>
18 
19 //using namespace std;
20 //using std::shared_ptr;
21 
22 namespace Proto
23 {
24  // Forward Declarations
25  template<typename T, unsigned int C, MemType MEM, unsigned int CTR>
26  class LevelBoxData;
27 
28 // =======================================================================
29 // LEVEL BOX DATA COPIER OP
30 
32 
36  template
37  <typename T, unsigned int C=1, MemType MEM = MemType::HOST ,unsigned int CTR=0 >
39  {
40  public:
43 
44  inline LevelCopierOp(){};
45 
46  inline LevelCopierOp(LBD& a_src, LBD& a_dst);
47 
49  inline int linearSize(const Box& a_bx,
50  const DataIndex& a_index) const;
51 
53  inline void linearOut(void* a_buf,
54  const Box& a_bx,
55  const DataIndex& a_index) const;
56 
58  inline void linearIn(void* a_buf,
59  const Box& a_bx,
60  const DataIndex& a_index) const;
61 
63  inline void localCopy(
64  const Box& a_domain, const DataIndex& a_domainIndex,
65  const Box& a_range, const DataIndex& a_rangeIndex) const;
66  };
67 // =======================================================================
68 // LEVEL BOX DATA COPIERS
69 
71 
74  template<typename T, unsigned int C=1, MemType MEM=MemType::HOST, unsigned int CTR=0>
75  class LevelCopier : public Copier<LevelCopierOp<T, C, MEM, CTR>>
76  {
77  public:
78 
79  inline LevelCopier(){};
80 
82  inline void buildMotionPlans(LevelCopierOp<T, C, MEM, CTR>& a_op);
83  };
84 
86 
90  template<typename T, unsigned int C=1, MemType MEM=MemType::HOST, unsigned int CTR=0>
91  class LevelExchangeCopier : public Copier<LevelCopierOp<T, C, MEM, CTR>>
92  {
93  public:
94 
95  inline LevelExchangeCopier(){};
96 
98  inline void buildMotionPlans(LevelCopierOp<T, C, MEM, CTR>& a_op);
99  };
100 
101 // =======================================================================
102 // LEVEL BOX DATA
103 
105 
108  template
109  <typename T, unsigned int C=1, MemType MEM=MemType::HOST, unsigned int CTR=DIM >
110  class LevelBoxData
111  {
112  public:
115 
118  inline LevelBoxData();
119 
121 
124  inline LevelBoxData(const DisjointBoxLayout& a_dbl, const Point& a_ghost);
127 
130  inline void define(const DisjointBoxLayout& a_dbl, const Point& a_ghost);
131 
133 
136  inline unsigned int size() const;
139 
143  inline void setToZero();
144 
146 
157  template<typename Func, typename... Srcs>
158  inline void initialize(Func& a_func, Srcs... a_srcs);
161 
166  inline void exchange();
167 
169 
174  inline void copyTo(LevelBoxData& a_dest) const;
175 
177 
181  inline unsigned int offset(int a_proc) const;
182  inline unsigned int offset() const { return offset(Proto::procID()); }
183 
185 
189  inline unsigned int patchSize() const;
190 
192 
200  inline void linearIn(void* a_buffer,
201  const Box& a_box,
202  const DataIndex& a_index);
203 
205 
213  inline void linearOut(void* a_buffer,
214  const Box& a_box,
215  const DataIndex& a_index) const;
216 
218 
225  inline size_t linearSize(const Box& a_box,
226  const DataIndex& a_index) const;
228 
231  inline void linearIn(void* a_buffer,
232  const DataIndex& a_index);
234 
237  inline void linearOut(void* a_buffer,
238  const DataIndex& a_index) const;
240 
243  inline size_t linearSize( const DataIndex& a_index) const;
244 
246 
249  inline void linearIn(void* a_buffer);
251 
254  inline void linearOut(void* a_buffer) const;
256 
259  inline size_t linearSize() const;
260 
262  inline DisjointBoxLayout layout() const { return m_dbl; }
264  inline DisjointBoxLayout getDBL() const { return m_dbl; }
265 
267  inline Point ghost() const { return m_ghost; }
269  inline Point getGhostVector() const {return m_ghost;}
270 
271  //=======================================
272  // DATA ITERATOR INTERFACE
273 
275  inline BoxData<T,C,MEM>& operator[](const DataIndex& a_index);
277  inline const BoxData<T,C,MEM>& operator[](const DataIndex& a_index) const;
278 
280  inline DataIterator begin() const;
281 
283  int s_verbosity = 0;
284 
285  private:
286 
287  std::vector<shared_ptr<BoxData<T,C> > > m_data;
288  Point m_ghost;
289  DisjointBoxLayout m_dbl;
290  bool m_isDefined;
291  LevelExchangeCopier<T, C, MEM, CTR> m_exchangeCopier;
292 
293  // disallow copy constructors and assignment operators
294  // to avoid very hard-to-find performance problems
297  }; // end class LevelBoxData
298 
299 #include "implem/Proto_LevelBoxDataImplem.H"
300 } //end namespace Proto
301 #endif
Definition: Proto_LevelIterators.H:19
int linearSize(const Box &a_bx, const DataIndex &a_index) const
Get Serialized Size.
Definition: Proto_LevelBoxData.H:257
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:458
Disjoint Box Layout.
Definition: Proto_DisjointBoxLayout.H:37
void localCopy(const Box &a_domain, const DataIndex &a_domainIndex, const Box &a_range, const DataIndex &a_rangeIndex) const
Local Copy.
Definition: Proto_LevelBoxData.H:288
Level Box Data.
Definition: Proto_LevelBoxData.H:26
Level Copier Operator.
Definition: Proto_LevelBoxData.H:38
An interval in DIM dimensional space.
Definition: Proto_Box.H:26
DisjointBoxLayout layout() const
Get Box Layout.
Definition: Proto_LevelBoxData.H:262
int procID()
local process ID
Definition: Proto_SPMD.H:52
Level Copier.
Definition: Proto_LevelBoxData.H:75
Definition: Proto_Box.H:11
void linearIn(void *a_buf, const Box &a_bx, const DataIndex &a_index) const
Serial Read From Buffer.
Definition: Proto_LevelBoxData.H:277
Integer Valued Vector.
Definition: Proto_Point.H:21
Point ghost() const
Get Ghost Size.
Definition: Proto_LevelBoxData.H:267
void linearOut(void *a_buf, const Box &a_bx, const DataIndex &a_index) const
Serial Write To Buffer.
Definition: Proto_LevelBoxData.H:266
Definition: Proto_DataIndex.H:17
DisjointBoxLayout getDBL() const
Get Box Layout (Overload)
Definition: Proto_LevelBoxData.H:264
Point getGhostVector() const
Get Ghost Size (Overload)
Definition: Proto_LevelBoxData.H:269
Abstract Generic Parallel Copier.
Definition: Proto_Copier.H:52
Exchange Copier.
Definition: Proto_LevelBoxData.H:91