21 #ifndef FUB_AMREX_CUTCELL_PATCH_HIERARCHY_HPP
22 #define FUB_AMREX_CUTCELL_PATCH_HIERARCHY_HPP
31 #include <AMReX_EBFabFactory.H>
32 #include <AMReX_FluxRegister.H>
33 #include <AMReX_Geometry.H>
34 #include <AMReX_MultiCutFab.H>
35 #include <AMReX_MultiFab.H>
36 #include <AMReX_PlotFileUtil.H>
38 #include <fmt/format.h>
83 const ::amrex::DistributionMapping& dm,
int n_components,
84 std::shared_ptr<::amrex::EBFArrayBoxFactory>
factory,
int ngrow);
87 std::array<std::shared_ptr<::amrex::MultiCutFab>, AMREX_SPACEDIM>;
90 std::shared_ptr<::amrex::EBFArrayBoxFactory>
factory;
117 GetOptionOr(options,
"ngrow_eb_level_set", ngrow_eb_level_set);
119 options,
"cutcell_load_balance_weight", cutcell_load_balance_weight);
120 remove_covered_grids =
121 GetOptionOr(options,
"remove_covered_grids", remove_covered_grids);
126 BOOST_LOG(log) <<
" - ngrow_eb_level_set = " << ngrow_eb_level_set;
127 BOOST_LOG(log) <<
" - cutcell_load_balance_weight = "
128 << cutcell_load_balance_weight;
129 BOOST_LOG(log) <<
" - remove_covered_grids = " << remove_covered_grids;
132 std::vector<const ::amrex::EB2::IndexSpace*> index_spaces{};
133 int ngrow_eb_level_set{5};
134 double cutcell_load_balance_weight{6.0};
135 bool remove_covered_grids{
true};
143 template <
typename Equation>
166 [[nodiscard]] const std::shared_ptr<CounterRegistry>&
167 GetCounterRegistry() const noexcept;
169 void SetCounterRegistry(std::shared_ptr<CounterRegistry> registry);
175 int GetNumberOfLevels() const noexcept;
177 int GetMaxNumberOfLevels() const noexcept;
186 std::ptrdiff_t GetCycles(
int level = 0) const;
198 int GetRatioToCoarserLevel(
int level,
Direction dir) const;
200 ::amrex::IntVect GetRatioToCoarserLevel(
int level) const;
202 const ::amrex::
Geometry& GetGeometry(
int level) const;
208 const std::shared_ptr<::amrex::EBFArrayBoxFactory>&
209 GetEmbeddedBoundary(
int level) const;
212 const ::amrex::MFIter& mfi) const;
216 GetDebugStorage() const noexcept;
225 std::vector<::amrex::
Geometry> patch_level_geometry_;
226 std::shared_ptr<CounterRegistry> registry_;
236 template <
typename Equation>
242 std::size_t size =
static_cast<std::size_t
>(nlevels);
243 ::amrex::Vector<const ::amrex::MultiFab*> mf(size);
244 ::amrex::Vector<::amrex::Geometry> geoms(size);
245 ::amrex::Vector<int> level_steps(size);
246 ::amrex::Vector<::amrex::IntVect> ref_ratio(size - 1);
247 for (std::size_t i = 0; i < size; ++i) {
250 level_steps[i] =
static_cast<int>(hier.
GetCycles(
static_cast<int>(i)));
252 for (std::size_t i = 1; i < size; ++i) {
256 constexpr
auto names = Traits::names;
258 const std::size_t n_names =
260 ::amrex::Vector<std::string> varnames;
261 varnames.reserve(n_names);
262 boost::mp11::tuple_for_each(
Zip(names,
StateToTuple(depths)), [&](
auto xs) {
263 const int ncomp = std::get<1>(xs);
265 varnames.push_back(std::get<0>(xs));
267 for (
int i = 0; i < ncomp; ++i) {
268 varnames.push_back(fmt::format(
"{}_{}", std::get<0>(xs), i));
272 ::amrex::EB_WriteMultiLevelPlotfile(plotfilename, nlevels, mf, varnames,
284 std::size_t size =
static_cast<std::size_t
>(nlevels);
285 ::amrex::Vector<const ::amrex::MultiFab*> mf(size);
286 ::amrex::Vector<::amrex::Geometry> geoms(size);
287 ::amrex::Vector<int> level_steps(size);
288 ::amrex::Vector<::amrex::IntVect> ref_ratio(size - 1);
289 for (std::size_t i = 0; i < size; ++i) {
292 level_steps[i] =
static_cast<int>(hier.
GetCycles(
static_cast<int>(i)));
294 for (std::size_t i = 1; i < size; ++i) {
298 constexpr
auto names = Traits::names;
300 const std::size_t n_names =
302 ::amrex::Vector<std::string> varnames;
303 varnames.reserve(n_names);
304 boost::mp11::tuple_for_each(
Zip(names,
StateToTuple(depths)), [&](
auto xs) {
305 const int ncomp = std::get<1>(xs);
307 varnames.push_back(std::get<0>(xs));
310 for (
int i = 0; i < ncomp; ++i) {
311 if (std::get<0>(xs) == std::string{
"Species"}) {
312 varnames.push_back(species[i]);
314 varnames.push_back(fmt::format(
"{}_{}", std::get<0>(xs), i));
319 ::amrex::EB_WriteMultiLevelPlotfile(plotfilename, nlevels, mf, varnames,
#define FUB_ASSERT(x)
Definition: assert.hpp:39
span< const std::string > GetSpeciesNames() const
Return the name of the ith species.
Definition: FlameMasterReactor.hpp:338
FlameMasterReactor & GetReactor() noexcept
Definition: IdealGasMix.hpp:140
This class stores a list of snapshots and returns proxy objects to those.
Definition: output/DebugOutput.hpp:201
Definition: AMReX/Geometry.hpp:30
Definition: AMReX/cutcell/PatchHierarchy.hpp:139
PatchLevel & GetPatchLevel(int level)
Returns the number of cycles done for a specific level.
int GetRatioToCoarserLevel(int level, Direction dir) const
Returns the ratio from fine to coarse for specified fine level number and direction.
Duration GetTimePoint(int level=0) const
Returns the time point of a specified level number.
int GetNumberOfLevels() const noexcept
std::ptrdiff_t GetCycles(int level=0) const
Returns the number of cycles done for a specific level.
PatchHierarchy(DataDescription description, const CartesianGridGeometry &geometry, const PatchHierarchyOptions &options)
Constructs a PatchHierarchy object which is capable of holding data described by the secified data de...
const DataDescription & GetDataDescription() const noexcept
Return some additional patch hierarchy options.
const ::amrex::Geometry & GetGeometry(int level) const
Returns the number of cycles done for a specific level.
Definition: mdspan.hpp:573
An extents object defines a multidimensional index space which is the Cartesian product of integers e...
Definition: mdspan.hpp:208
A span is a view over a contiguous sequence of objects, the storage of which is owned by some other o...
Definition: span.hpp:81
Definition: FillCutCellData.hpp:30
PatchHierarchy ReadCheckpointFile(const std::string &checkpointname, DataDescription desc, const CartesianGridGeometry &geometry, const PatchHierarchyOptions &options)
void WriteMatlabData(const std::string &name, const PatchHierarchy &hierarchy, fub::Duration time_point, std::ptrdiff_t cycle_number, MPI_Comm comm)
std::vector< double > GatherStates(const PatchHierarchy &hierarchy, basic_mdspan< const double, extents< AMREX_SPACEDIM, dynamic_extent >> xs, MPI_Comm comm)
void WritePlotFile(const std::string &plotfilename, const PatchHierarchy &hier, const Equation &equation)
Definition: AMReX/cutcell/PatchHierarchy.hpp:237
void Write2Dfrom3D(const std::string &name, const PatchHierarchy &hierarchy, const ::amrex::Box &finest_box, const IdealGasMix< 3 > &eq, fub::Duration time_point, std::ptrdiff_t cycle_number, MPI_Comm comm)
void WriteCheckpointFile(const std::string &checkpointname, const PatchHierarchy &hier)
The amrex namespace.
Definition: AverageState.hpp:33
DataDescription MakeDataDescription(const Equation &equation)
Definition: AMReX/PatchHierarchy.hpp:248
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
typename remove_cvref< T >::type remove_cvref_t
Definition: type_traits.hpp:226
void Log(std::string message, Duration timepoint, boost::log::trivial::severity_level level=boost::log::trivial::severity_level::info)
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
constexpr struct fub::DepthsFn Depths
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
constexpr auto Zip(Ts &&... ts)
Definition: State.hpp:65
ProgramOptions GetOptions(const ProgramOptions &options, const std::string &name)
T GetOptionOr(const ProgramOptions &map, const std::string &name, const T &value)
Definition: ProgramOptions.hpp:48
auto StateToTuple(const State &x)
Definition: State.hpp:322
IndexBox< Rank > Box(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:486
std::map< std::string, pybind11::object > ProgramOptions
Definition: ProgramOptions.hpp:40
Definition: CutCellData.hpp:34
Definition: State.hpp:162
Definition: CartesianGridGeometry.hpp:37
The DataDescription class contains all information which is neccessary to describe the complete and c...
Definition: AMReX/PatchHierarchy.hpp:73
void Print(Log &log)
Definition: AMReX/PatchHierarchy.hpp:385
The PatchLevel represents a distributed grid containing plain simulation data without a ghost cell la...
Definition: AMReX/PatchHierarchy.hpp:90
Duration time_point
Definition: AMReX/PatchHierarchy.hpp:141
::amrex::MultiFab data
Definition: AMReX/PatchHierarchy.hpp:145
This class extents the normal hierarchy options with a pointer to an embedded boundary index space fo...
Definition: AMReX/cutcell/PatchHierarchy.hpp:112
void Print(Log &log)
Definition: AMReX/cutcell/PatchHierarchy.hpp:124
PatchHierarchyOptions()=default
PatchHierarchyOptions(const ProgramOptions &options)
Definition: AMReX/cutcell/PatchHierarchy.hpp:114
This class holds state data arrays for each refinement level of a patch hierarchy.
Definition: AMReX/cutcell/PatchHierarchy.hpp:57
MultiCutFabs shielded_left
Store singly shielded from left face fractions for all faces which touch a cut cell.
Definition: AMReX/cutcell/PatchHierarchy.hpp:98
std::array< std::shared_ptr<::amrex::MultiCutFab >, AMREX_SPACEDIM > MultiCutFabs
Definition: AMReX/cutcell/PatchHierarchy.hpp:87
PatchLevel(PatchLevel &&) noexcept=default
Moves a patch level without any allocations happening.
MultiCutFabs doubly_shielded
Store doubly shielded face fractions for all faces which touch a cut cell.
Definition: AMReX/cutcell/PatchHierarchy.hpp:106
PatchLevel(const PatchLevel &)
Deeply copy a patch level on each MPI Rank and recompute shielded fractions.
PatchLevel & operator=(const PatchLevel &)
Deeply copy a patch level on each MPI Rank and recompute shielded fractions.
MultiCutFabs unshielded
Store unshielded face fractions for all faces which touch a cut cell.
Definition: AMReX/cutcell/PatchHierarchy.hpp:94
MultiCutFabs shielded_right
Store singly shielded from right face fractions for all faces which touch a cut cell.
Definition: AMReX/cutcell/PatchHierarchy.hpp:102
std::shared_ptr<::amrex::EBFArrayBoxFactory > factory
This stores the EB factory for this refinement level.
Definition: AMReX/cutcell/PatchHierarchy.hpp:90