diff --git a/src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp b/src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp index 3b6a90393..919e27c88 100644 --- a/src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp +++ b/src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp @@ -47,8 +47,8 @@ namespace PHARE namespace amr { - /** \brief An HybridMessenger is the specialization of a HybridMessengerStrategy for hybrid to - * hybrid data communications. + /** \brief An HybridMessenger is the specialization of a HybridMessengerStrategy for hybrid + * to hybrid data communications. */ template class HybridHybridMessengerStrategy : public HybridMessengerStrategy @@ -82,7 +82,7 @@ namespace amr using DefaultCoarsenOp = BaseCoarsenOp>; public: - static const inline std::string stratName = "HybridModel-HybridModel"; + static inline std::string const stratName = "HybridModel-HybridModel"; static constexpr std::size_t rootLevelNumber = 0; @@ -191,7 +191,7 @@ namespace amr , all quantities that are in initialization refiners need to be regridded */ void regrid(std::shared_ptr const& hierarchy, - const int levelNumber, + int const levelNumber, std::shared_ptr const& oldLevel, IPhysicalModel& model, double const initDataTime) override { @@ -345,7 +345,7 @@ namespace amr auto dataOnPatch = resourcesManager_->setOnPatch(*patch, ions); for (auto& pop : ions) { - empty(pop.patchGhostParticles()); + pop.patchGhostParticles().clear(); } } patchGhostPartRefiners_.fill(level.getLevelNumber(), fillTime); @@ -465,44 +465,24 @@ namespace amr */ void lastStep(IPhysicalModel& model, SAMRAI::hier::PatchLevel& level) override { - if (level.getLevelNumber() > 0) - { - PHARE_LOG_SCOPE(3, "HybridHybridMessengerStrategy::lastStep"); + if (level.getLevelNumber() == 0) + return; + + PHARE_LOG_SCOPE(3, "HybridHybridMessengerStrategy::lastStep"); - auto& hybridModel = static_cast(model); - for (auto& patch : level) + auto& hybridModel = static_cast(model); + for (auto& patch : level) + { + auto& ions = hybridModel.state.ions; + auto dataOnPatch = resourcesManager_->setOnPatch(*patch, ions); + for (auto& pop : ions) { - auto& ions = hybridModel.state.ions; - auto dataOnPatch = resourcesManager_->setOnPatch(*patch, ions); - for (auto& pop : ions) - { - auto& levelGhostParticlesOld = pop.levelGhostParticlesOld(); - auto& levelGhostParticlesNew = pop.levelGhostParticlesNew(); - auto& levelGhostParticles = pop.levelGhostParticles(); - - core::swap(levelGhostParticlesNew, levelGhostParticlesOld); - core::empty(levelGhostParticlesNew); - core::empty(levelGhostParticles); - std::copy(std::begin(levelGhostParticlesOld), - std::end(levelGhostParticlesOld), - std::back_inserter(levelGhostParticles)); - - if (level.getLevelNumber() == 0) - { - if (levelGhostParticlesNew.size() != 0) - throw std::runtime_error( - "levelGhostParticlesNew detected in root level : " - + std::to_string(levelGhostParticlesNew.size())); - if (levelGhostParticles.size() != 0) - throw std::runtime_error( - "levelGhostParticles detected in root level : " - + std::to_string(levelGhostParticles.size())); - if (levelGhostParticlesOld.size() != 0) - throw std::runtime_error( - "levelGhostParticlesOld detected in root level : " - + std::to_string(levelGhostParticlesOld.size())); - } - } + auto& levelGhostParticlesOld = pop.levelGhostParticlesOld(); + auto& levelGhostParticlesNew = pop.levelGhostParticlesNew(); + auto& levelGhostParticles = pop.levelGhostParticles(); + + levelGhostParticlesOld = std::move(levelGhostParticlesNew); + levelGhostParticles = levelGhostParticlesOld; } } } @@ -737,9 +717,7 @@ namespace amr auto& levelGhostParticlesOld = pop.levelGhostParticlesOld(); auto& levelGhostParticles = pop.levelGhostParticles(); - core::empty(levelGhostParticles); - std::copy(std::begin(levelGhostParticlesOld), std::end(levelGhostParticlesOld), - std::back_inserter(levelGhostParticles)); + levelGhostParticles = levelGhostParticlesOld; } } } @@ -959,7 +937,7 @@ namespace amr // maybe we should keep these for some time // as comments in case they are useful again - PHARE_DEBUG_DO(const std::string before = "BEFORE"; + PHARE_DEBUG_DO(std::string const before = "BEFORE"; debug_print(B, layout, loc, ix, iy, before);) Bx(ix, iy - 1) = Bx(ix + 1, iy - 1) + dx / dy * (By(ix, iy) - By(ix, iy - 1)); @@ -967,7 +945,7 @@ namespace amr By(ix - 1, iy) = By(ix - 1, iy + 1) + dy / dx * (Bx(ix, iy) - Bx(ix - 1, iy)); - PHARE_DEBUG_DO(const std::string after = "AFTER"; + PHARE_DEBUG_DO(std::string const after = "AFTER"; debug_print(B, layout, loc, ix, iy, after);) } } // end corner loops diff --git a/src/core/data/particles/particle_array.hpp b/src/core/data/particles/particle_array.hpp index 93acc3066..b2db05ac1 100644 --- a/src/core/data/particles/particle_array.hpp +++ b/src/core/data/particles/particle_array.hpp @@ -56,10 +56,33 @@ class ParticleArray assert(box_.size() > 0); } - ParticleArray(ParticleArray const& from) = default; - ParticleArray(ParticleArray&& from) = default; - ParticleArray& operator=(ParticleArray&& from) = default; - ParticleArray& operator=(ParticleArray const& from) = default; + ParticleArray(ParticleArray&& from) = default; + + ParticleArray(ParticleArray const& from) + : particles_{from.particles_} + , box_{from.box_} + , cellMap_{from.cellMap_} + { + remap_particles(); + } + + ParticleArray& operator=(ParticleArray const& from) + { + this->particles_ = from.particles_; + this->box_ = from.box_; + this->cellMap_ = from.cellMap_; // copy for alloc, not alloc on pushback + remap_particles(); + return *this; + }; + + ParticleArray& operator=(ParticleArray&& from) + { + this->particles_ = std::move(from.particles_); + this->box_ = from.box_; // not movable + this->cellMap_ = from.cellMap_; // std::move == segfault / bug in cellmap? + from.cellMap_.clear(); + return *this; + }; NO_DISCARD std::size_t size() const { return particles_.size(); } NO_DISCARD std::size_t capacity() const { return particles_.capacity(); } @@ -148,6 +171,11 @@ class ParticleArray void map_particles() const { cellMap_.add(particles_); } void empty_map() { cellMap_.empty(); } + void remap_particles() + { + empty_map(); + map_particles(); + } NO_DISCARD auto nbr_particles_in(box_t const& box) const { return cellMap_.size(box); } @@ -262,17 +290,6 @@ namespace PHARE { namespace core { - template - void empty(ParticleArray& array) - { - array.clear(); - } - - template - void swap(ParticleArray& array1, ParticleArray& array2) - { - array1.swap(array2); - } template