Block-Structured AMR Software Framework
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>
12 #include <AMReX_MFInterpolater.H>
13 #ifdef AMREX_USE_EB
14 #include <AMReX_EBInterpolater.H>
15 #include <AMReX_EBMFInterpolater.H>
16 #endif
17 
18 #include <utility>
19 #include <memory>
20 
21 namespace 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 
36 public:
37 
39  enum TimeCenter { Point = 0 , Interval };
40 
46  class BndryFunc
47  {
48  public:
49 
53  BndryFunc () noexcept = default;
54 
58  BndryFunc (BndryFuncDefault inFunc) noexcept : m_func(inFunc) {}
59 
60  BndryFunc (BndryFunc3DDefault inFunc) noexcept : m_func3D(inFunc) {}
61 
62  BndryFunc (BndryFuncFabDefault inFunc) noexcept : m_funcfab(std::move(inFunc)) {}
63 
71  : m_func(inFunc), m_gfunc(gFunc) {}
72 
74  : m_func3D(inFunc), m_gfunc3D(gFunc) {}
75 
89  void operator () (Real* data, const int* lo, const int* hi,
90  const int* dom_lo, const int* dom_hi,
91  const Real* dx, const Real* grd_lo,
92  const Real* time, const int* bc) const;
93 
108  void operator () (Real* data, const int* lo, const int* hi,
109  const int* dom_lo, const int* dom_hi,
110  const Real* dx, const Real* grd_lo,
111  const Real* time, const int* bc, int ng) const;
112 
113  void operator () (Box const& bx, FArrayBox& data,
114  int dcomp, int numcomp,
115  Geometry const& geom, Real time,
116  const Vector<BCRec>& bcr, int bcomp,
117  int scomp) const;
118 
119  [[nodiscard]] bool RunOnGPU () const noexcept { return m_run_on_gpu; }
120 
121  void setRunOnGPU (bool b) noexcept { m_run_on_gpu = b; }
122 
123  [[nodiscard]] bool hasFabVersion () const noexcept { return m_funcfab != nullptr; }
124 
125  private:
126 
132  bool m_run_on_gpu = false;
133  };
134 
138  StateDescriptor () noexcept {} // NOLINT /* = default does not work with old clang */
139 
153  TimeCenter ttyp,
154  int ident,
155  int nextra,
156  int num_comp,
158  bool extrap = false,
159  bool store_in_checkpoint = true);
160 
173  void define (IndexType btyp,
174  TimeCenter ttyp,
175  int ident,
176  int nextra,
177  int num_comp,
179  bool extrap = false,
180  bool store_in_checkpoint = true);
181 
193  void setComponent (int comp,
194  const std::string& nm,
195  const BCRec& bc,
196  const BndryFunc& func,
197  InterpBase* interp = nullptr,
198  int max_map_start_comp = -1,
199  int min_map_end_comp = -1);
200 
212  void setComponent (int comp,
213  const std::string& nm,
214  const BCRec& bc,
215  const BndryFunc& func,
217  bool a_primary,
218  int groupsize);
219 
227  void resetComponentBCs (int comp,
228  const BCRec& bcr,
229  const BndryFunc& func);
230 
245  void setUpMaps (int& use_default_map,
246  const InterpBase* default_map,
247  int start_comp,
248  int num_comp,
249  InterpBase**& maps,
250  int& nmaps,
251  int*& map_start_comp,
252  int*& map_num_comp,
253  int*& max_start_comp,
254  int*& min_end_comp) const;
255 
265  static void cleanUpMaps (InterpBase**& maps,
266  int*& map_start_comp,
267  int*& map_num_comp,
268  int*& max_start_comp,
269  int*& min_end_comp) ;
270 
278  void dumpNames (std::ostream& os,
279  int start_comp,
280  int num_comp) const;
281 
285  [[nodiscard]] IndexType getType () const noexcept;
286 
290  [[nodiscard]] StateDescriptor::TimeCenter timeType () const noexcept;
291 
295  [[nodiscard]] int nComp () const noexcept;
296 
300  [[nodiscard]] int nExtra () const noexcept;
301 
305  [[nodiscard]] InterpBase* interp () const noexcept;
306 
312  [[nodiscard]] InterpBase* interp (int i) const noexcept;
313 
319  [[nodiscard]] const std::string& name (int i) const noexcept;
320 
326  [[nodiscard]] const BCRec& getBC (int i) const noexcept;
327 
331  [[nodiscard]] const Vector<BCRec>& getBCs () const noexcept;
332 
338  [[nodiscard]] const BndryFunc& bndryFill (int i) const noexcept;
339 
346  [[nodiscard]] int inRange (int sc, int nc) const noexcept;
347 
354  [[nodiscard]] bool identicalInterps (int scomp, int ncomp) const noexcept;
355  //
356  // Returns contiguous ranges of comps with identical interpolaters.
357  //
358  [[nodiscard]] std::vector< std::pair<int,int> > sameInterps (int scomp, int ncomp) const;
359 
363  [[nodiscard]] bool extrap () const noexcept;
364 
368  [[nodiscard]] bool store_in_checkpoint () const noexcept;
369 
370  [[nodiscard]] bool primary (int i) const noexcept { return m_primary[i]; }
371 
372  [[nodiscard]] int groupsize (int i) const noexcept { return m_groupsize[i]; }
373 
374 
378  [[nodiscard]] bool RunOnGPU () const noexcept { return bc_func[0]->RunOnGPU(); }
379 
383  [[nodiscard]] bool hasBndryFuncFab () const noexcept { return bc_func[0]->hasFabVersion(); }
384 
385  static void setBndryFuncThreadSafety (int ext_dir_safe) noexcept {
386  bf_ext_dir_threadsafe = ext_dir_safe;
387  }
388 
389 private:
390 
393  int id{-1};
394  int ncomp{0};
395  int ngrow{0};
396  InterpBase* mapper{nullptr};
397  bool m_extrap{false};
404 
410 
423 
425 
426  static bool bf_thread_safety (const int* lo,const int* hi,
427  const int* dom_lo, const int* dom_hi,
428  const int* bc, int ng);
429 };
430 
437 {
438 public:
439 
443  void clear ();
444 
448  [[nodiscard]] int size () const noexcept;
449 
462  void addDescriptor (int indx,
463  IndexType typ,
465  int nextra,
466  int num_comp,
467  InterpBase* interp,
468  bool extrap = false,
469  bool store_in_checkpoint = true);
470 
479  void resetComponentBCs (int indx,
480  int comp,
481  const BCRec& bc,
482  const StateDescriptor::BndryFunc& func);
483 
496  void setComponent (int indx,
497  int comp,
498  const std::string& nm,
499  const BCRec& bc,
500  const StateDescriptor::BndryFunc& func,
501  InterpBase* interp = nullptr,
502  int max_map_start_comp = -1,
503  int min_map_end_comp = -1);
504 
515  void setComponent (int indx,
516  int comp,
517  const Vector<std::string>& nm,
518  const Vector<BCRec>& bc,
519  const StateDescriptor::BndryFunc& func,
520  InterpBase* interp = nullptr);
524  const StateDescriptor& operator[] (int k) const noexcept;
525 
526 private:
527 
529 };
530 
531 }
532 
533 #endif /*_StateDescriptor_H_*/
Boundary Condition Records. Necessary information and functions for computing boundary conditions.
Definition: AMReX_BCRec.H:17
Definition: AMReX_StateDescriptor.H:437
const StateDescriptor & operator[](int k) const noexcept
Definition: AMReX_StateDescriptor.cpp:163
void clear()
Set the list to its default state.
Definition: AMReX_StateDescriptor.cpp:112
void resetComponentBCs(int indx, int comp, const BCRec &bc, const StateDescriptor::BndryFunc &func)
Calls resetComponentBCs() on StateDescriptor at index 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)
Calls setComponent() on StateDescriptor at index indx.
Definition: AMReX_StateDescriptor.cpp:133
int size() const noexcept
Returns number of elements in the list.
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 new StateDescriptor at index indx to list.
Definition: AMReX_StateDescriptor.cpp:169
Vector< std::unique_ptr< StateDescriptor > > desc
Definition: AMReX_StateDescriptor.H:528
A Fortran Array of REALs.
Definition: AMReX_FArrayBox.H:229
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
Definition: AMReX_InterpBase.H:26
Definition: AMReX_StateDescriptor.H:47
BndryFuncDefault m_gfunc
Definition: AMReX_StateDescriptor.H:129
BndryFunc() noexcept=default
Bogus constructor.
bool m_run_on_gpu
Definition: AMReX_StateDescriptor.H:132
BndryFunc(BndryFuncFabDefault inFunc) noexcept
Definition: AMReX_StateDescriptor.H:62
BndryFunc(BndryFunc3DDefault inFunc, BndryFunc3DDefault gFunc) noexcept
Definition: AMReX_StateDescriptor.H:73
bool RunOnGPU() const noexcept
Definition: AMReX_StateDescriptor.H:119
BndryFunc3DDefault m_gfunc3D
Definition: AMReX_StateDescriptor.H:130
void setRunOnGPU(bool b) noexcept
Definition: AMReX_StateDescriptor.H:121
BndryFunc(BndryFunc3DDefault inFunc) noexcept
Definition: AMReX_StateDescriptor.H:60
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
Definition: AMReX_StateDescriptor.cpp:30
BndryFuncFabDefault m_funcfab
Definition: AMReX_StateDescriptor.H:131
bool hasFabVersion() const noexcept
Definition: AMReX_StateDescriptor.H:123
BndryFuncDefault m_func
Definition: AMReX_StateDescriptor.H:127
BndryFunc(BndryFuncDefault inFunc, BndryFuncDefault gFunc) noexcept
Another Constructor.
Definition: AMReX_StateDescriptor.H:70
BndryFunc3DDefault m_func3D
Definition: AMReX_StateDescriptor.H:128
Attributes of StateData.
Definition: AMReX_StateDescriptor.H:33
Vector< BCRec > bc
Array of bndry types for entire level.
Definition: AMReX_StateDescriptor.H:400
InterpBase * interp() const noexcept
Returns the interpolater.
Definition: AMReX_StateDescriptor.cpp:251
InterpBase * mapper
Default interpolator.
Definition: AMReX_StateDescriptor.H:396
Vector< InterpBase * > mapper_comp
If mapper_comp[icomp] != 0, that map is used instead of mapper when interpolating icomp; otherwise,...
Definition: AMReX_StateDescriptor.H:409
Vector< std::string > names
Printable names of components.
Definition: AMReX_StateDescriptor.H:399
const std::string & name(int i) const noexcept
Returns the name of specified component.
Definition: AMReX_StateDescriptor.cpp:263
bool identicalInterps(int scomp, int ncomp) const noexcept
Are the interpolaters in the specified range identical?
Definition: AMReX_StateDescriptor.cpp:517
const BCRec & getBC(int i) const noexcept
Returns the BCRec of specified component.
Definition: AMReX_StateDescriptor.cpp:269
bool primary(int i) const noexcept
Definition: AMReX_StateDescriptor.H:370
StateDescriptor::TimeCenter timeType() const noexcept
Returns StateDescriptor::TimeCenter.
Definition: AMReX_StateDescriptor.cpp:233
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)
Sets details of comp component.
Definition: AMReX_StateDescriptor.cpp:337
int inRange(int sc, int nc) const noexcept
Is sc>=0 && sc+nc<=ncomp ?
Definition: AMReX_StateDescriptor.cpp:300
bool m_extrap
Can extrapolate in time?
Definition: AMReX_StateDescriptor.H:397
Vector< std::unique_ptr< BndryFunc > > bc_func
Array of pointers to bndry fill functions.
Definition: AMReX_StateDescriptor.H:401
bool RunOnGPU() const noexcept
will it run on gpu?
Definition: AMReX_StateDescriptor.H:378
Vector< int > m_groupsize
Groupsize if we're a primary.
Definition: AMReX_StateDescriptor.H:403
void resetComponentBCs(int comp, const BCRec &bcr, const BndryFunc &func)
Resets boundary condition data for comp component.
Definition: AMReX_StateDescriptor.cpp:216
static void setBndryFuncThreadSafety(int ext_dir_safe) noexcept
Definition: AMReX_StateDescriptor.H:385
bool store_in_checkpoint() const noexcept
Should store this StateData in the checkpoint file.
Definition: AMReX_StateDescriptor.cpp:287
TimeCenter t_type
Temporal centering.
Definition: AMReX_StateDescriptor.H:392
Vector< int > m_primary
Are we a primary or secondary? (true or false)
Definition: AMReX_StateDescriptor.H:402
bool extrap() const noexcept
Can extrapolate in time.
Definition: AMReX_StateDescriptor.cpp:281
int nComp() const noexcept
Returns number of components.
Definition: AMReX_StateDescriptor.cpp:239
bool m_store_in_checkpoint
Should store this in the checkpoint file?
Definition: AMReX_StateDescriptor.H:398
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:306
int groupsize(int i) const noexcept
Definition: AMReX_StateDescriptor.H:372
std::vector< std::pair< int, int > > sameInterps(int scomp, int ncomp) const
Definition: AMReX_StateDescriptor.cpp:535
Vector< int > max_map_start_comp
For component icomp, max_map_start_comp[icomp] and min_map_end_comp[icomp] represent the maximum star...
Definition: AMReX_StateDescriptor.H:421
TimeCenter
Defines the temporal centeredness of data.
Definition: AMReX_StateDescriptor.H:39
@ Interval
Definition: AMReX_StateDescriptor.H:39
@ Point
Definition: AMReX_StateDescriptor.H:39
void setUpMaps(int &use_default_map, const InterpBase *default_map, int start_comp, int num_comp, InterpBase **&maps, int &nmaps, int *&map_start_comp, int *&map_num_comp, int *&max_start_comp, int *&min_end_comp) const
Set interpolaters for a subset of the state vector components.
Definition: AMReX_StateDescriptor.cpp:398
Vector< int > min_map_end_comp
Definition: AMReX_StateDescriptor.H:422
int ncomp
Number of components.
Definition: AMReX_StateDescriptor.H:394
const Vector< BCRec > & getBCs() const noexcept
Returns all BCRecs.
Definition: AMReX_StateDescriptor.cpp:275
static bool bf_thread_safety(const int *lo, const int *hi, const int *dom_lo, const int *dom_hi, const int *bc, int ng)
Definition: AMReX_StateDescriptor.cpp:14
bool hasBndryFuncFab() const noexcept
has new fab version of BndryFunc?
Definition: AMReX_StateDescriptor.H:383
IndexType getType() const noexcept
Returns the IndexType.
Definition: AMReX_StateDescriptor.cpp:227
IndexType type
Cell centered, node centered ...
Definition: AMReX_StateDescriptor.H:391
StateDescriptor() noexcept
The default constructor.
Definition: AMReX_StateDescriptor.H:138
int ngrow
Grow factor.
Definition: AMReX_StateDescriptor.H:395
int nExtra() const noexcept
Returns the grow factor.
Definition: AMReX_StateDescriptor.cpp:245
const BndryFunc & bndryFill(int i) const noexcept
Returns the BndryFunc of specified component.
Definition: AMReX_StateDescriptor.cpp:294
static int bf_ext_dir_threadsafe
Definition: AMReX_StateDescriptor.H:424
static void cleanUpMaps(InterpBase **&maps, int *&map_start_comp, int *&map_num_comp, int *&max_start_comp, int *&min_end_comp)
Cleanup interpolaters for a subset of the state vector components.
Definition: AMReX_StateDescriptor.cpp:503
void dumpNames(std::ostream &os, int start_comp, int num_comp) const
Output names of components.
Definition: AMReX_StateDescriptor.cpp:385
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
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
void(*)(Real *data, AMREX_ARLIM_P(lo), AMREX_ARLIM_P(hi), 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