Skip to content

Commit

Permalink
Remove multifab_map and associated functions (ECP-WarpX#5351)
Browse files Browse the repository at this point in the history
Now that all MultiFabs are registered in the new system, the old
`multifab_map` can be removed.

Note that the `imultifab_map` is still needed since the new system does
not yet work with `iMultiFabs`.

This breaks the Python API since it removes `warpx.field` which was
returning the old map.
  • Loading branch information
dpgrote authored Oct 3, 2024
1 parent ab91803 commit 6302c39
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 94 deletions.
7 changes: 0 additions & 7 deletions Source/Python/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ void init_WarpX (py::module& m)
//py::overload_cast< int >(&WarpX::boxArray, py::const_),
py::arg("lev")
)
.def("field",
[](WarpX const & wx) {
return wx.multifab_map;
},
py::return_value_policy::reference_internal,
R"doc(Registry to all WarpX MultiFab (fields).)doc"
)
.def("multifab",
[](WarpX & wx, std::string internal_name) {
if (wx.m_fields.internal_has(internal_name)) {
Expand Down
50 changes: 2 additions & 48 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -403,31 +403,6 @@ public:
// Global rho nodal flag to know about rho index type when rho MultiFab is not allocated
amrex::IntVect m_rho_nodal_flag;

/**
* \brief
* Allocate and optionally initialize the MultiFab. This also adds the MultiFab
* to the map of MultiFabs (used to ease the access to MultiFabs from the Python
* interface
*
* \param[out] mf The MultiFab unique pointer to be allocated
* \param[in] ba The BoxArray describing the MultiFab
* \param[in] dm The DistributionMapping describing the MultiFab
* \param[in] ncomp The number of components in the MultiFab
* \param[in] ngrow The number of guard cells in the MultiFab
* \param[in] level The refinement level
* \param[in] name The name of the MultiFab to use in the map
* \param[in] initial_value The optional initial value
*/
static void AllocInitMultiFab (
std::unique_ptr<amrex::MultiFab>& mf,
const amrex::BoxArray& ba,
const amrex::DistributionMapping& dm,
int ncomp,
const amrex::IntVect& ngrow,
int level,
const std::string& name,
std::optional<const amrex::Real> initial_value = {});

/**
* \brief
* Allocate and optionally initialize the iMultiFab. This also adds the iMultiFab
Expand All @@ -453,30 +428,9 @@ public:
const std::string& name,
std::optional<const int> initial_value = {});

/**
* \brief
* Create an alias of a MultiFab, adding the alias to the MultiFab map
* \param[out] mf The MultiFab to create
* \param[in] mf_to_alias The MultiFab to alias
* \param[in] scomp The starting component to be aliased
* \param[in] ncomp The number of components to alias
* \param[in] level The refinement level
* \param[in] name The name of the MultiFab to use in the map
* \param[in] initial_value optional initial value for MultiFab
*/
static void AliasInitMultiFab (
std::unique_ptr<amrex::MultiFab>& mf,
const amrex::MultiFab& mf_to_alias,
int scomp,
int ncomp,
int level,
const std::string& name,
std::optional<const amrex::Real> initial_value);

// Maps of all of the MultiFabs and iMultiFabs used (this can include MFs from other classes)
// This is a convenience for the Python interface, allowing all MultiFabs
// Maps of all of the iMultiFabs used (this can include MFs from other classes)
// This is a convenience for the Python interface, allowing all iMultiFabs
// to be easily referenced from Python.
static std::map<std::string, amrex::MultiFab *> multifab_map;
static std::map<std::string, amrex::iMultiFab *> imultifab_map;

/**
Expand Down
39 changes: 0 additions & 39 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ bool WarpX::safe_guard_cells = false;

utils::parser::IntervalsParser WarpX::dt_update_interval;

std::map<std::string, amrex::MultiFab *> WarpX::multifab_map;
std::map<std::string, amrex::iMultiFab *> WarpX::imultifab_map;

IntVect WarpX::filter_npass_each_dir(1);
Expand Down Expand Up @@ -3284,26 +3283,6 @@ TagWithLevelSuffix (std::string name, int const level)
return name;
}

void
WarpX::AllocInitMultiFab (
std::unique_ptr<amrex::MultiFab>& mf,
const amrex::BoxArray& ba,
const amrex::DistributionMapping& dm,
const int ncomp,
const amrex::IntVect& ngrow,
const int level,
const std::string& name,
std::optional<const amrex::Real> initial_value)
{
const auto name_with_suffix = TagWithLevelSuffix(name, level);
const auto tag = amrex::MFInfo().SetTag(name_with_suffix);
mf = std::make_unique<amrex::MultiFab>(ba, dm, ncomp, ngrow, tag);
if (initial_value) {
mf->setVal(*initial_value);
}
multifab_map[name_with_suffix] = mf.get();
}

void
WarpX::AllocInitMultiFab (
std::unique_ptr<amrex::iMultiFab>& mf,
Expand All @@ -3324,24 +3303,6 @@ WarpX::AllocInitMultiFab (
imultifab_map[name_with_suffix] = mf.get();
}

void
WarpX::AliasInitMultiFab (
std::unique_ptr<amrex::MultiFab>& mf,
const amrex::MultiFab& mf_to_alias,
const int scomp,
const int ncomp,
const int level,
const std::string& name,
std::optional<const amrex::Real> initial_value)
{
const auto name_with_suffix = TagWithLevelSuffix(name, level);
mf = std::make_unique<amrex::MultiFab>(mf_to_alias, amrex::make_alias, scomp, ncomp);
if (initial_value) {
mf->setVal(*initial_value);
}
multifab_map[name_with_suffix] = mf.get();
}

amrex::DistributionMapping
WarpX::MakeDistributionMap (int lev, amrex::BoxArray const& ba)
{
Expand Down

0 comments on commit 6302c39

Please sign in to comment.