Proto  3.2
Proto_AMROp.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_AMR_OP_
3 #define _PROTO_AMR_OP_
4 
5 #include "Proto_AMRData.H"
6 
7 namespace Proto {
8 
9 /// AMR-Scope Operator
10 /**
11  AMROp contains the necessary tools to apply a user-defined descendent of
12  BoxOp on an AMR hierarchy.
13 
14  \tparam OpType A BoxOp class
15  \tparam T Datatype of the data holder (e.g. int, double, etc.)
16  \tparam MEM Proto::MemType of the data holder
17 */
18 
19 template <template<typename, MemType> class OPType,
20  typename T, MemType MEM>
21 class AMROp
22 {
23  public:
24 
25  typedef OPType<T, MEM> BOP;
26  // NB: PeriodicBC isn't used because BCs are computed manually by AMROp
34 
35  static constexpr unsigned int numState() { return BOP::numState(); }
36  static constexpr unsigned int numAux() { return BOP::numAux(); }
37 
38  /// Ghost Region Size (State)
39  /**
40  Amount of data needed in ghost regions of state variables to apply the operator
41  */
42  static Point ghost() { return BOP::ghost(); }
43 
44  /// Ghost Region Size (Auxiliary)
45  /**
46  Amount of data needed in ghost regions of auxiliary variables to apply the operator
47  */
48  static Point auxGhost()
49  {
50  if (numAux() > 0) { return BOP::auxGhost(); }
51  return Point::Zeros();
52  }
53 
54  static int order()
55  {
56  return BOP::order();
57  }
58 
59  /// Default Constructor
60  inline AMROp();
61 
62  /// Non-Trivial Constructor
63  /**
64  \param grid AMR Grid
65  \param cdx Coarsest level grid spacing
66  */
67  inline AMROp(AMRGrid& a_grid, T a_cdx);
68  inline AMROp(AMRGrid& a_grid, Array<T, DIM>& a_cdx);
69 
70  /// Lazy Constructor
71  /**
72  \param grid AMR Grid
73  \param cdx Coarsest level grid spacing
74  */
75  inline void define(AMRGrid& a_grid, T a_cdx);
76  inline void define(AMRGrid& a_grid, Array<T, DIM>& a_cdx);
77 
78  /// Apply
79  /**
80  Compute L(phi, rho) on all levels of the hierarchy including reflux
81  corrections and boundary condition interpolation where necessary
82 
83  \param output Evaluated operator (output)
84  \param state State variables
85  \param aux Auxiliary variables
86  */
87  inline void
88  operator()(
89  AMRStateData& a_output,
90  const AMRStateData& a_state,
91  const AMRAuxData& a_aux,
92  T a_scale = 1.0);
93 
94  /// Apply
95  /**
96  Compute L(phi) on all levels of the hierarchy including reflux
97  corrections and boundary condition interpolation where necessary
98 
99  \param output Evaluated operator (output)
100  \param state State variables
101  */
102  inline void
103  operator()(
104  AMRStateData& a_output,
105  AMRStateData& a_state,
106  T a_scale = 1.0);
107 
108  /// Level Apply
109  /**
110  Compute L(phi, rho) on a specified level of the hierarchy including reflux
111  corrections and boundary condition interpolation.
112 
113  \param output Evaluated operator (output)
114  \param state State variables
115  \param aux Auxiliary variables
116  \param level Specified level of application
117  */
118  inline void
119  levelApply(
120  LevelStateData& a_output,
121  AMRStateData& a_state,
122  AMRAuxData& a_aux,
123  int a_level,
124  T a_scale = 1.0);
125 
126  /// Level Apply
127  /**
128  Compute L(phi) on a specified level of the hierarchy including reflux
129  corrections and boundary condition interpolation.
130 
131  \param output Evaluated operator (output)
132  \param state State variables
133  \param level Specified level of application
134  */
135  inline void
136  levelApply(
137  LevelStateData& a_output,
138  AMRStateData& a_state,
139  int a_level,
140  T a_scale = 1.0);
141 
142  /// Reflux
143  /**
144  Given state variable information on two levels l and l+1, compute and apply
145  the appropriate reflux correction to a dataset on level l.
146 
147  \param crseOut The coarse level dataset to which refluxing will be applied
148  \param crseState coarse level state data (level l)
149  \param fineState fine level state data (level l+1)
150  \param crseLevel The level on which refluxing is computed (level l)
151  \param scale An optional value which will scale the reflux correction
152  */
153  inline void
154  reflux(
155  LevelStateData& a_crseOut,
156  LevelStateData& a_crseState,
157  LevelStateData& a_fineState,
158  int a_crseLevel,
159  T a_scale) const;
160 
161 
162  inline InterpStencil<T>& interpStencil(int a_level);
163 
164  inline void setDiagScale(T a_value, int a_gridFactor = 0);
165  inline void setFluxScale(T a_value, int a_gridFactor = 0);
166  inline Array<T, DIM> dx(int a_level) const { return m_dx[a_level]; }
167  const LOP& levelOp(int a_level) const { return *m_levelOps[a_level]; }
168  const BOP& boxOp(int a_level, const LevelIndex& a_index) const { return levelOp(a_level)[a_index]; }
169 
170  private:
171 
172  bool m_defined;
173  AMRGrid m_grid; //this is intentionally a deep copy.
174  std::vector<Array<T, DIM>> m_dx;
175  std::vector<std::shared_ptr<LOP>> m_levelOps;
176  std::vector<std::shared_ptr<LevelFluxRegister<T, BOP::numState(), MEM>>> m_fluxRegisters;
177  std::vector<InterpStencil<T>> m_interp;
178 };
179 
180 #include "implem/Proto_AMROpImplem.H"
181 
182 } // end namespace Proto
183 #endif // end include guard
184 
AMRData< T, BOP::numAux(), MEM, PR_CELL > AMRAuxData
Definition: Proto_AMROp.H:29
AMRGrid m_grid
Definition: Proto_AMROp.H:173
LevelOp< OPType, T, PeriodicBC, MEM > LOP
Definition: Proto_AMROp.H:27
std::vector< Array< T, DIM > > m_dx
Definition: Proto_AMROp.H:174
AMROp()
Default Constructor.
Definition: Proto_AMROp.H:4
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
BoxData< T, BOP::numState(), MEM > StateData
Definition: Proto_AMROp.H:32
std::vector< InterpStencil< T > > m_interp
Definition: Proto_AMROp.H:177
AMRData< T, BOP::numState(), MEM, PR_CELL > AMRStateData
Definition: Proto_AMROp.H:28
MemType
Definition: Proto_MemType.H:7
AMR-Scope Operator.
Definition: Proto_AMROp.H:21
Level Box Data.
Definition: Proto_HDF5.H:17
Definition: Proto_InterpStencil.H:14
static constexpr unsigned int numState()
Definition: Proto_AMROp.H:35
static constexpr unsigned int numAux()
Definition: Proto_AMROp.H:36
AMR Grid.
Definition: Proto_AMRGrid.H:26
InterpStencil< T > & interpStencil(int a_level)
Definition: Proto_AMROp.H:280
void reflux(LevelStateData &a_crseOut, LevelStateData &a_crseState, LevelStateData &a_fineState, int a_crseLevel, T a_scale) const
Reflux.
Definition: Proto_AMROp.H:234
OPType< T, MEM > BOP
Definition: Proto_AMROp.H:25
AMR Data Hierarchy.
Definition: Proto_AMRData.H:23
static Point auxGhost()
Ghost Region Size (Auxiliary)
Definition: Proto_AMROp.H:48
Level-Scope Operator.
Definition: Proto_LevelOp.H:25
BoxData< T, BOP::numAux(), MEM > AuxData
Definition: Proto_AMROp.H:33
void levelApply(LevelStateData &a_output, AMRStateData &a_state, AMRAuxData &a_aux, int a_level, T a_scale=1.0)
Level Apply.
Definition: Proto_AMROp.H:145
const LOP & levelOp(int a_level) const
Definition: Proto_AMROp.H:167
static Point ghost()
Ghost Region Size (State)
Definition: Proto_AMROp.H:42
Array< T, DIM > dx(int a_level) const
Definition: Proto_AMROp.H:166
LevelBoxData< T, BOP::numState(), MEM, PR_CELL > LevelStateData
Definition: Proto_AMROp.H:30
static ACCEL_DECORATION Point Zeros()
Get Zeros.
Definition: Proto_Array.H:17
void operator()(AMRStateData &a_output, const AMRStateData &a_state, const AMRAuxData &a_aux, T a_scale=1.0)
Apply.
Definition: Proto_AMROp.H:65
static int order()
Definition: Proto_AMROp.H:54
Integer Valued Vector.
Definition: Proto_Point.H:24
LevelBoxData< T, BOP::numAux(), MEM, PR_CELL > LevelAuxData
Definition: Proto_AMROp.H:31
void setDiagScale(T a_value, int a_gridFactor=0)
Definition: Proto_AMROp.H:288
void setFluxScale(T a_value, int a_gridFactor=0)
Definition: Proto_AMROp.H:311
std::vector< std::shared_ptr< LOP > > m_levelOps
Definition: Proto_AMROp.H:175
bool m_defined
Definition: Proto_AMROp.H:172
void define(AMRGrid &a_grid, T a_cdx)
Lazy Constructor.
Definition: Proto_AMROp.H:22
std::vector< std::shared_ptr< LevelFluxRegister< T, BOP::numState(), MEM > > > m_fluxRegisters
Definition: Proto_AMROp.H:176
const BOP & boxOp(int a_level, const LevelIndex &a_index) const
Definition: Proto_AMROp.H:168