Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
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>
9#include <AMReX_MultiFab.H>
10
16#include <list>
17#include <string>
18
19namespace amrex {
20
21extern "C"
22{
23
49 using DeriveFunc = void (*)(amrex::Real* data, AMREX_ARLIM_P(dlo), AMREX_ARLIM_P(dhi),
50 const int* nvar, const amrex::Real* compdat,
51 AMREX_ARLIM_P(compdat_lo), AMREX_ARLIM_P(compdat_hi),
52 const int* ncomp,
53 const int* lo, const int* hi,
54 const int* domain_lo, const int* domain_hi,
55 const amrex::Real* delta, const amrex::Real* xlo,
56 const amrex::Real* time, const amrex::Real* dt,
57 const int* bcrec,
58 const int* level, const int* grid_no) ;
59
83 using DeriveFunc3D = void (*)(amrex::Real* data, const int* dlo, const int* dhi, const int* nvar,
84 const amrex::Real* compdat, const int* clo, const int* chi, const int* ncomp,
85 const int* lo, const int* hi,
86 const int* domain_lo, const int* domain_hi,
87 const amrex::Real* delta, const amrex::Real* xlo,
88 const amrex::Real* time, const amrex::Real* dt,
89 const int* bcrec,
90 const int* level, const int* grid_no) ;
91}
92
93using DeriveFuncFab = std::function<void(const amrex::Box& bx, amrex::FArrayBox& derfab, int dcomp, int ncomp,
94 const amrex::FArrayBox& datafab, const amrex::Geometry& geomdata,
95 amrex::Real time, const int* bcrec, int level)>;
96
97using DeriveFuncMF = std::function<void(amrex::MultiFab& der_mf, int dcomp, int ncomp,
98 const amrex::MultiFab& data_mf, const amrex::Geometry& geomdata,
99 amrex::Real time, const int* bcrec, int level)>;
100
101class DescriptorList;
102
103
114{
115 friend class DeriveList;
116
117public:
118
123 using DeriveBoxMap = std::function<Box(const Box&)>;
124
130 static Box TheSameBox (const Box& box) noexcept;
131
137 static Box GrowBoxByOne (const Box& box) noexcept;
138
142 ~DeriveRec ();
143
145 DeriveRec (DeriveRec const&) = delete;
147 DeriveRec (DeriveRec &&) = delete;
149 DeriveRec& operator= (DeriveRec const&) = delete;
152
156 [[nodiscard]] const std::string& name () const noexcept;
157
161 [[nodiscard]] const std::string& variableName (int comp) const noexcept;
162
166 [[nodiscard]] IndexType deriveType () const noexcept;
167
171 [[nodiscard]] DeriveFunc derFunc () const noexcept;
173 [[nodiscard]] DeriveFunc3D derFunc3D () const noexcept;
175 [[nodiscard]] DeriveFuncFab derFuncFab () const noexcept;
177 [[nodiscard]] DeriveFuncMF derFuncMF () const noexcept;
178
182 [[nodiscard]] DeriveBoxMap boxMap () const noexcept;
183
187 [[nodiscard]] Interpolater* interp () const noexcept;
188
192 [[nodiscard]] int numDerive () const noexcept;
193
197 [[nodiscard]] int numRange () const noexcept;
198
202 [[nodiscard]] int numState () const noexcept;
203
207 [[nodiscard]] const int* getBC () const noexcept;
209 [[nodiscard]] const int* getBC3D () const noexcept;
210
219 void getRange (int k,
220 int& state_indx,
221 int& src_comp,
222 int& num_comp) const;
223
234 DeriveRec (std::string name,
235 IndexType result_type,
236 int nvar_derive,
237 DeriveFunc der_func,
238 DeriveBoxMap box_map,
240
246 DeriveRec (std::string name,
247 IndexType result_type,
248 int nvar_derive,
249 DeriveFunc3D der_func_3d,
250 DeriveBoxMap box_map,
252
258 DeriveRec (std::string name,
259 IndexType result_type,
260 int nvar_derive,
261 DeriveFuncFab der_func_fab,
262 DeriveBoxMap box_map,
264
270 DeriveRec (std::string name,
271 IndexType result_type,
272 int nvar_derive,
273 DeriveFuncMF der_func_mf,
274 DeriveBoxMap box_map,
276
277
286 DeriveRec (std::string name,
287 IndexType result_type,
288 int nvar_derive,
289 DeriveRec::DeriveBoxMap box_map);
290
302 DeriveRec (std::string name,
303 IndexType result_type,
304 int nvar_derive,
305 Vector<std::string> const& var_names,
306 DeriveFunc der_func,
307 DeriveBoxMap box_map,
309
311 DeriveRec (std::string name,
312 IndexType result_type,
313 int nvar_derive,
314 Vector<std::string> const& var_names,
315 DeriveFunc3D der_func_3d,
316 DeriveBoxMap box_map,
318
320 DeriveRec (std::string name,
321 IndexType result_type,
322 int nvar_derive,
323 Vector<std::string> const& var_names,
324 DeriveFuncFab der_func_fab,
325 DeriveBoxMap box_map,
327
329 DeriveRec (std::string name,
330 IndexType result_type,
331 int nvar_derive,
332 Vector<std::string> const& var_names,
333 DeriveFuncMF der_func_mf,
334 DeriveBoxMap box_map,
336
345 void addRange (const DescriptorList& d_list,
346 int state_indx,
347 int src_comp,
348 int num_comp);
349
351 void buildBC (const DescriptorList& d_list);
353 void buildBC3D (const DescriptorList& d_list);
354
357 {
358 int typ;
359 int sc;
360 int nc;
362 };
363
364private:
365
367 std::string derive_name;
368
370 Vector<std::string> variable_names;
371
373 IndexType der_type;
374
376 int n_derive = 0;
377
379 DeriveFunc func = nullptr;
380 DeriveFunc3D func_3d = nullptr;
381 DeriveFuncFab func_fab = nullptr;
382 DeriveFuncMF func_mf = nullptr;
383
385 Interpolater* mapper = nullptr;
386
388 DeriveBoxMap bx_map = nullptr;
389
391 int n_state = 0;
392
394 int nsr = 0;
395
397 StateRange* rng = nullptr;
398
400 int* bcr = nullptr;
401 int* bcr3D = nullptr;
402};
403
404
411{
412public:
413
417 DeriveList () = default;
418
420 ~DeriveList () = default;
422 DeriveList (const DeriveList&) = delete;
424 DeriveList (DeriveList &&) = delete;
429
435 [[nodiscard]] bool canDerive (const std::string& name) const;
436
442 [[nodiscard]] const DeriveRec* get (const std::string& name) const;
443
454 void add (const std::string& name,
455 IndexType result_type,
456 int nvar_derive,
457 DeriveFunc der_func,
458 const DeriveRec::DeriveBoxMap& bx_map,
459 Interpolater* interp = &pc_interp);
460
462 void add (const std::string& name,
463 IndexType result_type,
464 int nvar_derive,
465 DeriveFunc3D der_func_3d,
466 const DeriveRec::DeriveBoxMap& bx_map,
467 Interpolater* interp = &pc_interp);
468
470 void add (const std::string& name,
471 IndexType result_type,
472 int nvar_derive,
473 const DeriveFuncFab& der_func_fab,
474 const DeriveRec::DeriveBoxMap& bx_map,
475 Interpolater* interp = &pc_interp);
476
478 void add (const std::string& name,
479 IndexType result_type,
480 int nvar_derive,
481 const DeriveFuncMF& der_func_mf,
482 const DeriveRec::DeriveBoxMap& bx_map,
483 Interpolater* interp = &pc_interp);
484
493 void add (const std::string& name,
494 IndexType result_type,
495 int nvar_derive,
497
509 void add (const std::string& name,
510 IndexType res_typ,
511 int nvar_derive,
512 Vector<std::string> const& vars,
513 DeriveFunc der_func,
514 const DeriveRec::DeriveBoxMap& bx_map,
515 Interpolater* interp = &pc_interp);
516
518 void add (const std::string& name,
519 IndexType res_typ,
520 int nvar_derive,
521 Vector<std::string> const& vars,
522 DeriveFunc3D der_func_3d,
523 const DeriveRec::DeriveBoxMap& bx_map,
524 Interpolater* interp = &pc_interp);
525
527 void add (const std::string& name,
528 IndexType res_typ,
529 int nvar_derive,
530 Vector<std::string> const& vars,
531 const DeriveFuncFab& der_func_fab,
532 const DeriveRec::DeriveBoxMap& bx_map,
533 Interpolater* interp = &pc_interp);
534
536 void add (const std::string& name,
537 IndexType res_typ,
538 int nvar_derive,
539 Vector<std::string> const& vars,
540 const DeriveFuncMF& der_func_mf,
541 const DeriveRec::DeriveBoxMap& bx_map,
542 Interpolater* interp = &pc_interp);
543
553 void addComponent (const std::string& name,
554 const DescriptorList& d_list,
555 int state_indx,
556 int s_comp,
557 int n_comp);
558
560 [[nodiscard]] std::list<DeriveRec>& dlist ();
561
563 void clear () { lst.clear(); }
564
565private:
566
567 std::list<DeriveRec> lst;
568};
569
570}
571
572#endif /*_Derive_H_*/
#define AMREX_ARLIM_P(x)
Definition AMReX_ArrayLim.H:30
Collection of spatial interpolaters used by FillPatch and flux-register logic.
A list of DeriveRecs.
Definition AMReX_Derive.H:411
DeriveList(DeriveList &&)=delete
Non-movable because the registry’s entries self-register with static globals.
DeriveList()=default
The default constructor.
~DeriveList()=default
Destructor (defaulted to keep header-only implementation trivial).
void add(const std::string &name, IndexType result_type, int nvar_derive, DeriveFunc der_func, const DeriveRec::DeriveBoxMap &bx_map, Interpolater *interp=&pc_interp)
Register a new derived quantity backed by a DeriveFunc.
Definition AMReX_Derive.cpp:378
std::list< DeriveRec > & dlist()
Mutable access to the underlying list of records.
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
Copy assignment disabled for the same reason as the copy constructor.
void clear()
Remove all registered derived records.
Definition AMReX_Derive.H:563
bool canDerive(const std::string &name) const
Determines whether quantity identified by name is registered.
Definition AMReX_Derive.cpp:486
DeriveList(const DeriveList &)=delete
Non-copyable registry; it owns pointers to callback records.
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:114
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
DeriveFunc3D derFunc3D() const noexcept
Dimension-agnostic version of derFunc() that always takes 3-component bounds.
Definition AMReX_Derive.cpp:199
const std::string & name() const noexcept
The name of the derived type.
Definition AMReX_Derive.cpp:181
int numDerive() const noexcept
Number of components in the derived type.
Definition AMReX_Derive.cpp:229
void getRange(int k, int &state_indx, int &src_comp, int &num_comp) const
Describe which chunk of state data is needed for derived component range k.
Definition AMReX_Derive.cpp:295
const std::string & variableName(int comp) const noexcept
Return the name of derived component comp.
Definition AMReX_Derive.cpp:368
void buildBC(const DescriptorList &d_list)
Build the 1D/2D BC arrays from the registered state descriptors d_list.
Definition AMReX_Derive.cpp:314
~DeriveRec()
The destructor.
Definition AMReX_Derive.cpp:162
DeriveFuncMF derFuncMF() const noexcept
MultiFab variant that fills directly without per-box callbacks.
Definition AMReX_Derive.cpp:211
const int * getBC3D() const noexcept
Boundary-condition array padded/truncated to three entries.
Definition AMReX_Derive.cpp:254
DeriveFunc derFunc() const noexcept
The DeriveFunc used to calculate the derived type.
Definition AMReX_Derive.cpp:193
static Box GrowBoxByOne(const Box &box) noexcept
Convenience mapper that grows the supplied box by one cell in every direction.
Definition AMReX_Derive.cpp:16
DeriveRec & operator=(DeriveRec const &)=delete
Copy assignment disabled for the same reason as the copy constructor.
void addRange(const DescriptorList &d_list, int state_indx, int src_comp, int num_comp)
Append another chunk of state data requirements.
Definition AMReX_Derive.cpp:261
std::function< Box(const Box &)> DeriveBoxMap
A pointer to function taking and returning a Box.
Definition AMReX_Derive.H:123
static Box TheSameBox(const Box &box) noexcept
Identity mapping from destination to source boxes.
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
Non-movable to keep internal pointers/registrations stable.
DeriveRec(DeriveRec const &)=delete
Non-copyable; derived metadata owns non-trivial resources.
const int * getBC() const noexcept
The boundary conditions.
Definition AMReX_Derive.cpp:247
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
void buildBC3D(const DescriptorList &d_list)
Build the 3D BC arrays from the registered state descriptors d_list.
Definition AMReX_Derive.cpp:338
DeriveFuncFab derFuncFab() const noexcept
Callable that operates on a FAB-sized box instead of raw pointers.
Definition AMReX_Derive.cpp:205
Definition AMReX_StateDescriptor.H:423
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:231
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
Virtual base class for interpolaters.
Definition AMReX_Interpolater.H:27
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
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:90
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:99
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
void(*)(amrex::Real *data, const int &, const int &, const int &, const int &, const int &, const int &, const int *nvar, const amrex::Real *compdat, const int &, const int &, const int &, const int &, const int &, const int &, 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:58
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:95
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:357
int typ
Definition AMReX_Derive.H:358
int nc
Definition AMReX_Derive.H:360
StateRange * next
Definition AMReX_Derive.H:361
int sc
Definition AMReX_Derive.H:359