From 6fca2f77cdaaccf56d8607e56df2c62b8ddf3e5d Mon Sep 17 00:00:00 2001 From: deegan Date: Thu, 3 Oct 2024 10:30:13 +0200 Subject: [PATCH] keep particle overallocation on restore state --- src/amr/solvers/solver_ppc.hpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/amr/solvers/solver_ppc.hpp b/src/amr/solvers/solver_ppc.hpp index eb1f79fe8..3eb79f496 100644 --- a/src/amr/solvers/solver_ppc.hpp +++ b/src/amr/solvers/solver_ppc.hpp @@ -152,6 +152,22 @@ class SolverPPC : public ISolver std::unordered_map tmpDomain; std::unordered_map patchGhost; + template + 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 @@ -206,15 +222,9 @@ void SolverPPC::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()); } } }