Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
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
16namespace amrex::EB2 {
17
19extern AMREX_EXPORT int max_grid_size;
21
23void Initialize ();
25void Finalize ();
26
28{
29public:
30 virtual ~IndexSpace() = default;
31
32 IndexSpace () noexcept = default;
33 IndexSpace (IndexSpace const&) = delete;
34 IndexSpace (IndexSpace &&) = delete;
35 IndexSpace& operator= (IndexSpace const&) = delete;
36 IndexSpace& operator= (IndexSpace &&) = delete;
37
38 // This function will take the ownership of the IndexSpace
39 // pointer, and put it on the top of the stack (i.e., back of the
40 // vector). If the pointer is already in the stack, it will be
41 // moved to the top.
42 static void push (IndexSpace* ispace);
43
44 static void push (std::unique_ptr<IndexSpace> ispace);
45
46 // This erases `ispace` from the stack.
47 static void erase (IndexSpace* ispace);
48
49 static void pop () noexcept { m_instance.pop_back(); }
50 static void clear () noexcept { m_instance.clear(); }
51 static IndexSpace& top () {
53 "Have you forgot to call EB2::build? It's required even if the geometry is all regular.");
54 return *(m_instance.back());
55 }
56 static bool empty () noexcept { return m_instance.empty(); }
57 static int size () noexcept { return static_cast<int>(m_instance.size()); }
58
59 [[nodiscard]] virtual const Level& getLevel (const Geometry & geom) const = 0;
60 [[nodiscard]] virtual const Geometry& getGeometry (const Box& domain) const = 0;
61 [[nodiscard]] virtual const Box& coarsestDomain () const = 0;
62 virtual void addFineLevels (int num_new_fine_levels) = 0;
63 virtual void addRegularCoarseLevels (int num_new_coarse_levels) = 0;
64
65 virtual void setShift (int, int) {
66 amrex::Abort("IndexSpace::setShift: not supported");
67 }
68
69protected:
71};
72
74const IndexSpace* TopIndexSpaceIfPresent () noexcept;
76inline const IndexSpace* TopIndexSpace () noexcept { return TopIndexSpaceIfPresent(); }
77
78template <typename G>
80 : public IndexSpace
81{
82public:
83
84 IndexSpaceImp (const G& gshop, const Geometry& geom,
85 int required_coarsening_level, int max_coarsening_level,
86 int ngrow, bool build_coarse_level_by_coarsening,
87 bool extend_domain_face, int num_coarsen_opt);
88
89 IndexSpaceImp (const G& gshop, const Vector<Geometry>& geom,
90 int ngrow,
91 bool extend_domain_face, int num_coarsen_opt);
92
95 void operator= (IndexSpaceImp<G> const&) = delete;
96 void operator= (IndexSpaceImp<G> &&) = delete;
97
98 ~IndexSpaceImp () override = default;
99
100 [[nodiscard]] const Level& getLevel (const Geometry& geom) const final;
101 [[nodiscard]] const Geometry& getGeometry (const Box& dom) const final;
102 [[nodiscard]] const Box& coarsestDomain () const final {
103 return m_geom.back().Domain();
104 }
105 void addFineLevels (int num_new_fine_levels) final;
106 void addRegularCoarseLevels (int num_new_coarse_levels) final;
107
108 void setShift (int direction, int ncells) override;
109
110 using F = typename G::FunctionType;
111
112private:
113
114 G m_gshop;
115 bool m_build_coarse_level_by_coarsening;
116 bool m_extend_domain_face;
117 int m_num_coarsen_opt;
118
119 Vector<GShopLevel<G> > m_gslevel;
120 Vector<Geometry> m_geom;
121 Vector<Box> m_domain;
122 Vector<int> m_ngrow;
123};
124
126
132bool ExtendDomainFace ();
133
142int NumCoarsenOpt ();
143
160template <typename G>
161void
162Build (const G& gshop, const Geometry& geom,
163 int required_coarsening_level, int max_coarsening_level,
164 int ngrow = 4, bool build_coarse_level_by_coarsening = true,
165 bool extend_domain_face = ExtendDomainFace(),
166 int num_coarsen_opt = NumCoarsenOpt())
167{
168 BL_PROFILE("EB2::Initialize()");
169 IndexSpace::push(std::make_unique<IndexSpaceImp<G>>
170 (gshop, geom, required_coarsening_level, max_coarsening_level,
171 ngrow, build_coarse_level_by_coarsening,extend_domain_face,
172 num_coarsen_opt));
173}
174
186template <typename G>
187void
188Build (const G& gshop, Vector<Geometry> geom,
189 int ngrow = 4,
190 bool extend_domain_face = ExtendDomainFace(),
191 int num_coarsen_opt = NumCoarsenOpt())
192{
193 BL_PROFILE("EB2::Initialize()");
194 std::sort(geom.begin(), geom.end(), [] (Geometry const& a, Geometry const& b) { return a.Domain().numPts() > b.Domain().numPts(); });
195 IndexSpace::push(std::make_unique<IndexSpaceImp<G>>
196 (gshop, geom, ngrow, extend_domain_face, num_coarsen_opt));
197}
198
220void Build (const Geometry& geom,
221 int required_coarsening_level,
222 int max_coarsening_level,
223 int ngrow = 4,
224 bool build_coarse_level_by_coarsening = true,
225 bool extend_domain_face = ExtendDomainFace(),
226 int num_coarsen_opt = NumCoarsenOpt(),
227 bool support_mvmc = false);
228
235void BuildMultiValuedMultiCut (const Geometry& geom,
236 int required_coarsening_level,
237 int max_coarsening_level,
238 int ngrow = 4,
239 bool build_coarse_level_by_coarsening = true,
240 bool extend_domain_face = ExtendDomainFace(),
241 int num_coarsen_opt = NumCoarsenOpt());
242
255void BuildFromChkptFile (std::string const& fname,
256 const Geometry& geom,
257 int required_coarsening_level,
258 int max_coarsening_level,
259 int ngrow = 4,
260 bool build_coarse_level_by_coarsening = true,
261 bool extend_domain_face = ExtendDomainFace());
262
264int maxCoarseningLevel (const Geometry& geom);
266int maxCoarseningLevel (IndexSpace const* ebis, const Geometry& geom);
267
269void addFineLevels (int num_new_fine_levels);
270
272void addRegularCoarseLevels (int num_new_coarse_levels);
273
274}
275
276#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:81
typename G::FunctionType F
Definition AMReX_EB2.H:110
const Box & coarsestDomain() const final
Definition AMReX_EB2.H:102
const Level & getLevel(const Geometry &geom) const final
Definition AMReX_EB2_IndexSpaceI.H:101
~IndexSpaceImp() override=default
void addFineLevels(int num_new_fine_levels) final
Definition AMReX_EB2_IndexSpaceI.H:123
IndexSpaceImp(IndexSpaceImp< G > const &)=delete
void addRegularCoarseLevels(int num_new_coarse_levels) final
Definition AMReX_EB2_IndexSpaceI.H:152
const Geometry & getGeometry(const Box &dom) const final
Definition AMReX_EB2_IndexSpaceI.H:112
IndexSpaceImp(IndexSpaceImp< G > &&)=delete
void operator=(IndexSpaceImp< G > const &)=delete
void setShift(int direction, int ncells) override
Definition AMReX_EB2_IndexSpaceI.H:200
Definition AMReX_EB2.H:28
virtual const Geometry & getGeometry(const Box &domain) const =0
virtual const Level & getLevel(const Geometry &geom) const =0
IndexSpace() noexcept=default
virtual void addFineLevels(int num_new_fine_levels)=0
static void pop() noexcept
Definition AMReX_EB2.H:49
static void push(IndexSpace *ispace)
Definition AMReX_EB2.cpp:64
static bool empty() noexcept
Definition AMReX_EB2.H:56
virtual void addRegularCoarseLevels(int num_new_coarse_levels)=0
static Vector< std::unique_ptr< IndexSpace > > m_instance
Definition AMReX_EB2.H:70
static int size() noexcept
Definition AMReX_EB2.H:57
virtual ~IndexSpace()=default
virtual const Box & coarsestDomain() const =0
static void clear() noexcept
Definition AMReX_EB2.H:50
virtual void setShift(int, int)
Definition AMReX_EB2.H:65
static IndexSpace & top()
Definition AMReX_EB2.H:51
static void erase(IndexSpace *ispace)
Definition AMReX_EB2.cpp:83
Definition AMReX_EB2_Level.H:42
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
Definition AMReX_FabArrayBase.H:33
int NumCoarsenOpt()
Definition AMReX_EB2.cpp:58
void addRegularCoarseLevels(int num_new_coarse_levels)
Add num_new_coarse_levels regular levels below the current coarsest level.
Definition AMReX_EB2.cpp:264
bool ExtendDomainFace()
Definition AMReX_EB2.cpp:53
int maxCoarseningLevel(const Geometry &geom)
Return the maximum coarsening level supported for given geom.
Definition AMReX_EB2.cpp:298
void Initialize()
Initialize EB2’s global state (call before constructing geometries by amrex::Initialize).
Definition AMReX_EB2.cpp:35
void BuildMultiValuedMultiCut(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)
Build EB geometry dedicated to multi-valued multi-cut support.
Definition AMReX_EB2.cpp:314
void addFineLevels(int num_new_fine_levels)
Add num_new_fine_levels to the EB hierarchy.
Definition AMReX_EB2.cpp:255
const IndexSpace * TopIndexSpace() noexcept
Return the top IndexSpace if one has been built (nullptr otherwise).
Definition AMReX_EB2.H:76
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, bool support_mvmc)
Build EB geometry using the runtime-configured EB2 geometry type.
Definition AMReX_EB2.cpp:101
const IndexSpace * TopIndexSpaceIfPresent() noexcept
Return the top IndexSpace if one has been built (nullptr otherwise).
Definition AMReX_EB2.cpp:93
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)
Rebuild an IndexSpace from a checkpoint file.
Definition AMReX_EB2.cpp:273
void Finalize()
Tear down EB2 global resources (called automatically at shutdown).
Definition AMReX_EB2.cpp:45
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:240