Block-Structured AMR Software Framework
AMReX_Derive.H
Go to the documentation of this file.
1 #ifndef AMREX_Derive_H_
2 #define AMREX_Derive_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_ArrayLim.H>
6 #include <AMReX_REAL.H>
7 #include <AMReX_Box.H>
8 #include <AMReX_Interpolater.H>
9 #include <AMReX_MultiFab.H>
10 
11 #include <list>
12 #include <string>
13 
14 namespace amrex {
15 
16 extern "C"
17 {
18 
44  using DeriveFunc = void (*)(amrex::Real* data, AMREX_ARLIM_P(dlo), AMREX_ARLIM_P(dhi),
45  const int* nvar, const amrex::Real* compdat,
46  AMREX_ARLIM_P(compdat_lo), AMREX_ARLIM_P(compdat_hi),
47  const int* ncomp,
48  const int* lo, const int* hi,
49  const int* domain_lo, const int* domain_hi,
50  const amrex::Real* delta, const amrex::Real* xlo,
51  const amrex::Real* time, const amrex::Real* dt,
52  const int* bcrec,
53  const int* level, const int* grid_no) ;
54 
78  using DeriveFunc3D = void (*)(amrex::Real* data, const int* dlo, const int* dhi, const int* nvar,
79  const amrex::Real* compdat, const int* clo, const int* chi, const int* ncomp,
80  const int* lo, const int* hi,
81  const int* domain_lo, const int* domain_hi,
82  const amrex::Real* delta, const amrex::Real* xlo,
83  const amrex::Real* time, const amrex::Real* dt,
84  const int* bcrec,
85  const int* level, const int* grid_no) ;
86 }
87 
88 using DeriveFuncFab = std::function<void(const amrex::Box& bx, amrex::FArrayBox& derfab, int dcomp, int ncomp,
89  const amrex::FArrayBox& datafab, const amrex::Geometry& geomdata,
90  amrex::Real time, const int* bcrec, int level)>;
91 
92 using DeriveFuncMF = std::function<void(amrex::MultiFab& der_mf, int dcomp, int ncomp,
93  const amrex::MultiFab& data_mf, const amrex::Geometry& geomdata,
94  amrex::Real time, const int* bcrec, int level)>;
95 
96 class DescriptorList;
97 
98 
109 {
110  friend class DeriveList;
111 
112 public:
113 
118  using DeriveBoxMap = std::function<Box(const Box&)>;
119 
120  static Box TheSameBox (const Box& box) noexcept;
121 
122  static Box GrowBoxByOne (const Box& box) noexcept;
123 
127  ~DeriveRec ();
128 
129  DeriveRec (DeriveRec const&) = delete;
130  DeriveRec (DeriveRec &&) = delete;
131  DeriveRec& operator= (DeriveRec const&) = delete;
133 
137  [[nodiscard]] const std::string& name () const noexcept;
138 
144  [[nodiscard]] const std::string& variableName (int comp) const noexcept;
145 
149  [[nodiscard]] IndexType deriveType () const noexcept;
150 
154  [[nodiscard]] DeriveFunc derFunc () const noexcept;
155  [[nodiscard]] DeriveFunc3D derFunc3D () const noexcept;
156  [[nodiscard]] DeriveFuncFab derFuncFab () const noexcept;
157  [[nodiscard]] DeriveFuncMF derFuncMF () const noexcept;
158 
162  [[nodiscard]] DeriveBoxMap boxMap () const noexcept;
163 
167  [[nodiscard]] Interpolater* interp () const noexcept;
168 
172  [[nodiscard]] int numDerive () const noexcept;
173 
177  [[nodiscard]] int numRange () const noexcept;
178 
182  [[nodiscard]] int numState () const noexcept;
183 
187  [[nodiscard]] const int* getBC () const noexcept;
188  [[nodiscard]] const int* getBC3D () const noexcept;
189 
200  void getRange (int k,
201  int& state_indx,
202  int& src_comp,
203  int& num_comp) const;
204 
215  DeriveRec (std::string name,
216  IndexType result_type,
217  int nvar_derive,
218  DeriveFunc der_func,
219  DeriveBoxMap box_map,
221 
222  DeriveRec (std::string name,
223  IndexType result_type,
224  int nvar_derive,
225  DeriveFunc3D der_func_3d,
226  DeriveBoxMap box_map,
228 
229  DeriveRec (std::string name,
230  IndexType result_type,
231  int nvar_derive,
232  DeriveFuncFab der_func_fab,
233  DeriveBoxMap box_map,
235 
236  DeriveRec (std::string name,
237  IndexType result_type,
238  int nvar_derive,
239  DeriveFuncMF der_func_mf,
240  DeriveBoxMap box_map,
242 
243 
252  DeriveRec (std::string name,
253  IndexType result_type,
254  int nvar_derive,
255  DeriveRec::DeriveBoxMap box_map);
256 
268  DeriveRec (std::string name,
269  IndexType result_type,
270  int nvar_derive,
271  Vector<std::string> const& var_names,
272  DeriveFunc der_func,
273  DeriveBoxMap box_map,
275 
276  DeriveRec (std::string name,
277  IndexType result_type,
278  int nvar_derive,
279  Vector<std::string> const& var_names,
280  DeriveFunc3D der_func_3d,
281  DeriveBoxMap box_map,
283 
284  DeriveRec (std::string name,
285  IndexType result_type,
286  int nvar_derive,
287  Vector<std::string> const& var_names,
288  DeriveFuncFab der_func_fab,
289  DeriveBoxMap box_map,
291 
292  DeriveRec (std::string name,
293  IndexType result_type,
294  int nvar_derive,
295  Vector<std::string> const& var_names,
296  DeriveFuncMF der_func_mf,
297  DeriveBoxMap box_map,
299 
300  void addRange (const DescriptorList& d_list,
301  int state_indx,
302  int src_comp,
303  int num_comp);
304 
305  void buildBC (const DescriptorList& d_list);
306  void buildBC3D (const DescriptorList& d_list);
307 
309  struct StateRange
310  {
311  int typ;
312  int sc;
313  int nc;
315  };
316 
317 private:
318 
320  std::string derive_name;
321 
324 
327 
329  int n_derive = 0;
330 
332  DeriveFunc func = nullptr;
336 
338  Interpolater* mapper = nullptr;
339 
341  DeriveBoxMap bx_map = nullptr;
342 
344  int n_state = 0;
345 
347  int nsr = 0;
348 
350  StateRange* rng = nullptr;
351 
353  int* bcr = nullptr;
354  int* bcr3D = nullptr;
355 };
356 
357 
364 {
365 public:
366 
370  DeriveList () = default;
371 
372  ~DeriveList () = default;
373  DeriveList (const DeriveList&) = delete;
374  DeriveList (DeriveList &&) = delete;
375  DeriveList& operator= (const DeriveList&) = delete;
377 
383  [[nodiscard]] bool canDerive (const std::string& name) const;
384 
390  [[nodiscard]] const DeriveRec* get (const std::string& name) const;
391 
402  void add (const std::string& name,
403  IndexType result_type,
404  int nvar_derive,
405  DeriveFunc der_func,
406  const DeriveRec::DeriveBoxMap& bx_map,
407  Interpolater* interp = &pc_interp);
408 
409  void add (const std::string& name,
410  IndexType result_type,
411  int nvar_derive,
412  DeriveFunc3D der_func_3d,
413  const DeriveRec::DeriveBoxMap& bx_map,
414  Interpolater* interp = &pc_interp);
415 
416  void add (const std::string& name,
417  IndexType result_type,
418  int nvar_derive,
419  const DeriveFuncFab& der_func_fab,
420  const DeriveRec::DeriveBoxMap& bx_map,
421  Interpolater* interp = &pc_interp);
422 
423  void add (const std::string& name,
424  IndexType result_type,
425  int nvar_derive,
426  const DeriveFuncMF& der_func_mf,
427  const DeriveRec::DeriveBoxMap& bx_map,
428  Interpolater* interp = &pc_interp);
429 
438  void add (const std::string& name,
439  IndexType result_type,
440  int nvar_derive,
442 
454  void add (const std::string& name,
455  IndexType res_typ,
456  int nvar_derive,
457  Vector<std::string> const& vars,
458  DeriveFunc der_func,
459  const DeriveRec::DeriveBoxMap& bx_map,
460  Interpolater* interp = &pc_interp);
461 
462  void add (const std::string& name,
463  IndexType res_typ,
464  int nvar_derive,
465  Vector<std::string> const& vars,
466  DeriveFunc3D der_func_3d,
467  const DeriveRec::DeriveBoxMap& bx_map,
468  Interpolater* interp = &pc_interp);
469 
470  void add (const std::string& name,
471  IndexType res_typ,
472  int nvar_derive,
473  Vector<std::string> const& vars,
474  const DeriveFuncFab& der_func_fab,
475  const DeriveRec::DeriveBoxMap& bx_map,
476  Interpolater* interp = &pc_interp);
477 
478  void add (const std::string& name,
479  IndexType res_typ,
480  int nvar_derive,
481  Vector<std::string> const& vars,
482  const DeriveFuncMF& der_func_mf,
483  const DeriveRec::DeriveBoxMap& bx_map,
484  Interpolater* interp = &pc_interp);
485 
495  void addComponent (const std::string& name,
496  const DescriptorList& d_list,
497  int state_indx,
498  int s_comp,
499  int n_comp);
500 
501  [[nodiscard]] std::list<DeriveRec>& dlist ();
502 
503  void clear () { lst.clear(); }
504 
505 private:
506 
507  std::list<DeriveRec> lst;
508 };
509 
510 }
511 
512 #endif /*_Derive_H_*/
A list of DeriveRecs.
Definition: AMReX_Derive.H:364
DeriveList(DeriveList &&)=delete
DeriveList()=default
The default constructor.
~DeriveList()=default
void add(const std::string &name, IndexType result_type, int nvar_derive, DeriveFunc der_func, const DeriveRec::DeriveBoxMap &bx_map, Interpolater *interp=&pc_interp)
Adds another entry to the registry.
Definition: AMReX_Derive.cpp:378
std::list< DeriveRec > & dlist()
Definition: AMReX_Derive.cpp:480
const DeriveRec * get(const std::string &name) const
Access the particular record in registry.
Definition: AMReX_Derive.cpp:505
DeriveList & operator=(const DeriveList &)=delete
void clear()
Definition: AMReX_Derive.H:503
std::list< DeriveRec > lst
Definition: AMReX_Derive.H:507
bool canDerive(const std::string &name) const
Determines whether quantity identified by <name> is in the registry.
Definition: AMReX_Derive.cpp:486
DeriveList(const DeriveList &)=delete
void addComponent(const std::string &name, const DescriptorList &d_list, int state_indx, int s_comp, int n_comp)
Adds another StateRange to the DeriveRec identified by <name>.
Definition: AMReX_Derive.cpp:524
Derived Type Record.
Definition: AMReX_Derive.H:109
IndexType deriveType() const noexcept
The IndexType of the derived type.
Definition: AMReX_Derive.cpp:187
int numState() const noexcept
Total number of state variables needed for derived type.
Definition: AMReX_Derive.cpp:241
DeriveFunc func
Function that computes derived quantity from state variables.
Definition: AMReX_Derive.H:332
DeriveFuncMF func_mf
Definition: AMReX_Derive.H:335
DeriveFunc3D derFunc3D() const noexcept
Definition: AMReX_Derive.cpp:199
const std::string & name() const noexcept
The name of the derived type.
Definition: AMReX_Derive.cpp:181
int * bcr
Array of bndry types.
Definition: AMReX_Derive.H:353
int numDerive() const noexcept
Number of components in the derived type.
Definition: AMReX_Derive.cpp:229
int n_state
Total number of state variables.
Definition: AMReX_Derive.H:344
void getRange(int k, int &state_indx, int &src_comp, int &num_comp) const
Sets state_indx, src_comp and num_comp for the kth range (or chunk) of state data components needed t...
Definition: AMReX_Derive.cpp:295
int * bcr3D
Definition: AMReX_Derive.H:354
int n_derive
Number of components in derived quantity.
Definition: AMReX_Derive.H:329
const std::string & variableName(int comp) const noexcept
The names of components.
Definition: AMReX_Derive.cpp:368
void buildBC(const DescriptorList &d_list)
Definition: AMReX_Derive.cpp:314
~DeriveRec()
The destructor.
Definition: AMReX_Derive.cpp:162
DeriveFuncMF derFuncMF() const noexcept
Definition: AMReX_Derive.cpp:211
const int * getBC3D() const noexcept
Definition: AMReX_Derive.cpp:254
DeriveFunc derFunc() const noexcept
The DeriveFunc used to calculate the derived type.
Definition: AMReX_Derive.cpp:193
DeriveFunc3D func_3d
Definition: AMReX_Derive.H:333
static Box GrowBoxByOne(const Box &box) noexcept
Definition: AMReX_Derive.cpp:16
int nsr
Number of state ranges.
Definition: AMReX_Derive.H:347
void addRange(const DescriptorList &d_list, int state_indx, int src_comp, int num_comp)
Definition: AMReX_Derive.cpp:261
std::string derive_name
Name of derived quantity.
Definition: AMReX_Derive.H:320
std::function< Box(const Box &)> DeriveBoxMap
A pointer to function taking and returning a Box.
Definition: AMReX_Derive.H:118
static Box TheSameBox(const Box &box) noexcept
Definition: AMReX_Derive.cpp:10
DeriveBoxMap boxMap() const noexcept
Maps state data box to derived data box.
Definition: AMReX_Derive.cpp:217
DeriveRec(DeriveRec &&)=delete
DeriveRec(DeriveRec const &)=delete
IndexType der_type
Type of derived quantity.
Definition: AMReX_Derive.H:326
Interpolater * mapper
Interpolater for mapping crse grid derived data to finer levels.
Definition: AMReX_Derive.H:338
const int * getBC() const noexcept
The boundary conditions.
Definition: AMReX_Derive.cpp:247
DeriveRec & operator=(DeriveRec const &)=delete
DeriveBoxMap bx_map
Box mapper that specifies constituent region given derived region.
Definition: AMReX_Derive.H:341
int numRange() const noexcept
Number of different chunks of state data needed for derived type.
Definition: AMReX_Derive.cpp:235
Interpolater * interp() const noexcept
Type of interpolater to use in computing derived type.
Definition: AMReX_Derive.cpp:223
StateRange * rng
List of state data subranges required to derive given quantity.
Definition: AMReX_Derive.H:350
void buildBC3D(const DescriptorList &d_list)
Definition: AMReX_Derive.cpp:338
DeriveFuncFab func_fab
Definition: AMReX_Derive.H:334
DeriveFuncFab derFuncFab() const noexcept
Definition: AMReX_Derive.cpp:205
Vector< std::string > variable_names
Names of derived variables.
Definition: AMReX_Derive.H:323
Definition: AMReX_StateDescriptor.H:437
A Fortran Array of REALs.
Definition: AMReX_FArrayBox.H:229
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
Virtual base class for interpolaters.
Definition: AMReX_Interpolater.H:22
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
Definition: AMReX_Amr.cpp:49
void(*)(amrex::Real *data, const int *dlo, const int *dhi, const int *nvar, const amrex::Real *compdat, const int *clo, const int *chi, const int *ncomp, const int *lo, const int *hi, const int *domain_lo, const int *domain_hi, const amrex::Real *delta, const amrex::Real *xlo, const amrex::Real *time, const amrex::Real *dt, const int *bcrec, const int *level, const int *grid_no) DeriveFunc3D
This is dimension agnostic. For example, dlo always has three elements.
Definition: AMReX_Derive.H:85
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
std::function< void(amrex::MultiFab &der_mf, int dcomp, int ncomp, const amrex::MultiFab &data_mf, const amrex::Geometry &geomdata, amrex::Real time, const int *bcrec, int level)> DeriveFuncMF
Definition: AMReX_Derive.H:94
std::function< void(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datafab, const amrex::Geometry &geomdata, amrex::Real time, const int *bcrec, int level)> DeriveFuncFab
Definition: AMReX_Derive.H:90
void(*)(amrex::Real *data, AMREX_ARLIM_P(dlo), AMREX_ARLIM_P(dhi), const int *nvar, const amrex::Real *compdat, AMREX_ARLIM_P(compdat_lo), AMREX_ARLIM_P(compdat_hi), const int *ncomp, const int *lo, const int *hi, const int *domain_lo, const int *domain_hi, const amrex::Real *delta, const amrex::Real *xlo, const amrex::Real *time, const amrex::Real *dt, const int *bcrec, const int *level, const int *grid_no) DeriveFunc
Type of extern "C" function called by DeriveRec to compute derived quantity.
Definition: AMReX_Derive.H:53
PCInterp pc_interp
CONSTRUCT A GLOBAL OBJECT OF EACH VERSION.
Definition: AMReX_Interpolater.cpp:35
An element of a linked list to point to state quantities in AmrLevels.
Definition: AMReX_Derive.H:310
int typ
Definition: AMReX_Derive.H:311
int nc
Definition: AMReX_Derive.H:313
StateRange * next
Definition: AMReX_Derive.H:314
int sc
Definition: AMReX_Derive.H:312