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
22void useEB2 (bool);
23
24void 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
73const IndexSpace* TopIndexSpaceIfPresent () noexcept;
74inline const IndexSpace* TopIndexSpace () noexcept { return TopIndexSpaceIfPresent(); }
75
76template <typename G>
78 : public IndexSpace
79{
80public:
81
82 IndexSpaceImp (const G& gshop, const Geometry& geom,
83 int required_coarsening_level, int max_coarsening_level,
84 int ngrow, bool build_coarse_level_by_coarsening,
85 bool extend_domain_face, int num_coarsen_opt);
86
87 IndexSpaceImp (const G& gshop, const Vector<Geometry>& geom,
88 int ngrow,
89 bool extend_domain_face, int num_coarsen_opt);
90
93 void operator= (IndexSpaceImp<G> const&) = delete;
94 void operator= (IndexSpaceImp<G> &&) = delete;
95
96 ~IndexSpaceImp () override = default;
97
98 [[nodiscard]] const Level& getLevel (const Geometry& geom) const final;
99 [[nodiscard]] const Geometry& getGeometry (const Box& dom) const final;
100 [[nodiscard]] const Box& coarsestDomain () const final {
101 return m_geom.back().Domain();
102 }
103 void addFineLevels (int num_new_fine_levels) final;
104 void addRegularCoarseLevels (int num_new_coarse_levels) final;
105
106 void setShift (int direction, int ncells) override;
107
108 using F = typename G::FunctionType;
109
110private:
111
112 G m_gshop;
113 bool m_build_coarse_level_by_coarsening;
114 bool m_extend_domain_face;
115 int m_num_coarsen_opt;
116
117 Vector<GShopLevel<G> > m_gslevel;
118 Vector<Geometry> m_geom;
119 Vector<Box> m_domain;
120 Vector<int> m_ngrow;
121};
122
124
125bool ExtendDomainFace ();
126int NumCoarsenOpt ();
127
129template <typename G>
130void
131Build (const G& gshop, const Geometry& geom,
132 int required_coarsening_level, int max_coarsening_level,
133 int ngrow = 4, bool build_coarse_level_by_coarsening = true,
134 bool extend_domain_face = ExtendDomainFace(),
135 int num_coarsen_opt = NumCoarsenOpt())
136{
137 BL_PROFILE("EB2::Initialize()");
138 IndexSpace::push(std::make_unique<IndexSpaceImp<G>>
139 (gshop, geom, required_coarsening_level, max_coarsening_level,
140 ngrow, build_coarse_level_by_coarsening,extend_domain_face,
141 num_coarsen_opt));
142}
143
145template <typename G>
146void
147Build (const G& gshop, Vector<Geometry> geom,
148 int ngrow = 4,
149 bool extend_domain_face = ExtendDomainFace(),
150 int num_coarsen_opt = NumCoarsenOpt())
151{
152 BL_PROFILE("EB2::Initialize()");
153 std::sort(geom.begin(), geom.end(), [] (Geometry const& a, Geometry const& b) { return a.Domain().numPts() > b.Domain().numPts(); });
154 IndexSpace::push(std::make_unique<IndexSpaceImp<G>>
155 (gshop, geom, ngrow, extend_domain_face, num_coarsen_opt));
156}
157
159void Build (const Geometry& geom,
160 int required_coarsening_level,
161 int max_coarsening_level,
162 int ngrow = 4,
163 bool build_coarse_level_by_coarsening = true,
164 bool extend_domain_face = ExtendDomainFace(),
165 int num_coarsen_opt = NumCoarsenOpt(),
166 bool support_mvmc = false);
167
168void BuildMultiValuedMultiCut (const Geometry& geom,
169 int required_coarsening_level,
170 int max_coarsening_level,
171 int ngrow = 4,
172 bool build_coarse_level_by_coarsening = true,
173 bool extend_domain_face = ExtendDomainFace(),
174 int num_coarsen_opt = NumCoarsenOpt());
175
176void BuildFromChkptFile (std::string const& fname,
177 const Geometry& geom,
178 int required_coarsening_level,
179 int max_coarsening_level,
180 int ngrow = 4,
181 bool build_coarse_level_by_coarsening = true,
182 bool extend_domain_face = ExtendDomainFace());
183
184int maxCoarseningLevel (const Geometry& geom);
185int maxCoarseningLevel (IndexSpace const* ebis, const Geometry& geom);
186
187void addFineLevels (int num_new_fine_levels);
188
189void addRegularCoarseLevels (int num_new_coarse_levels);
190
191}
192
193#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:79
typename G::FunctionType F
Definition AMReX_EB2.H:108
const Box & coarsestDomain() const final
Definition AMReX_EB2.H:100
const Level & getLevel(const Geometry &geom) const final
Definition AMReX_EB2_IndexSpaceI.H:94
~IndexSpaceImp() override=default
void addFineLevels(int num_new_fine_levels) final
Definition AMReX_EB2_IndexSpaceI.H:112
IndexSpaceImp(IndexSpaceImp< G > const &)=delete
void addRegularCoarseLevels(int num_new_coarse_levels) final
Definition AMReX_EB2_IndexSpaceI.H:138
const Geometry & getGeometry(const Box &dom) const final
Definition AMReX_EB2_IndexSpaceI.H:103
IndexSpaceImp(IndexSpaceImp< G > &&)=delete
void operator=(IndexSpaceImp< G > const &)=delete
void setShift(int direction, int ncells) override
Definition AMReX_EB2_IndexSpaceI.H:184
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:40
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
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)
Definition AMReX_EB2.cpp:101
Definition AMReX_FabArrayBase.H:33
int NumCoarsenOpt()
Definition AMReX_EB2.cpp:58
void addRegularCoarseLevels(int num_new_coarse_levels)
Definition AMReX_EB2.cpp:264
bool ExtendDomainFace()
Definition AMReX_EB2.cpp:53
int maxCoarseningLevel(const Geometry &geom)
Definition AMReX_EB2.cpp:298
void Initialize()
Definition AMReX_EB2.cpp:35
void addFineLevels(int num_new_fine_levels)
Definition AMReX_EB2.cpp:255
const IndexSpace * TopIndexSpace() noexcept
Definition AMReX_EB2.H:74
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)
Definition AMReX_EB2.cpp:314
const IndexSpace * TopIndexSpaceIfPresent() noexcept
Definition AMReX_EB2.cpp:93
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:273
void Finalize()
Definition AMReX_EB2.cpp:45
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230