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
70 virtual void buildAllFCData () {}
71
72protected:
74};
75
77const IndexSpace* TopIndexSpaceIfPresent () noexcept;
79inline const IndexSpace* TopIndexSpace () noexcept { return TopIndexSpaceIfPresent(); }
80
81template <typename G>
83 : public IndexSpace
84{
85public:
86
87 IndexSpaceImp (const G& gshop, const Geometry& geom,
88 int required_coarsening_level, int max_coarsening_level,
89 int ngrow, bool build_coarse_level_by_coarsening,
90 bool extend_domain_face, int num_coarsen_opt);
91
92 IndexSpaceImp (const G& gshop, const Vector<Geometry>& geom,
93 int ngrow,
94 bool extend_domain_face, int num_coarsen_opt);
95
98 void operator= (IndexSpaceImp<G> const&) = delete;
99 void operator= (IndexSpaceImp<G> &&) = delete;
100
101 ~IndexSpaceImp () override = default;
102
103 [[nodiscard]] const Level& getLevel (const Geometry& geom) const final;
104 [[nodiscard]] const Geometry& getGeometry (const Box& dom) const final;
105 [[nodiscard]] const Box& coarsestDomain () const final {
106 return m_geom.back().Domain();
107 }
108 void addFineLevels (int num_new_fine_levels) final;
109 void addRegularCoarseLevels (int num_new_coarse_levels) final;
110
111 void setShift (int direction, int ncells) override;
112
113 void buildAllFCData () override;
114
115 using F = typename G::FunctionType;
116
117private:
118
119 G m_gshop;
120 bool m_build_coarse_level_by_coarsening;
121 bool m_extend_domain_face;
122 int m_num_coarsen_opt;
123
124 Vector<GShopLevel<G> > m_gslevel;
125 Vector<Geometry> m_geom;
126 Vector<Box> m_domain;
127 Vector<int> m_ngrow;
128};
129
131
137bool ExtendDomainFace ();
138
147int NumCoarsenOpt ();
148
165template <typename G>
166void
167Build (const G& gshop, const Geometry& geom,
168 int required_coarsening_level, int max_coarsening_level,
169 int ngrow = 4, bool build_coarse_level_by_coarsening = true,
170 bool extend_domain_face = ExtendDomainFace(),
171 int num_coarsen_opt = NumCoarsenOpt())
172{
173 BL_PROFILE("EB2::Initialize()");
174 IndexSpace::push(std::make_unique<IndexSpaceImp<G>>
175 (gshop, geom, required_coarsening_level, max_coarsening_level,
176 ngrow, build_coarse_level_by_coarsening,extend_domain_face,
177 num_coarsen_opt));
178}
179
191template <typename G>
192void
193Build (const G& gshop, Vector<Geometry> geom,
194 int ngrow = 4,
195 bool extend_domain_face = ExtendDomainFace(),
196 int num_coarsen_opt = NumCoarsenOpt())
197{
198 BL_PROFILE("EB2::Initialize()");
199 std::sort(geom.begin(), geom.end(), [] (Geometry const& a, Geometry const& b) { return a.Domain().numPts() > b.Domain().numPts(); });
200 IndexSpace::push(std::make_unique<IndexSpaceImp<G>>
201 (gshop, geom, ngrow, extend_domain_face, num_coarsen_opt));
202}
203
225void Build (const Geometry& geom,
226 int required_coarsening_level,
227 int max_coarsening_level,
228 int ngrow = 4,
229 bool build_coarse_level_by_coarsening = true,
230 bool extend_domain_face = ExtendDomainFace(),
231 int num_coarsen_opt = NumCoarsenOpt(),
232 bool support_mvmc = false);
233
240void BuildMultiValuedMultiCut (const Geometry& geom,
241 int required_coarsening_level,
242 int max_coarsening_level,
243 int ngrow = 4,
244 bool build_coarse_level_by_coarsening = true,
245 bool extend_domain_face = ExtendDomainFace(),
246 int num_coarsen_opt = NumCoarsenOpt());
247
260void BuildFromChkptFile (std::string const& fname,
261 const Geometry& geom,
262 int required_coarsening_level,
263 int max_coarsening_level,
264 int ngrow = 4,
265 bool build_coarse_level_by_coarsening = true,
266 bool extend_domain_face = ExtendDomainFace());
267
269int maxCoarseningLevel (const Geometry& geom);
271int maxCoarseningLevel (IndexSpace const* ebis, const Geometry& geom);
272
274void addFineLevels (int num_new_fine_levels);
275
277void addRegularCoarseLevels (int num_new_coarse_levels);
278
284void BuildFC ();
285
286}
287
288#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:196
Problem-domain geometry: maps between index space and physical space.
Definition AMReX_EB2.H:84
typename G::FunctionType F
Definition AMReX_EB2.H:115
const Box & coarsestDomain() const final
Definition AMReX_EB2.H:105
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
void buildAllFCData() override
Build face-centered EB data for all three face directions.
Definition AMReX_EB2_IndexSpaceI.H:211
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
virtual void buildAllFCData()
Build face-centered EB data for all three face directions.
Definition AMReX_EB2.H:70
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:73
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:85
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Definition AMReX_FabArrayBase.H:38
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:79
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 BuildFC()
Build face-centered EB data for all three face directions.
Definition AMReX_EB2.cpp:325
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 a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:242