Proto  3.2
Proto_AMRData.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_AMR_DATA_
3 #define _PROTO_AMR_DATA_
4 
5 #include "Proto_AMRGrid.H"
6 #include "Proto_LevelBoxData.H"
7 
8 namespace Proto
9 {
10 
11  /// AMR Data Hierarchy
12  /**
13  A nested hierarchy of data defined on an AMRGrid.
14  Each level is stored as a LevelBoxData<T, C, MEM, CTR>.
15 
16  \tparam T Type of data in array (int, double, etc.)
17  \tparam C Number of components
18  \tparam MEM Proto::MemType. HOST or DEVICE.
19  \tparam CTR Centering of underlying LevelBoxData
20  */
21  template<typename T, unsigned int C = 1,
23  class AMRData
24  {
25  public:
26 
27  /// Trivial Constructor
28  AMRData() {m_defined = false;}
29 
30  /// Grid Constructor
31  /**
32  Creates data holders for each layout level in the input grid with
33  specified ghost data space.
34 
35  \param grid An AMR Grid. Data is allocated only for existing levels
36  \param ghost Specifies the number of ghost cells to allocate
37  */
38  AMRData(AMRGrid& a_grid, Point a_ghost) { define (a_grid, a_ghost); }
39 
40  /// Alias Constructor
41  AMRData(std::vector<std::shared_ptr<LevelBoxData<T,C,MEM,CTR>>> a_data);
42 
43  /// Define
44  /**
45  Lazy construction. If *this is not yet defined, data holders are created based on the
46  inputs.
47  TODO: If *this was previously defined, redefine it based on the new grid
48  TODO: Determine how exiting data should be moved / reinitialized
49  */
50  inline void
51  define(AMRGrid& a_grid, Point a_ghost);
52 
53  /// Alias Define
54  inline void
55  define(std::vector<std::shared_ptr<LevelBoxData<T,C,MEM,CTR>>> a_data);
56 
57  /// Reinitialize grids and data due to regridding.
58  /**
59  For all levels starting at level a_lbase + 1, initialize new data holders.
60  (1) Define new DisjointBoxLayout, LevelBoxData.
61  (2) Interpolate / initialize from next coarser level.
62  (3) Copy on intersection from ald data at this level.
63  */
64  inline void
65  regrid(AMRGrid& a_newgrid, int a_lbase, int a_order);
66 
67  /// Grid Access (Const)
68  inline const AMRGrid& grid() const {return m_grid; }
69 
70  /// Grid Access (Non-Const)
71  inline AMRGrid& grid() { return m_grid;}
72 
73  /// Level Data Access (Const)
74  inline const LevelBoxData<T, C, MEM, CTR>&
75  operator[](unsigned int a_level) const;
76 
77  /// Level Data Access (Non-Const)
79  operator[](unsigned int a_level);
80 
81  /// Zero Initialize
82  inline void setToZero();
83 
84  /// Function Initialization
85  /**
86  Initializes *this using a function with a signature similar to that used by
87  Proto::forallInPlace_p. The input function must have the signature:
88 
89  <code>
90  void a_func(Point& a_point, Var<T, C, MEM>& a_thisData, Array<T, DIM> a_dx, ... )
91  </code>
92 
93  Unlike Proto::forall and its variants, this function cannot manage additional
94  data holders (e.g. Srcs should not include a LevelBoxData or similar complex object).
95  Unlike LevelBoxData::initialize(...), valid input functions must also include a
96  double argument representing the grid spacing, even if it is not used by the function
97  itself. Elements of a_srcs should be plain-old-data such as single values,
98  Points, or Boxes.
99 
100  \param dx0 Isotropic grid spacing on the coarsest level
101  \param func Initialization function
102  \param srcs Variadic arguments after the grid spacing in func
103  */
104  template<typename Func, typename... Srcs>
105  inline void initialize(T a_dx0, Func& a_func, Srcs... a_srcs);
106 
107  template<typename Func, typename... Srcs>
108  inline void initialize(const Array<T, DIM> a_dx0, Func& a_func, Srcs... a_srcs);
109 
110 
111  /// Function Initialization (With Convolution)
112  /**
113  Initialize *this as in <code>initialize</code> and then convolve the result using
114  a 4th-order convolution stencil to yield a cell-averaged field useful for finite
115  volume operations.
116  TODO: Do the correct thing here if CTR != PR_CELL
117 
118  \param dx0 Isotropic grid spacing on the coarsest level
119  \param func Initialization function
120  \param srcs Variadic arguments after the grid spacing in func
121  */
122  //template<typename Func, typename... Srcs>
123  //inline void initConvolve(double a_dx0, Func& a_func, Srcs... a_srcs);
124 
125  /// Average Down All Levels
126  /**
127  Synchronizes data between levels by recursively replacing coarse level data
128  with the geometric average of overlying fine data where it exists.
129 
130  TODO: Do the correct thing here if CTR != PR_CELL
131  TODO: Remove this from the AMRData API and make standalone(?)
132  */
133  inline void averageDown();
134 
135  /// Average Down Single Level
136  /**
137  Replace the data on a specified level with the geometric average of the overlying
138  fine data should any exist. If the specified level is the finest in the
139  hierarchy, this function is a null-op. There are more than one level finer than
140  the specified level, the average down is NOT computed recursively as in
141  <code>averageDown()</code>.
142  TODO: Do the correct thing here if CTR != PR_CELL
143  TODO: Remove this from the AMRData API and make standalone(?)
144 
145  \param crseLevel The level onto which finer level data will be averaged.
146  */
147  //inline void averageDown(int a_crseLevel);
148 
149  /// Interpolate Fine Boundaries
150  /**
151  Populate coarse-fine boundary ghost cells with data interpolated from the next
152  coarser level for all levels > 0.
153 
154  TODO: figure out how this should be defined for CTR != 0 (if at all)
155  TODO: Remove this from the AMRData API and make standalone
156 
157  \param a_order Order of interpolation. Valid values: 3, 5 (default 5)
158  */
159  //inline void interp(int a_order = 5);
160 
161  /// Interpolate Fine Boundaries
162  /**
163  Populate coarse-fine boundary ghost cells with data interpolated from the next
164  coarser level for the specified fine level ( > 0 )
165 
166  TODO: figure out how this should be defined for CTR != 0 (if at all)
167  TODO: Remove this from the AMRData API and make standalone
168 
169  \param a_order Order of interpolation. Valid values: 3, 5 (default 5)
170  */
171  //inline void interpLevel(int a_level, int a_order = 5);
173  /// Increment
174  /**
175  Add a scaled multiple of another AMRData to this. This function will fail
176  if the two AMRData do not share an AMRGrid configuration.
177  TODO: Implement += and -= operators for completeness
178 
179  \param data Another AMRData with the same AMRGrid configuration as *this
180  \param scale Optional scaling for the right-hand side data
181  */
182  inline void increment(AMRData<T, C, MEM, CTR>& a_data, T a_scale = 1.0);
183 
184  /// Multiply by a Constant
185  inline void operator*=(T a_value);
186  /// Increment by a Constant
187  inline void operator+=(T a_value);
188 
189  /// Compute Integral
190  /**
191  Compute the discrete integral over all valid data.
192  TODO: Right now this is just the integral over level 0. This is the correct
193  thing to do so long as averageDown has been called prior.
194 
195  \param cdx Coarsest grid spacing (Level 0)
196  */
197  inline T integrate(T a_cdx, unsigned int a_c = 0);
198  inline T integrate(const Array<T, DIM>& a_cdx, unsigned int a_c = 0);
199 
200  /// Compute Integral of Absolute Value
201  /**
202  Compute the discrete integral over all valid data.
203  TODO: Right now this is just the integral over level 0. This is the correct
204  thing to do so long as averageDown has been called prior.
205 
206  \param cdx Coarsest grid spacing (Level 0)
207  */
208  inline T integrateAbs(T a_cdx, unsigned int a_c = 0);
209  inline T integrateAbs(const Array<T, DIM>& a_cdx, unsigned int a_c = 0);
210 
211  /// Compute Max Norm
212  /**
213  Compute the max norm of a specified component.
214 
215  \param c A component in [0, C)
216  */
217  inline T absMax(unsigned int a_c = 0);
218 
219  /// Exchange
220  /**
221  Exchanges ghost cell data on all levels.
222  */
223  inline void exchange();
224 
225  /// Copy To
226  /**
227  Copies data from this into <code>a_rhs</code> on all levels shared
228  by the two AMRData objects.
229 
230  \param a_rhs Another AMRData.
231  */
232  inline void copyTo(AMRData<T, C, MEM, CTR>& a_rhs);
233 
234  /// Get Number of Levels
235  /**
236  Returns the number of levels in *this with a defined LevelBoxData.
237  This value will in general be different from the maximum number of levels.
238  TODO:
239  if numLevels() and grid().numLevels() are different, this is probably a bug. -CLG
240  */
241  inline int numLevels() const { return m_data.size(); }
242 
243  /// Get Max Levels
244  inline int maxLevels() const { return m_grid.maxLevels(); }
245 
246  private:
247 
248  bool m_defined;
251  //PC : debug
252  int m_counter = 0;
253  std::vector<std::shared_ptr<LevelBoxData<T, C, MEM, CTR>>> m_data;
254  };
255 
257 
258 #include "implem/Proto_AMRDataImplem.H"
259 }
260 #endif //end include guard
void increment(AMRData< T, C, MEM, CTR > &a_data, T a_scale=1.0)
Average Down Single Level.
Definition: Proto_AMRData.H:248
int m_counter
Definition: Proto_AMRData.H:252
AMRGrid m_grid
Definition: Proto_AMRData.H:249
std::vector< std::shared_ptr< LevelBoxData< T, C, MEM, CTR > > > m_data
Definition: Proto_AMRData.H:253
const AMRGrid & grid() const
Grid Access (Const)
Definition: Proto_AMRData.H:68
void initialize(T a_dx0, Func &a_func, Srcs... a_srcs)
Function Initialization.
Definition: Proto_AMRData.H:172
AMRData(AMRGrid &a_grid, Point a_ghost)
Grid Constructor.
Definition: Proto_AMRData.H:38
void operator+=(T a_value)
Increment by a Constant.
Definition: Proto_AMRData.H:263
MemType
Definition: Proto_MemType.H:7
Level Box Data.
Definition: Proto_HDF5.H:17
int maxLevels() const
Query Max Number of Levels.
Definition: Proto_AMRGrid.H:166
AMR Grid.
Definition: Proto_AMRGrid.H:26
Point m_ghost
Definition: Proto_AMRData.H:250
AMR Data Hierarchy.
Definition: Proto_AMRData.H:23
int maxLevels() const
Get Max Levels.
Definition: Proto_AMRData.H:244
void define(AMRGrid &a_grid, Point a_ghost)
Define.
Definition: Proto_AMRData.H:11
void averageDown()
Function Initialization (With Convolution)
Definition: Proto_AMRData.H:228
void exchange()
Exchange.
Definition: Proto_AMRData.H:349
T absMax(unsigned int a_c=0)
Compute Max Norm.
Definition: Proto_AMRData.H:321
void operator*=(T a_value)
Multiply by a Constant.
Definition: Proto_AMRData.H:274
Definition: Proto_Array.H:17
void setToZero()
Zero Initialize.
Definition: Proto_AMRData.H:161
AMRData()
Trivial Constructor.
Definition: Proto_AMRData.H:28
int numLevels() const
Get Number of Levels.
Definition: Proto_AMRData.H:241
Integer Valued Vector.
Definition: Proto_Point.H:24
T integrateAbs(T a_cdx, unsigned int a_c=0)
Compute Integral of Absolute Value.
Definition: Proto_AMRData.H:303
void regrid(AMRGrid &a_newgrid, int a_lbase, int a_order)
Reinitialize grids and data due to regridding.
Definition: Proto_AMRData.H:62
const LevelBoxData< T, C, MEM, CTR > & operator[](unsigned int a_level) const
Level Data Access (Const)
Definition: Proto_AMRData.H:152
Definition: Proto_Centering.H:9
T integrate(T a_cdx, unsigned int a_c=0)
Compute Integral.
Definition: Proto_AMRData.H:285
void copyTo(AMRData< T, C, MEM, CTR > &a_rhs)
Copy To.
Definition: Proto_AMRData.H:338
AMRData< short, 1, MEMTYPE_DEFAULT, PR_CELL > AMRTagData
Definition: Proto_AMRData.H:256
bool m_defined
Definition: Proto_AMRData.H:248
#define MEMTYPE_DEFAULT
Definition: Proto_MemType.H:24
AMRGrid & grid()
Grid Access (Non-Const)
Definition: Proto_AMRData.H:71
Centering
Definition: Proto_Centering.H:7