Skip to content

Commit

Permalink
keep particle overallocation on restore state
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 3, 2024
1 parent ecef2fe commit 6fca2f7
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/amr/solvers/solver_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ class SolverPPC : public ISolver<AMR_Types>
std::unordered_map<std::string, ParticleArray> tmpDomain;
std::unordered_map<std::string, ParticleArray> patchGhost;

template<typename Map>
static void add_to(Map& map, std::string const& key, ParticleArray const& ps)
{
// vector copy drops the capacity (over allocation of the source)
// we want to keep the overallocation somewhat - how much to be assessed
ParticleArray empty{ps.box()};

if (!map.count(key))
map.emplace(key, empty);
else
map.at(key) = empty;

auto& v = map.at(key);
v.reserve(ps.capacity());
v.replace_from(ps);
}

}; // end solverPPC

Expand Down Expand Up @@ -206,15 +222,9 @@ void SolverPPC<HybridModel, AMR_Types>::saveState_(level_t& level, ModelViews_t&
ss << state.patch->getGlobalId();
for (auto& pop : state.ions)
{
auto key = ss.str() + "_" + pop.name();
if (!tmpDomain.count(key))
tmpDomain.emplace(key, pop.domainParticles());
else
tmpDomain.at(key) = pop.domainParticles();
if (!patchGhost.count(key))
patchGhost.emplace(key, pop.patchGhostParticles());
else
patchGhost.at(key) = pop.patchGhostParticles();
std::string const key = ss.str() + "_" + pop.name();
add_to(tmpDomain, key, pop.domainParticles());
add_to(patchGhost, key, pop.patchGhostParticles());
}
}
}
Expand Down

0 comments on commit 6fca2f7

Please sign in to comment.