Skip to content

Commit

Permalink
refinement reserving capacity test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 16, 2024
1 parent 04b1b69 commit 8c4fa42
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/amr/data/particles/refine/particles_data_split.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace PHARE
{
namespace amr
{
enum class ParticlesDataSplitType {
coarseBoundary,
enum class ParticlesDataSplitType : std::uint8_t {
coarseBoundary = 0,
interior,
coarseBoundaryOld,
coarseBoundaryNew
Expand Down Expand Up @@ -191,6 +191,7 @@ namespace amr
}
return incoming_estimate;
};

_reserve(destDomainParticles, count_expected);

Splitter split;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ std::array<int, 3> boxBoundsUpper(Box const& box)


template<std::size_t dimension>
ParticleArray<dimension> loadCell(int iCellX, int iCellY, int iCellZ)
void loadCell(ParticleArray<dimension>& particles, int iCellX, int iCellY, int iCellZ)
{
std::array<int, 3> _3diCell = {iCellX, iCellY, iCellZ};
std::array<int, 3> const _3diCell = {iCellX, iCellY, iCellZ};

float middle = 0.5;
float delta = 0.30f;
float const middle = 0.5;
float const delta = 0.30f;

Particle<dimension> particle;
ParticleArray<dimension> particles;

particle.weight = 1.;
particle.charge = 1.;
Expand Down Expand Up @@ -79,8 +78,6 @@ ParticleArray<dimension> loadCell(int iCellX, int iCellY, int iCellZ)

particle.delta[dirX] = middle + delta / 3;
particles.push_back(particle);

return particles;
}


Expand Down Expand Up @@ -156,17 +153,9 @@ class TagStrategy : public SAMRAI::mesh::StandardTagAndInitStrategy
auto const upper = boxBoundsUpper<dimension>(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<dimension>(iCellX, iCellY, iCellZ);
interior.insert(std::end(interior), std::begin(particles),
std::end(particles));
}
}
}
loadCell<dimension>(interior, iCellX, iCellY, iCellZ);
}
}
}
Expand Down Expand Up @@ -210,7 +199,19 @@ class TagStrategy : public SAMRAI::mesh::StandardTagAndInitStrategy
// do nothing
}


auto domainParticlesForLevel(std::shared_ptr<SAMRAI::hier::PatchHierarchy> const& hierarchy,
int levelNumber)
{
std::vector<ParticleArray<dimension>*> 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<ParticlesData<ParticleArray<dimension>>>(
patch->getPatchData(dataId))
->domainParticles);
return particle_arrays;
}

private:
std::map<std::string, int> dataToAllocate_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ template<std::size_t dimension, std::size_t interpOrder, ParticlesDataSplitType
class BasicHierarchy
{
using ParticlesVariable_t = ParticlesVariable<ParticleArray<dimension>, interpOrder>;
using Splitter_t = Splitter<DimConst<dimension>, InterpConst<interpOrder>,
RefinedParticlesConst<refinedParticlesNbr>>;
using ParticlesRefineOperator_t
= ParticlesRefineOperator<ParticleArray<dimension>, splitType, Splitter_t>;

public:
/**
Expand All @@ -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))}
Expand All @@ -97,10 +101,7 @@ class BasicHierarchy
dimension_, "ChopAndPackLoadBalancer",
inputDatabase_->getDatabase("ChopAndPackLoadBalancer"))}

, refineOperator_{std::make_shared<
ParticlesRefineOperator<ParticleArray<dimension>, splitType,
Splitter<DimConst<dimension>, InterpConst<interpOrder>,
RefinedParticlesConst<refinedParticlesNbr>>>>()}
, refineOperator_{std::make_shared<ParticlesRefineOperator_t>()}


, tagStrategy_{std::make_shared<TagStrategy<dimension>>(variablesIds_, refineOperator_,
Expand Down Expand Up @@ -167,6 +168,11 @@ class BasicHierarchy

SAMRAI::hier::IntVector const ratio;

auto domainParticlesForLevel(int levelNumber) const
{
return tagStrategy_->domainParticlesForLevel(hierarchy_, levelNumber);
}

private:
std::map<std::string, int> getVariablesIds_()
{
Expand Down
22 changes: 20 additions & 2 deletions tests/amr/data/particles/refine/test_split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#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"


namespace
{
template<std::size_t dimension, std::size_t interpOrder, std::size_t refineParticlesNbr>
using Splitter
using Splitter_t
= PHARE::amr::Splitter<PHARE::core::DimConst<dimension>, PHARE::core::InterpConst<interpOrder>,
PHARE::core::RefinedParticlesConst<refineParticlesNbr>>;

Expand All @@ -22,7 +24,7 @@ struct SplitterTest : public ::testing::Test
SplitterTest() { Splitter splitter; }
};

using Splitters = testing::Types<Splitter<1, 1, 2>, Splitter<2, 1, 8> /*, Splitter<3, 1, 27>*/>;
using Splitters = testing::Types<Splitter_t<1, 1, 2>, Splitter_t<2, 1, 8> /*, Splitter<3, 1, 27>*/>;

TYPED_TEST_SUITE(SplitterTest, Splitters);

Expand All @@ -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);
}

0 comments on commit 8c4fa42

Please sign in to comment.