Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_StateDescriptor.H
Go to the documentation of this file.
1
2#ifndef AMREX_StateDescriptor_H_
3#define AMREX_StateDescriptor_H_
4#include <AMReX_Config.H>
5
6#include <AMReX_Array.H>
7#include <AMReX_Vector.H>
8#include <AMReX_REAL.H>
9#include <AMReX_Box.H>
10#include <AMReX_PhysBCFunct.H>
11#include <AMReX_Interpolater.H>
13#ifdef AMREX_USE_EB
16#endif
17
18#include <utility>
19#include <memory>
20
21namespace amrex {
22
23 using BndryFuncFabDefault = std::function<void(Box const& bx, FArrayBox& data,
24 int dcomp, int numcomp,
25 Geometry const& geom, Real time,
26 const Vector<BCRec>& bcr, int bcomp,
27 int scomp)>;
28
33{
34 friend class DescriptorList;
35
36public:
37
39 enum TimeCenter { Point = 0 , Interval };
40
47 {
48 public:
49
53 BndryFunc () noexcept = default;
54
60 BndryFunc (BndryFuncDefault inFunc) noexcept : m_func(inFunc) {}
61
67 BndryFunc (BndryFunc3DDefault inFunc) noexcept : m_func3D(inFunc) {}
68
74 BndryFunc (BndryFuncFabDefault inFunc) noexcept : m_funcfab(std::move(inFunc)) {}
75
83 : m_func(inFunc), m_gfunc(gFunc) {}
84
87 : m_func3D(inFunc), m_gfunc3D(gFunc) {}
88
102 void operator () (Real* data, const int* lo, const int* hi,
103 const int* dom_lo, const int* dom_hi,
104 const Real* dx, const Real* grd_lo,
105 const Real* time, const int* bc) const;
106
121 void operator () (Real* data, const int* lo, const int* hi,
122 const int* dom_lo, const int* dom_hi,
123 const Real* dx, const Real* grd_lo,
124 const Real* time, const int* bc, int ng) const;
138 void operator () (Box const& bx, FArrayBox& data,
139 int dcomp, int numcomp,
140 Geometry const& geom, Real time,
141 const Vector<BCRec>& bcr, int bcomp,
142 int scomp) const;
143
144 [[nodiscard]] bool RunOnGPU () const noexcept { return m_run_on_gpu; }
145
146 void setRunOnGPU (bool b) noexcept { m_run_on_gpu = b; }
147
148 [[nodiscard]] bool hasFabVersion () const noexcept { return m_funcfab != nullptr; }
149
150 private:
151
152 BndryFuncDefault m_func = nullptr;
153 BndryFunc3DDefault m_func3D = nullptr;
154 BndryFuncDefault m_gfunc = nullptr;
155 BndryFunc3DDefault m_gfunc3D = nullptr;
156 BndryFuncFabDefault m_funcfab = nullptr;
157 bool m_run_on_gpu = false;
158 };
159
163 StateDescriptor () noexcept {} // NOLINT /* = default does not work with old clang */
164
178 TimeCenter ttyp,
179 int ident,
180 int nextra,
181 int num_comp,
183 bool extrap = false,
184 bool store_in_checkpoint = true);
185
198 void define (IndexType btyp,
199 TimeCenter ttyp,
200 int ident,
201 int nextra,
202 int num_comp,
204 bool extrap = false,
205 bool store_in_checkpoint = true);
206
218 void setComponent (int comp,
219 const std::string& nm,
220 const BCRec& bc,
221 const BndryFunc& func,
222 InterpBase* interp = nullptr,
223 int max_map_start_comp = -1,
224 int min_map_end_comp = -1);
225
237 void setComponent (int comp,
238 const std::string& nm,
239 const BCRec& bc,
240 const BndryFunc& func,
242 bool a_primary,
243 int groupsize);
244
252 void resetComponentBCs (int comp,
253 const BCRec& bcr,
254 const BndryFunc& func);
255
263 void dumpNames (std::ostream& os,
264 int start_comp,
265 int num_comp) const;
266
270 [[nodiscard]] IndexType getType () const noexcept;
271
275 [[nodiscard]] StateDescriptor::TimeCenter timeType () const noexcept;
276
280 [[nodiscard]] int nComp () const noexcept;
281
285 [[nodiscard]] int nExtra () const noexcept;
286
290 [[nodiscard]] InterpBase* interp () const noexcept;
291
297 [[nodiscard]] InterpBase* interp (int i) const noexcept;
298
304 [[nodiscard]] const std::string& name (int i) const noexcept;
305
311 [[nodiscard]] const BCRec& getBC (int i) const noexcept;
312
316 [[nodiscard]] const Vector<BCRec>& getBCs () const noexcept;
317
323 [[nodiscard]] const BndryFunc& bndryFill (int i) const noexcept;
324
331 [[nodiscard]] int inRange (int sc, int nc) const noexcept;
332
339 [[nodiscard]] bool identicalInterps (int scomp, int ncomp) const noexcept;
341 [[nodiscard]] std::vector< std::pair<int,int> > sameInterps (int scomp, int ncomp) const;
342
346 [[nodiscard]] bool extrap () const noexcept;
347
351 [[nodiscard]] bool store_in_checkpoint () const noexcept;
352
354 [[nodiscard]] bool primary (int i) const noexcept { return m_primary[i]; }
355
357 [[nodiscard]] int groupsize (int i) const noexcept { return m_groupsize[i]; }
358
359
363 [[nodiscard]] bool RunOnGPU () const noexcept { return bc_func[0]->RunOnGPU(); }
364
368 [[nodiscard]] bool hasBndryFuncFab () const noexcept { return bc_func[0]->hasFabVersion(); }
369
371 static void setBndryFuncThreadSafety (int ext_dir_safe) noexcept {
372 bf_ext_dir_threadsafe = ext_dir_safe;
373 }
374
375private:
376
377 IndexType type;
378 TimeCenter t_type{Point};
379 int id{-1};
380 int ncomp{0};
381 int ngrow{0};
382 InterpBase* mapper{nullptr};
383 bool m_extrap{false};
384 bool m_store_in_checkpoint{true};
385 Vector<std::string> names;
386 Vector<BCRec> bc;
387 Vector<std::unique_ptr<BndryFunc> > bc_func;
388 Vector<int> m_primary;
389 Vector<int> m_groupsize;
390
395 Vector<InterpBase*> mapper_comp;
396
407 Vector<int> max_map_start_comp;
408 Vector<int> min_map_end_comp;
409
410 static int bf_ext_dir_threadsafe;
411
412 static bool bf_thread_safety (const int* lo,const int* hi,
413 const int* dom_lo, const int* dom_hi,
414 const int* bc, int ng);
415};
416
423{
424public:
425
427 void clear ();
428
430 [[nodiscard]] int size () const noexcept;
431
444 void addDescriptor (int indx,
445 IndexType typ,
447 int nextra,
448 int num_comp,
449 InterpBase* interp,
450 bool extrap = false,
451 bool store_in_checkpoint = true);
452
461 void resetComponentBCs (int indx,
462 int comp,
463 const BCRec& bc,
464 const StateDescriptor::BndryFunc& func);
465
478 void setComponent (int indx,
479 int comp,
480 const std::string& nm,
481 const BCRec& bc,
482 const StateDescriptor::BndryFunc& func,
483 InterpBase* interp = nullptr,
484 int max_map_start_comp = -1,
485 int min_map_end_comp = -1);
486
497 void setComponent (int indx,
498 int comp,
499 const Vector<std::string>& nm,
500 const Vector<BCRec>& bc,
501 const StateDescriptor::BndryFunc& func,
502 InterpBase* interp = nullptr);
504 const StateDescriptor& operator[] (int k) const noexcept;
505
506private:
507
509};
510
511}
512
513#endif /*_StateDescriptor_H_*/
Collection of spatial interpolaters used by FillPatch and flux-register logic.
Interpolaters that operate directly on MultiFabs (cell- or node-centered).
Boundary Condition Records. Necessary information and functions for computing boundary conditions.
Definition AMReX_BCRec.H:17
Definition AMReX_StateDescriptor.H:423
const StateDescriptor & operator[](int k) const noexcept
Returns StateDescriptor stored at index k.
Definition AMReX_StateDescriptor.cpp:165
void clear()
Remove all descriptors and reset the list to an empty state.
Definition AMReX_StateDescriptor.cpp:112
void resetComponentBCs(int indx, int comp, const BCRec &bc, const StateDescriptor::BndryFunc &func)
Forward resetComponentBCs() to descriptor indx.
Definition AMReX_StateDescriptor.cpp:124
void setComponent(int indx, int comp, const std::string &nm, const BCRec &bc, const StateDescriptor::BndryFunc &func, InterpBase *interp=nullptr, int max_map_start_comp=-1, int min_map_end_comp=-1)
Forward the basic setComponent() overload to descriptor indx.
Definition AMReX_StateDescriptor.cpp:133
int size() const noexcept
Returns number of descriptors currently stored.
Definition AMReX_StateDescriptor.cpp:118
void addDescriptor(int indx, IndexType typ, StateDescriptor::TimeCenter ttyp, int nextra, int num_comp, InterpBase *interp, bool extrap=false, bool store_in_checkpoint=true)
Adds a new StateDescriptor at index indx.
Definition AMReX_StateDescriptor.cpp:171
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:231
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
Definition AMReX_InterpBase.H:34
Definition AMReX_StateDescriptor.H:47
BndryFunc() noexcept=default
Bogus constructor.
BndryFunc(BndryFuncFabDefault inFunc) noexcept
Construct from a FAB-aware functor inFunc.
Definition AMReX_StateDescriptor.H:74
BndryFunc(BndryFunc3DDefault inFunc, BndryFunc3DDefault gFunc) noexcept
3D counterpart installing per-cell function inFunc and group function gFunc.
Definition AMReX_StateDescriptor.H:86
bool RunOnGPU() const noexcept
Definition AMReX_StateDescriptor.H:144
void setRunOnGPU(bool b) noexcept
Definition AMReX_StateDescriptor.H:146
BndryFunc(BndryFunc3DDefault inFunc) noexcept
Construct from a 3-D boundary-fill callback inFunc.
Definition AMReX_StateDescriptor.H:67
void operator()(Real *data, const int *lo, const int *hi, const int *dom_lo, const int *dom_hi, const Real *dx, const Real *grd_lo, const Real *time, const int *bc) const
Fill boundary cells using the "regular" scalar function pointer.
Definition AMReX_StateDescriptor.cpp:30
bool hasFabVersion() const noexcept
Definition AMReX_StateDescriptor.H:148
BndryFunc(BndryFuncDefault inFunc, BndryFuncDefault gFunc) noexcept
Constructor that installs both regular and group boundary callbacks.
Definition AMReX_StateDescriptor.H:82
Attributes of StateData.
Definition AMReX_StateDescriptor.H:33
InterpBase * interp() const noexcept
Returns the interpolater.
Definition AMReX_StateDescriptor.cpp:253
const std::string & name(int i) const noexcept
Returns the name of component i.
Definition AMReX_StateDescriptor.cpp:265
bool identicalInterps(int scomp, int ncomp) const noexcept
Return true if all components in [scomp, scomp+ncomp) share the same interpolater.
Definition AMReX_StateDescriptor.cpp:401
const BCRec & getBC(int i) const noexcept
Returns the BCRec of component i.
Definition AMReX_StateDescriptor.cpp:271
bool primary(int i) const noexcept
Return whether component i is the primary entry of a grouped set.
Definition AMReX_StateDescriptor.H:354
StateDescriptor::TimeCenter timeType() const noexcept
Returns StateDescriptor::TimeCenter.
Definition AMReX_StateDescriptor.cpp:235
void setComponent(int comp, const std::string &nm, const BCRec &bc, const BndryFunc &func, InterpBase *interp=nullptr, int max_map_start_comp=-1, int min_map_end_comp=-1)
Configure metadata for component comp.
Definition AMReX_StateDescriptor.cpp:339
int inRange(int sc, int nc) const noexcept
Return true if the component range [sc, sc+nc) lies within this descriptor.
Definition AMReX_StateDescriptor.cpp:302
bool RunOnGPU() const noexcept
will it run on gpu?
Definition AMReX_StateDescriptor.H:363
void resetComponentBCs(int comp, const BCRec &bcr, const BndryFunc &func)
Resets boundary condition data for component comp.
Definition AMReX_StateDescriptor.cpp:218
static void setBndryFuncThreadSafety(int ext_dir_safe) noexcept
Control thread-safety flag for boundary fill functors (nonzero ext_dir_safe triggers thread-safe hand...
Definition AMReX_StateDescriptor.H:371
bool store_in_checkpoint() const noexcept
Should store this StateData in the checkpoint file.
Definition AMReX_StateDescriptor.cpp:289
bool extrap() const noexcept
Can extrapolate in time.
Definition AMReX_StateDescriptor.cpp:283
int nComp() const noexcept
Returns number of components.
Definition AMReX_StateDescriptor.cpp:241
void define(IndexType btyp, TimeCenter ttyp, int ident, int nextra, int num_comp, InterpBase *interp, bool extrap=false, bool store_in_checkpoint=true)
Define the data members if constructed with default constructor.
Definition AMReX_StateDescriptor.cpp:308
int groupsize(int i) const noexcept
Return the size of the component group anchored at primary component i.
Definition AMReX_StateDescriptor.H:357
std::vector< std::pair< int, int > > sameInterps(int scomp, int ncomp) const
Returns contiguous component ranges (start,count) that share identical interpolaters within [scomp,...
Definition AMReX_StateDescriptor.cpp:419
TimeCenter
Defines the temporal centeredness of data.
Definition AMReX_StateDescriptor.H:39
@ Interval
Definition AMReX_StateDescriptor.H:39
@ Point
Definition AMReX_StateDescriptor.H:39
const Vector< BCRec > & getBCs() const noexcept
Returns all BCRecs.
Definition AMReX_StateDescriptor.cpp:277
bool hasBndryFuncFab() const noexcept
has new fab version of BndryFunc?
Definition AMReX_StateDescriptor.H:368
IndexType getType() const noexcept
Returns the IndexType.
Definition AMReX_StateDescriptor.cpp:229
StateDescriptor() noexcept
The default constructor.
Definition AMReX_StateDescriptor.H:163
int nExtra() const noexcept
Returns the grow factor.
Definition AMReX_StateDescriptor.cpp:247
const BndryFunc & bndryFill(int i) const noexcept
Returns the BndryFunc associated with component i.
Definition AMReX_StateDescriptor.cpp:296
void dumpNames(std::ostream &os, int start_comp, int num_comp) const
Output names of components.
Definition AMReX_StateDescriptor.cpp:388
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(*)(Real *data, const int &, const int &, const int &, const int &, const int &, const int &, const int *dom_lo, const int *dom_hi, const Real *dx, const Real *grd_lo, const Real *time, const int *bc) BndryFuncDefault
Definition AMReX_PhysBCFunct.H:21
std::function< void(Box const &bx, FArrayBox &data, int dcomp, int numcomp, Geometry const &geom, Real time, const Vector< BCRec > &bcr, int bcomp, int scomp)> BndryFuncFabDefault
Definition AMReX_StateDescriptor.H:27
void(*)(Real *data, const int *lo, const int *hi, const int *dom_lo, const int *dom_hi, const Real *dx, const Real *grd_lo, const Real *time, const int *bc) BndryFunc3DDefault
Definition AMReX_PhysBCFunct.H:25