diff --git a/src/amr/data/particles/refine/particles_data_split.hpp b/src/amr/data/particles/refine/particles_data_split.hpp index 8bbe880c3..9b0fd443e 100644 --- a/src/amr/data/particles/refine/particles_data_split.hpp +++ b/src/amr/data/particles/refine/particles_data_split.hpp @@ -24,8 +24,8 @@ namespace PHARE { namespace amr { - enum class ParticlesDataSplitType { - coarseBoundary, + enum class ParticlesDataSplitType : std::uint8_t { + coarseBoundary = 0, interior, coarseBoundaryOld, coarseBoundaryNew @@ -191,6 +191,7 @@ namespace amr } return incoming_estimate; }; + _reserve(destDomainParticles, count_expected); Splitter split; diff --git a/tests/amr/data/particles/refine/test_particle_data_refine_tag_strategy.hpp b/tests/amr/data/particles/refine/test_particle_data_refine_tag_strategy.hpp index 7808db27d..0e556b3af 100644 --- a/tests/amr/data/particles/refine/test_particle_data_refine_tag_strategy.hpp +++ b/tests/amr/data/particles/refine/test_particle_data_refine_tag_strategy.hpp @@ -42,15 +42,14 @@ std::array boxBoundsUpper(Box const& box) template -ParticleArray loadCell(int iCellX, int iCellY, int iCellZ) +void loadCell(ParticleArray& particles, int iCellX, int iCellY, int iCellZ) { - std::array _3diCell = {iCellX, iCellY, iCellZ}; + std::array const _3diCell = {iCellX, iCellY, iCellZ}; - float middle = 0.5; - float delta = 0.30f; + float const middle = 0.5; + float const delta = 0.30f; Particle particle; - ParticleArray particles; particle.weight = 1.; particle.charge = 1.; @@ -79,8 +78,6 @@ ParticleArray loadCell(int iCellX, int iCellY, int iCellZ) particle.delta[dirX] = middle + delta / 3; particles.push_back(particle); - - return particles; } @@ -156,17 +153,9 @@ class TagStrategy : public SAMRAI::mesh::StandardTagAndInitStrategy auto const upper = boxBoundsUpper(particlesBox); for (auto iCellX = lower[dirX]; iCellX <= upper[dirX]; ++iCellX) - { for (auto iCellY = lower[dirY]; iCellY <= upper[dirY]; ++iCellY) - { for (auto iCellZ = lower[dirZ]; iCellZ <= upper[dirZ]; ++iCellZ) - { - auto const particles = loadCell(iCellX, iCellY, iCellZ); - interior.insert(std::end(interior), std::begin(particles), - std::end(particles)); - } - } - } + loadCell(interior, iCellX, iCellY, iCellZ); } } } @@ -210,7 +199,19 @@ class TagStrategy : public SAMRAI::mesh::StandardTagAndInitStrategy // do nothing } - + auto domainParticlesForLevel(std::shared_ptr const& hierarchy, + int levelNumber) + { + std::vector*> particle_arrays; + auto level = hierarchy->getPatchLevel(levelNumber); + for (auto& patch : *level) + for (auto const& [name, dataId] : dataToAllocate_) + particle_arrays.emplace_back( + &std::dynamic_pointer_cast>>( + patch->getPatchData(dataId)) + ->domainParticles); + return particle_arrays; + } private: std::map dataToAllocate_; diff --git a/tests/amr/data/particles/refine/test_particledata_refine_basic_hierarchy.hpp b/tests/amr/data/particles/refine/test_particledata_refine_basic_hierarchy.hpp index edd6d9c9f..38c7f0c50 100644 --- a/tests/amr/data/particles/refine/test_particledata_refine_basic_hierarchy.hpp +++ b/tests/amr/data/particles/refine/test_particledata_refine_basic_hierarchy.hpp @@ -48,6 +48,10 @@ template, interpOrder>; + using Splitter_t = Splitter, InterpConst, + RefinedParticlesConst>; + using ParticlesRefineOperator_t + = ParticlesRefineOperator, splitType, Splitter_t>; public: /** @@ -74,7 +78,7 @@ class BasicHierarchy } - explicit BasicHierarchy(int _ratio) + explicit BasicHierarchy(int _ratio = 2) : ratio{SAMRAI::tbox::Dimension{dimension}, _ratio} , inputDatabase_{SAMRAI::tbox::InputManager::getManager()->parseInputFile( inputString(_ratio))} @@ -97,10 +101,7 @@ class BasicHierarchy dimension_, "ChopAndPackLoadBalancer", inputDatabase_->getDatabase("ChopAndPackLoadBalancer"))} - , refineOperator_{std::make_shared< - ParticlesRefineOperator, splitType, - Splitter, InterpConst, - RefinedParticlesConst>>>()} + , refineOperator_{std::make_shared()} , tagStrategy_{std::make_shared>(variablesIds_, refineOperator_, @@ -167,6 +168,11 @@ class BasicHierarchy SAMRAI::hier::IntVector const ratio; + auto domainParticlesForLevel(int levelNumber) const + { + return tagStrategy_->domainParticlesForLevel(hierarchy_, levelNumber); + } + private: std::map getVariablesIds_() { diff --git a/tests/amr/data/particles/refine/test_split.cpp b/tests/amr/data/particles/refine/test_split.cpp index 8027c35a2..c376fdcfb 100644 --- a/tests/amr/data/particles/refine/test_split.cpp +++ b/tests/amr/data/particles/refine/test_split.cpp @@ -5,6 +5,8 @@ #include "core/utilities/types.hpp" #include "amr/data/particles/refine/split.hpp" +#include "test_particledata_refine_basic_hierarchy.hpp" + #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -12,7 +14,7 @@ namespace { template -using Splitter +using Splitter_t = PHARE::amr::Splitter, PHARE::core::InterpConst, PHARE::core::RefinedParticlesConst>; @@ -22,7 +24,7 @@ struct SplitterTest : public ::testing::Test SplitterTest() { Splitter splitter; } }; -using Splitters = testing::Types, Splitter<2, 1, 8> /*, Splitter<3, 1, 27>*/>; +using Splitters = testing::Types, Splitter_t<2, 1, 8> /*, Splitter<3, 1, 27>*/>; TYPED_TEST_SUITE(SplitterTest, Splitters); @@ -31,4 +33,20 @@ TYPED_TEST(SplitterTest, constexpr_init) constexpr TypeParam param{}; } + + } // namespace + + +using BasicHierarchy_t = BasicHierarchy<2, 3, ParticlesDataSplitType::interior, 4>; +struct Hierarchy_t : public ::testing::Test, public BasicHierarchy_t +{ +}; + +TEST_F(Hierarchy_t, checkCapacityPostRefinement) +{ // without reserve the capacity is 4096 and will likely have multiple allocations + auto domainParticles = domainParticlesForLevel(1); + ASSERT_EQ(domainParticles.size(), 1); + EXPECT_EQ(domainParticles[0]->size(), 2800); + EXPECT_EQ(domainParticles[0]->capacity(), 4032); +}