Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions res/cmake/bench.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ if (bench)
add_subdirectory(tools/bench/core/numerics/pusher)

add_subdirectory(tools/bench/amr/data/particles)
add_subdirectory(tools/bench/core/numerics/ion_updater)
add_subdirectory(tools/bench/core/numerics/interpolator)

add_subdirectory(tools/bench/hi5)
add_subdirectory(tools/bench/real)
Expand Down
2 changes: 1 addition & 1 deletion res/cmake/dep.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include("${PHARE_PROJECT_DIR}/res/cmake/dep/samrai.cmake")

# caliper build option
# enabled with -DCALIPER_ROOT=/path/to/caliper
# or -DwithCaliper, which dowloads to subprojects dir
# or -DwithCaliper, which downloads to subprojects dir
include("${PHARE_PROJECT_DIR}/res/cmake/dep/caliper.cmake")

# pybind
Expand Down
2 changes: 1 addition & 1 deletion res/cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests


add_subdirectory(tests/core/data/ndarray)
add_subdirectory(tests/core/data/field)
add_subdirectory(tests/core/data/grid)
add_subdirectory(tests/core/data/gridlayout)
add_subdirectory(tests/core/data/vecfield)
add_subdirectory(tests/core/data/particles)
Expand Down
76 changes: 39 additions & 37 deletions src/amr/data/field/field_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace amr
// We use another class here so that we can specialize specifics function: copy , pack , unpack
// on the dimension and we don't want to loose non specialized function related to SAMRAI
// interface
template<typename GridLayoutT, std::size_t dim, typename FieldImpl,
typename PhysicalQuantity = decltype(std::declval<FieldImpl>().physicalQuantity())>
template<typename GridLayoutT, std::size_t dim, typename Grid_t,
typename PhysicalQuantity = decltype(std::declval<Grid_t>().physicalQuantity())>
class FieldDataInternals
{
};
Expand All @@ -36,8 +36,8 @@ namespace amr
/**@brief FieldData is the specialization of SAMRAI::hier::PatchData to Field objects
*
*/
template<typename GridLayoutT, typename FieldImpl,
typename PhysicalQuantity = decltype(std::declval<FieldImpl>().physicalQuantity())>
template<typename GridLayoutT, typename Grid_t,
typename PhysicalQuantity = decltype(std::declval<Grid_t>().physicalQuantity())>
class FieldData : public SAMRAI::hier::PatchData
{
using Super = SAMRAI::hier::PatchData;
Expand Down Expand Up @@ -86,7 +86,9 @@ namespace amr
{
Super::getFromRestart(restart_db);

restart_db->getVector("field_" + field.name(), field.vector());
assert(field.vector().size() > 0);
restart_db->getDoubleArray("field_" + field.name(), field.vector().data(),
field.vector().size()); // do not reallocate!
Comment on lines +89 to +91
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of the assertion on line 89 is good for ensuring that the vector is not empty before attempting to populate it. However, consider adding a more descriptive error message to the assertion for better debugging.

assert(field.vector().size() > 0 && "Field vector must not be empty before data retrieval.");

The change to getDoubleArray is a performance improvement as it avoids reallocation. Ensure that the size of field.vector() is correctly set before this operation to prevent buffer overruns.

}

void putToRestart(std::shared_ptr<SAMRAI::tbox::Database> const& restart_db) const override
Expand Down Expand Up @@ -224,7 +226,7 @@ namespace amr

// getDataStreamSize_<true> mean that we want to apply the transformation
std::size_t expectedSize = getDataStreamSize_<true>(overlap) / sizeof(double);
std::vector<typename FieldImpl::type> buffer;
std::vector<typename Grid_t::type> buffer;
buffer.reserve(expectedSize);

auto& fieldOverlap = dynamic_cast<FieldOverlap const&>(overlap);
Expand Down Expand Up @@ -309,13 +311,13 @@ namespace amr



FieldImpl* getPointer() { return &field; }
auto* getPointer() { return &field; }


static GridLayoutT const& getLayout(SAMRAI::hier::Patch const& patch, int id)
{
auto const& patchData = std::dynamic_pointer_cast<FieldData<GridLayoutT, FieldImpl>>(
patch.getPatchData(id));
auto const& patchData
= std::dynamic_pointer_cast<FieldData<GridLayoutT, Grid_t>>(patch.getPatchData(id));
if (!patchData)
{
throw std::runtime_error("cannot cast to FieldData");
Expand All @@ -324,10 +326,10 @@ namespace amr
}


static FieldImpl& getField(SAMRAI::hier::Patch const& patch, int id)
static Grid_t& getField(SAMRAI::hier::Patch const& patch, int id)
{
auto const& patchData = std::dynamic_pointer_cast<FieldData<GridLayoutT, FieldImpl>>(
patch.getPatchData(id));
auto const& patchData
= std::dynamic_pointer_cast<FieldData<GridLayoutT, Grid_t>>(patch.getPatchData(id));
if (!patchData)
{
throw std::runtime_error("cannot cast to FieldData");
Expand All @@ -339,7 +341,7 @@ namespace amr


GridLayoutT gridLayout;
FieldImpl field;
Grid_t field;

private:
PhysicalQuantity quantity_; ///! PhysicalQuantity used for this field data
Expand All @@ -352,8 +354,8 @@ namespace amr
*/
void copy_(SAMRAI::hier::Box const& intersectBox, SAMRAI::hier::Box const& sourceBox,
SAMRAI::hier::Box const& destinationBox,
[[maybe_unused]] FieldData const& source, FieldImpl const& fieldSource,
FieldImpl& fieldDestination)
[[maybe_unused]] FieldData const& source, Grid_t const& fieldSource,
Grid_t& fieldDestination)
{
// First we represent the intersection that is defined in AMR space to the local space
// of the source
Expand Down Expand Up @@ -411,8 +413,8 @@ namespace amr

if (!intersectionBox.empty())
{
FieldImpl const& sourceField = source.field;
FieldImpl& destinationField = field;
Grid_t const& sourceField = source.field;
Grid_t& destinationField = field;

copy_(intersectionBox, transformedSource, destinationBox, source,
sourceField, destinationField);
Expand Down Expand Up @@ -451,23 +453,23 @@ namespace amr
SAMRAI::hier::BoxContainer const& boxContainer
= fieldOverlap.getDestinationBoxContainer();

return boxContainer.getTotalSizeOfBoxes() * sizeof(typename FieldImpl::type);
return boxContainer.getTotalSizeOfBoxes() * sizeof(typename Grid_t::type);
}


FieldDataInternals<GridLayoutT, dimension, FieldImpl, PhysicalQuantity> internals_;
FieldDataInternals<GridLayoutT, dimension, Grid_t, PhysicalQuantity> internals_;
}; // namespace PHARE




// 1D internals implementation
template<typename GridLayoutT, typename FieldImpl, typename PhysicalQuantity>
class FieldDataInternals<GridLayoutT, 1, FieldImpl, PhysicalQuantity>
template<typename GridLayoutT, typename Grid_t, typename PhysicalQuantity>
class FieldDataInternals<GridLayoutT, 1, Grid_t, PhysicalQuantity>
{
public:
void copyImpl(SAMRAI::hier::Box const& localSourceBox, FieldImpl const& source,
SAMRAI::hier::Box const& localDestinationBox, FieldImpl& destination) const
void copyImpl(SAMRAI::hier::Box const& localSourceBox, Grid_t const& source,
SAMRAI::hier::Box const& localDestinationBox, Grid_t& destination) const
{
std::uint32_t xSourceStart = static_cast<std::uint32_t>(localSourceBox.lower(0));
std::uint32_t xDestinationStart
Expand All @@ -487,7 +489,7 @@ namespace amr



void packImpl(std::vector<double>& buffer, FieldImpl const& source,
void packImpl(std::vector<double>& buffer, Grid_t const& source,
SAMRAI::hier::Box const& overlap, SAMRAI::hier::Box const& sourceBox) const
{
int xStart = overlap.lower(0) - sourceBox.lower(0);
Expand All @@ -501,7 +503,7 @@ namespace amr



void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, FieldImpl& source,
void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, Grid_t& source,
SAMRAI::hier::Box const& overlap,
SAMRAI::hier::Box const& destination) const
{
Expand All @@ -519,12 +521,12 @@ namespace amr


// 2D internals implementation
template<typename GridLayoutT, typename FieldImpl, typename PhysicalQuantity>
class FieldDataInternals<GridLayoutT, 2, FieldImpl, PhysicalQuantity>
template<typename GridLayoutT, typename Grid_t, typename PhysicalQuantity>
class FieldDataInternals<GridLayoutT, 2, Grid_t, PhysicalQuantity>
{
public:
void copyImpl(SAMRAI::hier::Box const& localSourceBox, FieldImpl const& source,
SAMRAI::hier::Box const& localDestinationBox, FieldImpl& destination) const
void copyImpl(SAMRAI::hier::Box const& localSourceBox, Grid_t const& source,
SAMRAI::hier::Box const& localDestinationBox, Grid_t& destination) const
{
std::uint32_t xSourceStart = static_cast<std::uint32_t>(localSourceBox.lower(0));
std::uint32_t xDestinationStart
Expand Down Expand Up @@ -558,7 +560,7 @@ namespace amr



void packImpl(std::vector<double>& buffer, FieldImpl const& source,
void packImpl(std::vector<double>& buffer, Grid_t const& source,
SAMRAI::hier::Box const& overlap, SAMRAI::hier::Box const& destination) const

{
Expand All @@ -580,7 +582,7 @@ namespace amr



void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, FieldImpl& source,
void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, Grid_t& source,
SAMRAI::hier::Box const& overlap,
SAMRAI::hier::Box const& destination) const
{
Expand All @@ -604,12 +606,12 @@ namespace amr


// 3D internals implementation
template<typename GridLayoutT, typename FieldImpl, typename PhysicalQuantity>
class FieldDataInternals<GridLayoutT, 3, FieldImpl, PhysicalQuantity>
template<typename GridLayoutT, typename Grid_t, typename PhysicalQuantity>
class FieldDataInternals<GridLayoutT, 3, Grid_t, PhysicalQuantity>
{
public:
void copyImpl(SAMRAI::hier::Box const& localSourceBox, FieldImpl const& source,
SAMRAI::hier::Box const& localDestinationBox, FieldImpl& destination) const
void copyImpl(SAMRAI::hier::Box const& localSourceBox, Grid_t const& source,
SAMRAI::hier::Box const& localDestinationBox, Grid_t& destination) const
{
std::uint32_t xSourceStart = static_cast<std::uint32_t>(localSourceBox.lower(0));
std::uint32_t xDestinationStart
Expand Down Expand Up @@ -657,7 +659,7 @@ namespace amr



void packImpl(std::vector<double>& buffer, FieldImpl const& source,
void packImpl(std::vector<double>& buffer, Grid_t const& source,
SAMRAI::hier::Box const& overlap, SAMRAI::hier::Box const& destination) const
{
int xStart = overlap.lower(0) - destination.lower(0);
Expand All @@ -684,7 +686,7 @@ namespace amr



void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, FieldImpl& source,
void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, Grid_t& source,
SAMRAI::hier::Box const& overlap,
SAMRAI::hier::Box const& destination) const
{
Expand Down
16 changes: 11 additions & 5 deletions src/amr/data/particles/particles_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,27 @@ namespace amr
static constexpr int ghostSafeMapLayer = 1;

public:
ParticlesData(SAMRAI::hier::Box const& box, SAMRAI::hier::IntVector const& ghost)
ParticlesData(SAMRAI::hier::Box const& box, SAMRAI::hier::IntVector const& ghost,
std::string const& name)
: SAMRAI::hier::PatchData::PatchData(box, ghost)
, domainParticles{grow(phare_box_from<dim>(getGhostBox()), ghostSafeMapLayer)}
, patchGhostParticles{grow(phare_box_from<dim>(getGhostBox()), ghostSafeMapLayer)}
, levelGhostParticles{grow(phare_box_from<dim>(getGhostBox()), ghostSafeMapLayer)}
, levelGhostParticlesOld{grow(phare_box_from<dim>(getGhostBox()), ghostSafeMapLayer)}
, levelGhostParticlesNew{grow(phare_box_from<dim>(getGhostBox()), ghostSafeMapLayer)}
, pack{&domainParticles, &patchGhostParticles, &levelGhostParticles,
&levelGhostParticlesOld, &levelGhostParticlesNew}
, pack{name,
&domainParticles,
&patchGhostParticles,
&levelGhostParticles,
&levelGhostParticlesOld,
&levelGhostParticlesNew}
, interiorLocalBox_{AMRToLocal(box, this->getGhostBox())}
, name_{name}
{
}



auto& name() const { return name_; }

ParticlesData() = delete;
ParticlesData(ParticlesData const&) = delete;
Expand Down Expand Up @@ -441,12 +447,12 @@ namespace amr
core::ParticlesPack<ParticleArray> pack;



private:
//! interiorLocalBox_ is the box, in local index space, that goes from the first to the last
//! cell in our patch physical domain, i.e. "from dual physical start index to dual physical
//! end index"
SAMRAI::hier::Box interiorLocalBox_;
std::string name_;

void copy_(SAMRAI::hier::Box const& overlapBox, ParticlesData const& sourceData)
{
Expand Down
14 changes: 7 additions & 7 deletions src/amr/data/particles/particles_data_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ namespace amr

// SAMRAI interface

ParticlesDataFactory(SAMRAI::hier::IntVector ghost, bool fineBoundaryRepresentsVariable)
ParticlesDataFactory(SAMRAI::hier::IntVector ghost, bool fineBoundaryRepresentsVariable,
std::string const& name)
: SAMRAI::hier::PatchDataFactory{ghost}
, fineBoundaryRepresentsVariable_{fineBoundaryRepresentsVariable}
, name_{name}
{
}

std::shared_ptr<SAMRAI::hier::PatchDataFactory>
cloneFactory(SAMRAI::hier::IntVector const&) final
{
return std::make_shared<ParticlesDataFactory>(d_ghosts,
fineBoundaryRepresentsVariable_);
return std::make_shared<ParticlesDataFactory>(d_ghosts, fineBoundaryRepresentsVariable_,
name_);
}

std::shared_ptr<SAMRAI::hier::PatchData>
allocate(const SAMRAI::hier::Patch& patch) const final
{
return std::make_shared<ParticlesData<ParticleArray>>(patch.getBox(), d_ghosts);
return std::make_shared<ParticlesData<ParticleArray>>(patch.getBox(), d_ghosts, name_);
}

std::shared_ptr<SAMRAI::hier::BoxGeometry>
Expand Down Expand Up @@ -77,9 +79,7 @@ namespace amr
// End SAMRAI interface
private:
bool fineBoundaryRepresentsVariable_;


private:
std::string const name_;
};
} // namespace amr

Expand Down
2 changes: 1 addition & 1 deletion src/amr/data/particles/particles_variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace amr
= SAMRAI::hier::IntVector{SAMRAI::tbox::Dimension{dim},
core::ghostWidthForParticles<interp>()})
: SAMRAI::hier::Variable{name, std::make_shared<ParticlesDataFactory<ParticleArray>>(
ghost, fineBoundaryRepresentsVariable)}
ghost, fineBoundaryRepresentsVariable, name)}
, fineBoundaryRepresentsVariable_{fineBoundaryRepresentsVariable}
{
}
Expand Down
Loading