Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hierarchy views #787

Closed
wants to merge 4 commits into from
Closed
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: 1 addition & 1 deletion res/cmake/dep.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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
6 changes: 4 additions & 2 deletions src/amr/data/field/field_data.hpp
Original file line number Diff line number Diff line change
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!
}

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



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


static GridLayoutT const& getLayout(SAMRAI::hier::Patch const& patch, int id)
Expand Down
55 changes: 35 additions & 20 deletions src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,43 @@ namespace amr

// this structure is a wrapper of a field*
// so to serve as a ResourcesUser for the ResourcesManager
template<typename FieldT>
template<typename GridT>
struct FieldUser
{
using grid_type = GridT;
using field_type = typename GridT::field_type;

struct Property
{
std::string name;
typename PHARE::core::HybridQuantity::Scalar qty;
};
FieldUser(std::string fieldName, FieldT* ptr,

FieldUser(std::string fieldName, field_type* ptr,
typename PHARE::core::HybridQuantity::Scalar qty)
: name{fieldName}
, f{ptr}
, quantity{qty}
{
}
std::string name;
FieldT* f;
typename PHARE::core::HybridQuantity::Scalar quantity;
using field_type = FieldT;

std::vector<Property> getFieldNamesAndQuantities() const { return {{name, quantity}}; }

void setBuffer(std::string const& /*bufferName*/, FieldT* field) { f = field; }
void copyData(FieldT const& source) { f->copyData(source); }
void setBuffer(std::string const& /*bufferName*/, field_type* field)
{
f = field;
}

template<typename That>
void copyData(That const& that)
{
assert(f);
f->copyData(that);
}

std::string name;
field_type* f{nullptr};
typename PHARE::core::HybridQuantity::Scalar quantity;
};


Expand All @@ -82,29 +95,31 @@ namespace amr
template<typename HybridModel, typename RefinementParams>
class HybridHybridMessengerStrategy : public HybridMessengerStrategy<HybridModel>
{
using IonsT = typename HybridModel::ions_type;
using ElectromagT = typename HybridModel::electromag_type;
using VecFieldT = typename HybridModel::vecfield_type;
using GridLayoutT = typename HybridModel::gridlayout_type;
using FieldT = typename VecFieldT::field_type;
using ResourcesManagerT = typename HybridModel::resources_manager_type;
using GridT = typename HybridModel::grid_type;
using IonsT = typename HybridModel::ions_type;
using ElectromagT = typename HybridModel::electromag_type;
using VecFieldT = typename HybridModel::vecfield_type;
using GridLayoutT = typename HybridModel::gridlayout_type;
using FieldT = typename VecFieldT::field_type;
using ResourcesManagerT = typename HybridModel::resources_manager_type;
using IPhysicalModel = typename HybridModel::Interface;

static constexpr std::size_t dimension = GridLayoutT::dimension;
static constexpr std::size_t interpOrder = GridLayoutT::interp_order;
using IPhysicalModel = typename HybridModel::Interface;

using InteriorParticleRefineOp = typename RefinementParams::InteriorParticleRefineOp;
using CoarseToFineRefineOpOld = typename RefinementParams::CoarseToFineRefineOpOld;
using CoarseToFineRefineOpNew = typename RefinementParams::CoarseToFineRefineOpNew;

template<typename Policy>
using BaseRefineOp = FieldRefineOperator<GridLayoutT, FieldT, Policy>;
using BaseRefineOp = FieldRefineOperator<GridLayoutT, GridT, Policy>;
using DefaultFieldRefineOp = BaseRefineOp<DefaultFieldRefiner<dimension>>;
using MagneticFieldRefineOp = BaseRefineOp<MagneticFieldRefiner<dimension>>;
using ElectricFieldRefineOp = BaseRefineOp<ElectricFieldRefiner<dimension>>;
using FieldTimeInterp = FieldLinearTimeInterpolate<GridLayoutT, FieldT>;
using FieldTimeInterp = FieldLinearTimeInterpolate<GridLayoutT, GridT>;

template<typename Policy>
using BaseCoarsenOp = FieldCoarsenOperator<GridLayoutT, FieldT, Policy>;
using BaseCoarsenOp = FieldCoarsenOperator<GridLayoutT, GridT, Policy>;
using MagneticCoarsenOp = BaseCoarsenOp<MagneticFieldCoarsener<dimension>>;
using DefaultCoarsenOp = BaseCoarsenOp<DefaultFieldCoarsener<dimension>>;

Expand Down Expand Up @@ -991,8 +1006,8 @@ namespace amr
VecFieldT Jold_{stratName + "_Jold", core::HybridQuantity::Vector::J};
VecFieldT ViOld_{stratName + "_VBulkOld", core::HybridQuantity::Vector::V};
FieldT* NiOld_{nullptr};
FieldUser<FieldT> NiOldUser_{stratName + "_NiOld", NiOld_,
core::HybridQuantity::Scalar::rho};
FieldUser<GridT> NiOldUser_{stratName + "_NiOld", NiOld_,
core::HybridQuantity::Scalar::rho};


//! ResourceManager shared with other objects (like the HybridModel)
Expand Down
16 changes: 15 additions & 1 deletion src/amr/multiphysics_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ namespace solver

levelInitializer.initialize(hierarchy, levelNumber, oldLevel, model, messenger,
initDataTime, isRegridding);

if (static_cast<std::size_t>(levelNumber) == model_views_.size())
model_views_.push_back(solver.make_view(*level, model));
else
model_views_[levelNumber] = solver.make_view(*level, model);
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't super sure of the point of the level descriptor system here so I didn't use it.

That might very well be an issue for future usage with varying solvers between levels, tbc

}


Expand All @@ -360,7 +365,11 @@ namespace solver
{
auto& messenger = getMessengerWithCoarser_(coarsestLevel);
for (auto ilvl = coarsestLevel; ilvl <= finestLevel; ++ilvl)
{
messenger.registerLevel(hierarchy, ilvl);
model_views_.push_back(getSolver_(ilvl).make_view(
AMR_Types::getLevel(*hierarchy, ilvl), getModel_(ilvl)));
}
restartInitialized_ = true;
}
}
Expand Down Expand Up @@ -486,7 +495,8 @@ namespace solver

fromCoarser.prepareStep(model, *level, currentTime);

solver.advanceLevel(hierarchy, iLevel, model, fromCoarser, currentTime, newTime);
solver.advanceLevel(*hierarchy, iLevel, getModelView_(iLevel), fromCoarser, currentTime,
newTime);

if (lastStep)
{
Expand Down Expand Up @@ -565,6 +575,9 @@ namespace solver
std::vector<LevelDescriptor> levelDescriptors_;
std::vector<std::unique_ptr<ISolver<AMR_Types>>> solvers_;
std::vector<std::shared_ptr<IPhysicalModel<AMR_Types>>> models_;

std::vector<std::shared_ptr<ISolverModelView>> model_views_;

std::vector<std::shared_ptr<PHARE::amr::Tagger>> taggers_;
std::map<std::string, std::unique_ptr<IMessengerT>> messengers_;
std::map<std::string, std::unique_ptr<LevelInitializerT>> levelInitializers_;
Expand Down Expand Up @@ -791,6 +804,7 @@ namespace solver
}


auto& getModelView_(int iLevel) { return *model_views_[iLevel]; }


IPhysicalModel<AMR_Types>& getModel_(int iLevel)
Expand Down
22 changes: 13 additions & 9 deletions src/amr/physical_models/hybrid_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

#include "initializer/data_provider.hpp"
#include "core/data/grid/grid.hpp" // !?!
#include "core/models/hybrid_state.hpp"
#include "amr/physical_models/physical_model.hpp"
#include "core/data/ions/particle_initializers/particle_initializer_factory.hpp"
Expand All @@ -23,23 +24,26 @@ template<typename GridLayoutT, typename Electromag, typename Ions, typename Elec
class HybridModel : public IPhysicalModel<AMR_Types>
{
public:
static constexpr auto dimension = GridLayoutT::dimension;
using type_list = PHARE::core::type_list<GridLayoutT, Electromag, Ions, Electrons, AMR_Types>;
using Interface = IPhysicalModel<AMR_Types>;
using amr_types = AMR_Types;
using patch_t = typename AMR_Types::patch_t;
using level_t = typename AMR_Types::level_t;
static const std::string model_name;
using gridlayout_type = GridLayoutT;
using electromag_type = Electromag;
using vecfield_type = typename Electromag::vecfield_type;
using field_type = typename vecfield_type::field_type;
using ions_type = Ions;
using particle_array_type = typename Ions::particle_array_type;
using resources_manager_type = amr::ResourcesManager<gridlayout_type>;
static constexpr auto dimension = GridLayoutT::dimension;
using gridlayout_type = GridLayoutT;
using electromag_type = Electromag;
using vecfield_type = typename Electromag::vecfield_type;
using field_type = typename vecfield_type::field_type;
using grid_type = core::Grid<core::NdArrayVector<dimension, typename field_type::value_type>,
typename field_type::physical_quantity_type>;
using ions_type = Ions;
using particle_array_type = typename Ions::particle_array_type;
using resources_manager_type = amr::ResourcesManager<gridlayout_type>;
using ParticleInitializerFactory
= core::ParticleInitializerFactory<particle_array_type, gridlayout_type>;

static const std::string model_name;


core::HybridState<Electromag, Ions, Electrons> state;
std::shared_ptr<resources_manager_type> resourcesManager;
Expand Down
4 changes: 2 additions & 2 deletions src/amr/resources_manager/field_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace amr
template<typename ResourcesUser, typename GridLayoutT>
struct UserFieldType
{
using patch_data_type = FieldData<GridLayoutT, typename ResourcesUser::field_type>;
using variable_type = FieldVariable<GridLayoutT, typename ResourcesUser::field_type>;
using patch_data_type = FieldData<GridLayoutT, typename ResourcesUser::grid_type>;
using variable_type = FieldVariable<GridLayoutT, typename ResourcesUser::grid_type>;
using internal_type_ptr = typename ResourcesUser::field_type*;
Copy link

Choose a reason for hiding this comment

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

The internal_type_ptr type alias still references typename ResourcesUser::field_type. If the transition from Field to Grid is complete, this might be an oversight and should be updated to use grid_type instead.

-        using internal_type_ptr = typename ResourcesUser::field_type*;
+        using internal_type_ptr = typename ResourcesUser::grid_type*;

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
using internal_type_ptr = typename ResourcesUser::field_type*;
using internal_type_ptr = typename ResourcesUser::grid_type*;

};

Expand Down
7 changes: 3 additions & 4 deletions src/amr/resources_manager/resources_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ namespace amr
template<typename ResourcesUser>
NO_DISCARD auto restart_patch_data_ids(ResourcesUser const& user) const
{
// // true for now with https://github.com/PHAREHUB/PHARE/issues/664
// true for now with https://github.com/PHAREHUB/PHARE/issues/664
constexpr bool ALL_IDS = true;

std::vector<int> ids;
Expand Down Expand Up @@ -571,9 +571,8 @@ namespace amr

//! \brief Allocate the data on the given level
template<typename ResourcesUser, typename ResourcesProperties>
void allocate_([[maybe_unused]] ResourcesUser const& obj,
ResourcesProperties const& resourcesProperties, SAMRAI::hier::Patch& patch,
double const allocateTime) const
void allocate_(ResourcesUser const& /*obj*/, ResourcesProperties const& resourcesProperties,
SAMRAI::hier::Patch& patch, double const allocateTime) const
{
for (auto const& properties : resourcesProperties)
{
Expand Down
28 changes: 25 additions & 3 deletions src/amr/solvers/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
#include "amr/physical_models/physical_model.hpp"
#include "core/def.hpp"

namespace PHARE::solver
{


class ISolverModelView
{
public:
using This = ISolverModelView;

virtual ~ISolverModelView() = default;
};


} // namespace PHARE::solver



namespace PHARE
Expand All @@ -29,6 +44,10 @@ namespace solver
class ISolver
{
public:
using patch_t = typename AMR_Types::patch_t;
using level_t = typename AMR_Types::level_t;
using hierarchy_t = typename AMR_Types::hierarchy_t;

/**
* @brief return the name of the ISolver
*/
Expand Down Expand Up @@ -67,8 +86,8 @@ namespace solver
/**
* @brief advanceLevel advances the given level from t to t+dt
*/
virtual void advanceLevel(std::shared_ptr<SAMRAI::hier::PatchHierarchy> const& hierarchy,
int const levelNumber, IPhysicalModel<AMR_Types>& model,
virtual void advanceLevel(hierarchy_t const& hierarchy, int const levelNumber,
ISolverModelView& view,
amr::IMessenger<IPhysicalModel<AMR_Types>>& fromCoarser,
const double currentTime, const double newTime)
= 0;
Expand All @@ -80,7 +99,7 @@ namespace solver
* @brief allocate is used to allocate ISolver variables previously registered to the
* ResourcesManager of the given model, onto the given Patch, at the given time.
*/
virtual void allocate(IPhysicalModel<AMR_Types>& model, SAMRAI::hier::Patch& patch,
virtual void allocate(IPhysicalModel<AMR_Types>& model, patch_t& patch,
double const allocateTime) const = 0;


Expand All @@ -89,6 +108,9 @@ namespace solver
virtual ~ISolver() = default;


virtual std::shared_ptr<ISolverModelView> make_view(level_t&, IPhysicalModel<AMR_Types>&)
= 0;

protected:
explicit ISolver(std::string name)
: solverName{std::move(name)}
Comment on lines 115 to 116
Copy link

Choose a reason for hiding this comment

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

The solverName member variable should be private or protected to maintain encapsulation. Public member variables can lead to less control over the state and behavior of an object.

-        std::string solverName;
+    protected:
+        std::string solverName;

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
explicit ISolver(std::string name)
: solverName{std::move(name)}
explicit ISolver(std::string name)
: solverName{std::move(name)}
protected:
std::string solverName;

Expand Down
21 changes: 15 additions & 6 deletions src/amr/solvers/solver_mhd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace solver
class SolverMHD : public ISolver<AMR_Types>
{
public:
using patch_t = typename AMR_Types::patch_t;
using level_t = typename AMR_Types::level_t;
using hierarchy_t = typename AMR_Types::hierarchy_t;

SolverMHD()
: ISolver<AMR_Types>{"MHDSolver"}
{
Expand All @@ -34,17 +38,22 @@ namespace solver
virtual void registerResources(IPhysicalModel<AMR_Types>& /*model*/) override {}

// TODO make this a resourcesUser
virtual void allocate(IPhysicalModel<AMR_Types>& /*model*/, SAMRAI::hier::Patch& /*patch*/,
virtual void allocate(IPhysicalModel<AMR_Types>& /*model*/, patch_t& /*patch*/,
double const /*allocateTime*/) const override
{
}

virtual void
advanceLevel(std::shared_ptr<SAMRAI::hier::PatchHierarchy> const& /*hierarchy*/,
int const /*levelNumber*/, IPhysicalModel<AMR_Types>& /*model*/,
amr::IMessenger<IPhysicalModel<AMR_Types>>& /*fromCoarser*/,
const double /*currentTime*/, const double /*newTime*/) override
virtual void advanceLevel(hierarchy_t const& /*hierarchy*/, int const /*levelNumber*/,
ISolverModelView& /*view*/,
amr::IMessenger<IPhysicalModel<AMR_Types>>& /*fromCoarser*/,
const double /*currentTime*/, const double /*newTime*/) override
{
}

std::shared_ptr<ISolverModelView> make_view(level_t&, IPhysicalModel<AMR_Types>&) override
{
throw std::runtime_error("Not implemented in mhd solver");
return nullptr;
}
};
} // namespace solver
Expand Down
Loading
Loading