Proto  3.2
Proto_BoxOp.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_BOX_OP_
3 #define _PROTO_BOX_OP_
4 
5 #include "Proto_BoxData.H"
6 namespace Proto {
7 
8 /// Abstract Box-Scope Operator
9 /**
10  BoxOp is the class from which all operators on single patches, levels of patches, and AMR
11  hierarchies are derived. Representable operators are of the form:
12 
13  L(phi, rho) = d*D(phi, rho)*I + f*[Div(F(phi, rho)) + S(phi, rho)]
14  L: Full Operator
15  phi: State Variables
16  rho: Auxiliary Variables
17  D: Diagonal Component of L
18  F: Flux Component of L
19  S: Source Component of L
20  I: Identity
21  d: Diagonal Term Scaling
22  f: Flux and Source Term Scaling
23 
24  TODO: potentially template the op on the data-holder itself (e.g. BoxData) for
25  additional flexibility.
26 
27  \tparam T Datatype of the data holder (e.g. int, double, etc.)
28  \tparam C_STATE Number of state variables
29  \tparam C_AUX Number of auxiliary (non-state) variables
30  \tparam MEM Proto::MemType of the data holder
31 */
32 template <typename T, unsigned int C_STATE, unsigned int C_AUX, MemType MEM = MEMTYPE_DEFAULT>
33 class BoxOp
34 {
35  public:
38 
39  /// Get Number of State Variables
40  /**
41  Allows C_STATE to be known after template parameter binding
42  */
43  inline static constexpr unsigned int numState() { return C_STATE; }
44 
45  /// Get Number of Auxiliary Variables
46  /**
47  Allows C_AUX to be known after template parameter binding
48  */
49  inline static constexpr unsigned int numAux() { return C_AUX; }
50 
51  //TODO: In addition to the following, the interface requires these
52  // static functions. There is no good way to specify necessary static
53  // functions in an interface which is extremely awkward...
54  //
55  // static Point ghost() const; (Needed ghost data in the state variables)
56  // static Point auxGhost() const; (Needed ghost data in the aux variables)
57 
58  /// Default Constructor
59  inline BoxOp();
60 
61  /// Non-Trivial Isotropic Constructor
62  /**
63  \param dx Grid spacing
64  */
65  inline BoxOp(const DisjointBoxLayout& a_layout, const LevelIndex& a_index, T a_dx);
66 
67  /// Non-Trivial Anisotropic Constructor
68  /**
69  \param dx Grid spacing
70  */
71  inline BoxOp(const DisjointBoxLayout& a_layout, const LevelIndex& a_index, Array<T, DIM> a_dx);
72 
73  inline BoxOp(BoxOp<T,C_STATE,C_AUX,MEM>&& a_bop) = default;
75  /// Lazy Isotropic Constructor
76  /**
77  \param dx Grid spacing
78  */
79  inline void define(const DisjointBoxLayout& a_layout, const LevelIndex& a_index, T a_dx);
80 
81  /// Lazy Anisotropic Constructor
82  /**
83  \param dx Grid spacing
84  */
85  inline void define(
86  const DisjointBoxLayout& a_layout, const LevelIndex& a_index, Array<T, DIM> a_dx);
87 
88  /// Initialize
89  /**
90  User defined function that is called inside of define.
91  Useful for caching things like Stencil instances.
92  */
93  inline virtual void init(){}
94 
95  /// Spectral Radius (User Defined)
96  /**
97  Approximate spectral radius of the operator. Not required, but
98  Needed for iterative solvers.
99  */
100  inline virtual T spectralRadius() const { return 1; }
101 
102  /// Apply (In Place)
103  /**
104  Compute L(phi, rho)
105 
106  \param output Evaluated operator (output)
107  \param state State variables
108  \param aux Auxiliary variables
109  */
110  inline virtual void
111  operator()(
112  StateData& a_output,
113  const StateData& a_state,
114  const AuxData& a_aux,
115  T a_scale = 1.0) const;
116 
117  /// Apply (In Place)
118  /**
119  Compute L(phi)
120 
121  \param output Evaluated operator (output)
122  \param state State variables
123  */
124  inline virtual void
125  operator()(
126  StateData& a_output,
127  const StateData& a_state,
128  T a_scale = 1.0) const;
129 
130  /// Apply (In Place, Flux Output)
131  /**
132  Compute L(phi, rho)
133 
134  \param output Evaluated operator (output)
135  \param state State variables
136  \param aux Auxiliary variables
137  */
138  inline virtual void
139  operator()(
140  StateData& a_output,
141  Array<StateData, DIM>& a_fluxes,
142  const StateData& a_state,
143  const AuxData& a_aux,
144  T a_scale = 1.0) const;
145 
146  /// Apply (In Place, Flux Output)
147  /**
148  Compute L(phi)
149 
150  \param output Evaluated operator (output)
151  \param state State variables
152  */
153  inline virtual void
154  operator()(
155  StateData& a_output,
156  Array<StateData, DIM>& a_fluxes,
157  const StateData& a_state,
158  T a_scale = 1.0) const;
159 
160  /// Apply (Out of Place)
161  /**
162  Compute L(phi, rho).
163 
164  \param state State variables
165  \param aux Auxiliary variables
166  \param range Range of the output data
167  */
168  inline virtual StateData
169  operator()(
170  const StateData& a_state,
171  const AuxData& a_aux,
172  Box a_range,
173  T a_scale = 1.0) const;
174 
175  /// Apply (Out of Place)
176  /**
177  Compute L(phi)
178 
179  \param state State variables
180  \param range Range of the output data
181  */
182  inline virtual StateData
183  operator()(
184  const StateData& a_state,
185  Box a_range,
186  T a_scale = 1.0) const;
187 
188  /// Apply All Boundary Conditions
189  inline void
190  applyBC(
191  Array<StateData, DIM>& a_fluxes,
192  const StateData& a_state) const;
193 
194  /// Apply User Specified Boundary Condition
195  /**
196  */
197  inline virtual void
199  Array<StateData, DIM>& a_fluxes,
200  const StateData& a_state,
201  Face a_face) const {}
202 
203  /// User Defined Flux
204  /**
205  Compute F(phi, rho) in the direction dir
206 
207  \param flux Computed flux (output)
208  \param state State variables
209  \param aux Auxiliary variables
210  \param dir Direction in [0, DIM)
211  */
212  inline virtual void flux(
213  StateData& a_flux,
214  const StateData& a_state,
215  const AuxData& a_aux,
216  int a_dir) const;
217 
218  /// User Defined Flux
219  /**
220  Compute F(phi) in the direction dir
221 
222  \param flux Computed flux (output)
223  \param state State variables
224  \param dir Direction in [0, DIM)
225  */
226  inline virtual void flux(
227  StateData& a_flux,
228  const StateData& a_state,
229  int a_dir) const;
230 
231  /// User Defined Source
232  /**
233  Compute S(phi, rho)
234 
235  \param source Computed flux (output)
236  \param state State variables
237  \param aux Auxiliary variables
238  */
239  inline virtual void source(
240  StateData& a_source,
241  const StateData& a_state,
242  const AuxData& a_aux) const;
243 
244  /// User Defined Source
245  /**
246  Compute S(phi)
247 
248  \param source Computed flux (output)
249  \param state State variables
250  */
251  inline virtual void source(
252  StateData& a_source,
253  const StateData& a_state) const;
254 
255  /// User Defined Diagonal
256  /**
257  Compute D(phi, rho)
258 
259  \param diag Computed flux (output)
260  \param state State variables
261  \param aux Auxiliary variables
262  */
263  inline virtual void diag(
264  StateData& a_diag,
265  const StateData& a_state,
266  const AuxData& a_aux) const;
267 
268  /// User Defined Diagonal
269  /**
270  Compute D(phi)
271 
272  \param diag Computed flux (output)
273  \param state State variables
274  */
275  inline virtual void diag(
276  StateData& a_diag,
277  const StateData& a_state) const;
278 
279  ///TODO: not implemented (see MMB version which has this implemented)
280 #if 0
281  /// Apply All BCs relevant to a Box
282  /** Automates the logic for determining if the patch
283  * is on a domain boundary and calls the user defined
284  * applyBC function with the correct Face argument
285  */
286  inline void applyBC(
287  Array<StateData,DIM>& a_fluxes,
288  const StateData& a_state) const;
289 
290  /// Apply Specific BC (User Defined)
291  inline virtual void applyBC(
292  Array<StateData,DIM>& a_fluxes,
293  const StateData& a_state,
294  Face a_face);
295 
296 #endif
297  /// Set Diagonal Term Scaling
298  /**
299  Sets the value of d
300  */
301  inline void setDiagScale(T a_value);
302 
303  /// Set Flux Term Scaling
304  /**
305  Sets the value of f
306  */
307  inline void setFluxScale(T a_value);
308 
309  /// Set Time
310  inline void setTime(T a_time);
311 
312  /// Set Runge Kutta Stage
313  inline void setRKStage(unsigned int a_stage);
314 
315  /// Read Diagonal Term Scaling
316  inline T diagScale() const { return m_scaleDiag; }
317 
318  /// Read Flux Term Scaling
319  inline T fluxScale() const { return m_scaleFlux; }
320 
321  /// Read Flux Term Scaling
322  inline unsigned int RKStage() const { return m_RKStage; }
323 
324  /// Get Time
325  inline T time() const { return m_time; }
326 
327  /// Get Grid Spacing
328  inline Array<T, DIM> dx() const;
330  /// Get Min Grid Spacing
331  inline T dxMin() const;
332 
333  /// Get Max Grid Spacing
334  inline T dxMax() const;
335 
336  /// Get Index
337  inline const LevelIndex& index() const { return m_index; }
338 
339  /// Get Layout
340  inline const DisjointBoxLayout& layout() const { return m_layout; }
341 
342  /// Get Box
343  inline const Box& box() const {return m_layout[m_index]; }
344 
345  /// DEPRECATED
346  /// Mapped Multiblock Utilities
347 #if 0
348 
349  /// Map Constructor
350  /** a_x is node centered, a_J is cell averaged */
351  inline BoxOp(
352  const Box& a_box,
353  const Array<double, DIM>& a_dx,
354  const BoxData<double, DIM, MEM>& a_x,
356 
357  /// Map Define
358  /** a_x is node centered, a_J is cell averaged */
359  inline void define(
360  const Box& a_box,
361  const Array<double, DIM>& a_dx,
362  const BoxData<double, DIM, MEM>& a_x,
363  const BoxData<double, 1, MEM>& a_J);
364 
365  /// Get Coordinates
366  /** Output is immutable and node centered */
367  inline const BoxData<double, DIM, MEM>& x() const;
368 
369  /// Get Coordinates
370  /** Output is immutable and cell averaged */
371  inline const BoxData<double, 1, MEM>& jacobian() const;
372 
373  /// Enforce Block Boundary Flux Matching condition
374  inline virtual void matchFlux(
375  StateData& a_rhs,
376  const StateData& a_locFlux,
377  const StateData& a_adjFlux,
378  const StateData& a_state,
379  Point a_localDir) const;
380 
381  /// Match Block Boundary Fluxes using the average of fluxes
382  inline void matchFluxAverage(
383  StateData& a_rhs,
384  const StateData& a_locFlux,
385  const StateData& a_adjFlux,
386  Point a_localDir) const;
387 #endif
388 
389  protected:
393  unsigned int m_RKStage;
396 
397  mutable bool m_definedSrce;
398  mutable bool m_definedFlux;
399 
401 
402  private:
403 
404 };
406 #include "implem/Proto_BoxOpImplem.H"
407 } // end namespace Proto
408 
409 #endif // end include guard
unsigned int m_RKStage
Definition: Proto_BoxOp.H:393
Definition: Proto_Face.H:122
virtual void init()
Initialize.
Definition: Proto_BoxOp.H:93
Abstract Box-Scope Operator.
Definition: Proto_BoxOp.H:33
virtual void flux(StateData &a_flux, const StateData &a_state, const AuxData &a_aux, int a_dir) const
User Defined Flux.
Definition: Proto_BoxOp.H:269
T dxMin() const
Get Min Grid Spacing.
Definition: Proto_BoxOp.H:405
Array< T, DIM > dx() const
Get Grid Spacing.
Definition: Proto_BoxOp.H:395
const LevelIndex & index() const
Get Index.
Definition: Proto_BoxOp.H:337
T time() const
Get Time.
Definition: Proto_BoxOp.H:325
LevelIndex m_index
Definition: Proto_BoxOp.H:394
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
Disjoint Box Layout.
Definition: Proto_DisjointBoxLayout.H:30
bool m_definedSrce
Definition: Proto_BoxOp.H:397
T m_scaleDiag
Definition: Proto_BoxOp.H:390
virtual T spectralRadius() const
Spectral Radius (User Defined)
Definition: Proto_BoxOp.H:100
BoxOp()
Default Constructor.
Definition: Proto_BoxOp.H:6
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
BoxOp< T, C_STATE, C_AUX, MEM > & operator=(BoxOp< T, C_STATE, C_AUX, MEM > &&a_bop)=default
void setFluxScale(T a_value)
Set Flux Term Scaling.
Definition: Proto_BoxOp.H:365
BoxData< T, 1, MEM > jacobian(const BoxData< T, DIM, MEM > &a_X, const FluxBoxData< T, DIM, MEM > &a_NT)
Definition: Proto_Operator.H:1269
static constexpr unsigned int numState()
Get Number of State Variables.
Definition: Proto_BoxOp.H:43
static constexpr unsigned int numAux()
Get Number of Auxiliary Variables.
Definition: Proto_BoxOp.H:49
BoxData< T, C_STATE, MEM > StateData
Definition: Proto_BoxOp.H:36
unsigned int RKStage() const
Read Flux Term Scaling.
Definition: Proto_BoxOp.H:322
void define(const DisjointBoxLayout &a_layout, const LevelIndex &a_index, T a_dx)
Lazy Isotropic Constructor.
Definition: Proto_BoxOp.H:38
T diagScale() const
Read Diagonal Term Scaling.
Definition: Proto_BoxOp.H:316
void setRKStage(unsigned int a_stage)
Set Runge Kutta Stage.
Definition: Proto_BoxOp.H:385
DisjointBoxLayout m_layout
Definition: Proto_BoxOp.H:395
T fluxScale() const
Read Flux Term Scaling.
Definition: Proto_BoxOp.H:319
Definition: Proto_Array.H:17
virtual void applyBC(Array< StateData, DIM > &a_fluxes, const StateData &a_state, Face a_face) const
Apply User Specified Boundary Condition.
Definition: Proto_BoxOp.H:198
void applyBC(Array< StateData, DIM > &a_fluxes, const StateData &a_state) const
Apply All Boundary Conditions.
Definition: Proto_BoxOp.H:251
virtual void diag(StateData &a_diag, const StateData &a_state, const AuxData &a_aux) const
User Defined Diagonal.
Definition: Proto_BoxOp.H:329
Integer Valued Vector.
Definition: Proto_Point.H:24
Array< T, DIM > m_dx
Definition: Proto_BoxOp.H:400
void setTime(T a_time)
Set Time.
Definition: Proto_BoxOp.H:375
virtual void operator()(StateData &a_output, const StateData &a_state, const AuxData &a_aux, T a_scale=1.0) const
Apply (In Place)
Definition: Proto_BoxOp.H:184
T m_scaleFlux
Definition: Proto_BoxOp.H:391
BoxData< T, C_AUX, MEM > AuxData
Definition: Proto_BoxOp.H:37
T dxMax() const
Get Max Grid Spacing.
Definition: Proto_BoxOp.H:420
T m_time
Definition: Proto_BoxOp.H:392
virtual void operator()(StateData &a_output, Array< StateData, DIM > &a_fluxes, const StateData &a_state, T a_scale=1.0) const
Apply (In Place, Flux Output)
Definition: Proto_BoxOp.H:131
bool m_definedFlux
Definition: Proto_BoxOp.H:398
const Box & box() const
Get Box.
Definition: Proto_BoxOp.H:343
virtual void source(StateData &a_source, const StateData &a_state, const AuxData &a_aux) const
User Defined Source.
Definition: Proto_BoxOp.H:300
const DisjointBoxLayout & layout() const
Get Layout.
Definition: Proto_BoxOp.H:340
void setDiagScale(T a_value)
TODO: not implemented (see MMB version which has this implemented)
Definition: Proto_BoxOp.H:355