Block-Structured AMR Software Framework
AMReX_EB2.H
Go to the documentation of this file.
1 #ifndef AMREX_EB2_H_
2 #define AMREX_EB2_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Geometry.H>
6 #include <AMReX_Vector.H>
8 #include <AMReX_EB2_Level.H>
9 
10 #include <cmath>
11 #include <algorithm>
12 #include <memory>
13 #include <type_traits>
14 #include <string>
15 
16 namespace amrex::EB2 {
17 
18 extern AMREX_EXPORT int max_grid_size;
19 
20 void useEB2 (bool);
21 
22 void Initialize ();
23 void Finalize ();
24 
26 {
27 public:
28  virtual ~IndexSpace() = default;
29 
30  IndexSpace () noexcept = default;
31  IndexSpace (IndexSpace const&) = delete;
32  IndexSpace (IndexSpace &&) = delete;
33  IndexSpace& operator= (IndexSpace const&) = delete;
34  IndexSpace& operator= (IndexSpace &&) = delete;
35 
36  // This function will take the ownership of the IndexSpace
37  // pointer, and put it on the top of the stack (i.e., back of the
38  // vector). If the pointer is already in the stack, it will be
39  // moved to the top.
40  static void push (IndexSpace* ispace);
41 
42  // This erases `ispace` from the stack.
43  static void erase (IndexSpace* ispace);
44 
45  static void pop () noexcept { m_instance.pop_back(); }
46  static void clear () noexcept { m_instance.clear(); }
47  static const IndexSpace& top () {
49  "Have you forgot to call EB2::build? It's required even if the geometry is all regular.");
50  return *(m_instance.back());
51  }
52  static bool empty () noexcept { return m_instance.empty(); }
53  static int size () noexcept { return static_cast<int>(m_instance.size()); }
54 
55  [[nodiscard]] virtual const Level& getLevel (const Geometry & geom) const = 0;
56  [[nodiscard]] virtual const Geometry& getGeometry (const Box& domain) const = 0;
57  [[nodiscard]] virtual const Box& coarsestDomain () const = 0;
58  virtual void addFineLevels (int num_new_fine_levels) = 0;
59  virtual void addRegularCoarseLevels (int num_new_coarse_levels) = 0;
60 
61 protected:
63 };
64 
65 const IndexSpace* TopIndexSpaceIfPresent () noexcept;
66 inline const IndexSpace* TopIndexSpace () noexcept { return TopIndexSpaceIfPresent(); }
67 
68 template <typename G>
70  : public IndexSpace
71 {
72 public:
73 
74  IndexSpaceImp (const G& gshop, const Geometry& geom,
75  int required_coarsening_level, int max_coarsening_level,
76  int ngrow, bool build_coarse_level_by_coarsening,
78 
79  IndexSpaceImp (IndexSpaceImp<G> const&) = delete;
81  void operator= (IndexSpaceImp<G> const&) = delete;
82  void operator= (IndexSpaceImp<G> &&) = delete;
83 
84  ~IndexSpaceImp () override = default;
85 
86  [[nodiscard]] const Level& getLevel (const Geometry& geom) const final;
87  [[nodiscard]] const Geometry& getGeometry (const Box& dom) const final;
88  [[nodiscard]] const Box& coarsestDomain () const final {
89  return m_geom.back().Domain();
90  }
91  void addFineLevels (int num_new_fine_levels) final;
92  void addRegularCoarseLevels (int num_new_coarse_levels) final;
93 
94  using F = typename G::FunctionType;
95 
96 private:
97 
102 
107 };
108 
109 #include <AMReX_EB2_IndexSpaceI.H>
110 
111 bool ExtendDomainFace ();
112 int NumCoarsenOpt ();
113 
114 template <typename G>
115 void
116 Build (const G& gshop, const Geometry& geom,
117  int required_coarsening_level, int max_coarsening_level,
118  int ngrow = 4, bool build_coarse_level_by_coarsening = true,
121 {
122  BL_PROFILE("EB2::Initialize()");
123  IndexSpace::push(new IndexSpaceImp<G>(gshop, geom,
124  required_coarsening_level,
125  max_coarsening_level,
126  ngrow, build_coarse_level_by_coarsening,
128  num_coarsen_opt));
129 } // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
130 
131 void Build (const Geometry& geom,
132  int required_coarsening_level,
133  int max_coarsening_level,
134  int ngrow = 4,
135  bool build_coarse_level_by_coarsening = true,
138 
139 void BuildFromChkptFile (std::string const& fname,
140  const Geometry& geom,
141  int required_coarsening_level,
142  int max_coarsening_level,
143  int ngrow = 4,
144  bool build_coarse_level_by_coarsening = true,
146 
147 int maxCoarseningLevel (const Geometry& geom);
148 int maxCoarseningLevel (IndexSpace const* ebis, const Geometry& geom);
149 
150 void addFineLevels (int num_new_fine_levels);
151 
152 void addRegularCoarseLevels (int num_new_coarse_levels);
153 
154 }
155 
156 #endif
#define BL_PROFILE(a)
Definition: AMReX_BLProfiler.H:551
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition: AMReX_BLassert.H:49
#define AMREX_EXPORT
Definition: AMReX_Extension.H:191
Definition: AMReX_EB2.H:71
typename G::FunctionType F
Definition: AMReX_EB2.H:94
const Level & getLevel(const Geometry &geom) const final
Definition: AMReX_EB2_IndexSpaceI.H:68
Vector< GShopLevel< G > > m_gslevel
Definition: AMReX_EB2.H:103
Vector< int > m_ngrow
Definition: AMReX_EB2.H:106
int m_num_coarsen_opt
Definition: AMReX_EB2.H:101
~IndexSpaceImp() override=default
void addFineLevels(int num_new_fine_levels) final
Definition: AMReX_EB2_IndexSpaceI.H:86
IndexSpaceImp(IndexSpaceImp< G > const &)=delete
Vector< Geometry > m_geom
Definition: AMReX_EB2.H:104
void addRegularCoarseLevels(int num_new_coarse_levels) final
Definition: AMReX_EB2_IndexSpaceI.H:112
G m_gshop
Definition: AMReX_EB2.H:98
Vector< Box > m_domain
Definition: AMReX_EB2.H:105
const Box & coarsestDomain() const final
Definition: AMReX_EB2.H:88
bool m_extend_domain_face
Definition: AMReX_EB2.H:100
const Geometry & getGeometry(const Box &dom) const final
Definition: AMReX_EB2_IndexSpaceI.H:77
IndexSpaceImp(IndexSpaceImp< G > &&)=delete
bool m_build_coarse_level_by_coarsening
Definition: AMReX_EB2.H:99
void operator=(IndexSpaceImp< G > const &)=delete
IndexSpaceImp(const G &gshop, const Geometry &geom, int required_coarsening_level, int max_coarsening_level, int ngrow, bool build_coarse_level_by_coarsening, bool extend_domain_face, int num_coarsen_opt)
Definition: AMReX_EB2_IndexSpaceI.H:3
Definition: AMReX_EB2.H:26
IndexSpace() noexcept=default
virtual void addFineLevels(int num_new_fine_levels)=0
static void pop() noexcept
Definition: AMReX_EB2.H:45
static void push(IndexSpace *ispace)
Definition: AMReX_EB2.cpp:53
virtual const Geometry & getGeometry(const Box &domain) const =0
virtual const Level & getLevel(const Geometry &geom) const =0
virtual const Box & coarsestDomain() const =0
static bool empty() noexcept
Definition: AMReX_EB2.H:52
virtual void addRegularCoarseLevels(int num_new_coarse_levels)=0
static AMREX_EXPORT Vector< std::unique_ptr< IndexSpace > > m_instance
Definition: AMReX_EB2.H:62
static int size() noexcept
Definition: AMReX_EB2.H:53
virtual ~IndexSpace()=default
static void clear() noexcept
Definition: AMReX_EB2.H:46
static const IndexSpace & top()
Definition: AMReX_EB2.H:47
static void erase(IndexSpace *ispace)
Definition: AMReX_EB2.cpp:66
Definition: AMReX_EB2_Level.H:33
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
Definition: AMReX_FabArrayBase.H:32
int NumCoarsenOpt()
Definition: AMReX_EB2.cpp:47
void Build(const Geometry &geom, int required_coarsening_level, int max_coarsening_level, int ngrow, bool build_coarse_level_by_coarsening, bool a_extend_domain_face, int a_num_coarsen_opt)
Definition: AMReX_EB2.cpp:84
void addRegularCoarseLevels(int num_new_coarse_levels)
Definition: AMReX_EB2.cpp:246
AMREX_EXPORT int max_grid_size
Definition: AMReX_EB2.cpp:23
bool ExtendDomainFace()
Definition: AMReX_EB2.cpp:42
int maxCoarseningLevel(const Geometry &geom)
Definition: AMReX_EB2.cpp:282
const IndexSpace * TopIndexSpace() noexcept
Definition: AMReX_EB2.H:66
void Initialize()
Definition: AMReX_EB2.cpp:27
void addFineLevels(int num_new_fine_levels)
Definition: AMReX_EB2.cpp:237
AMREX_EXPORT bool extend_domain_face
Definition: AMReX_EB2.cpp:24
AMREX_EXPORT int num_coarsen_opt
Definition: AMReX_EB2.cpp:25
const IndexSpace * TopIndexSpaceIfPresent() noexcept
Definition: AMReX_EB2.cpp:76
void useEB2(bool)
void BuildFromChkptFile(std::string const &fname, const Geometry &geom, int required_coarsening_level, int max_coarsening_level, int ngrow, bool build_coarse_level_by_coarsening, bool a_extend_domain_face)
Definition: AMReX_EB2.cpp:255
void Finalize()
Definition: AMReX_EB2.cpp:37