diff --git a/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp b/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp index ab93c7ea2..ec50a51e9 100644 --- a/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp +++ b/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp @@ -3,7 +3,7 @@ #ifndef PHARE_CONCRERTE_LOAD_BALANCER_HYBRID_STRATEGY_HOMOGENEOUS_HPP #define PHARE_CONCRERTE_LOAD_BALANCER_HYBRID_STRATEGY_HOMOGENEOUS_HPP -#include + #include #include @@ -24,14 +24,16 @@ class ConcreteLoadBalancerHybridStrategyHomogeneous : public LoadBalancerHybridS public: using HybridModel = typename PHARE_T::HybridModel_t; using gridlayout_type = typename HybridModel::gridlayout_type; + using amr_types = typename HybridModel::amr_types; + using level_t = typename amr_types::level_t; + using cell_data_t = SAMRAI::pdat::CellData; ConcreteLoadBalancerHybridStrategyHomogeneous(int const id) : id_{id} { } - void compute(SAMRAI::hier::PatchLevel& level, - PHARE::solver::IPhysicalModel& model) override; + void compute(level_t& level, PHARE::solver::IPhysicalModel& model) override; private: @@ -42,27 +44,25 @@ class ConcreteLoadBalancerHybridStrategyHomogeneous : public LoadBalancerHybridS template void ConcreteLoadBalancerHybridStrategyHomogeneous::compute( - SAMRAI::hier::PatchLevel& level, PHARE::solver::IPhysicalModel& model) + level_t& level, PHARE::solver::IPhysicalModel& model) { - static auto constexpr dimension = HybridModel::dimension; - auto& hybridModel = dynamic_cast(model); - auto& resourcesManager = hybridModel.resourcesManager; - auto& ions = hybridModel.state.ions; + auto static constexpr dimension = HybridModel::dimension; + bool static constexpr c_ordering = false; - bool constexpr c_ordering = false; + auto& hybridModel = dynamic_cast(model); + auto& resourcesManager = hybridModel.resourcesManager; + auto& ions = hybridModel.state.ions; for (auto& patch : level) { auto const& layout = layoutFromPatch(*patch); - auto patch_data_lb - = dynamic_cast*>(patch->getPatchData(this->id_).get()); + auto patch_data_lb = dynamic_cast(patch->getPatchData(this->id_).get()); auto load_balancer_val = patch_data_lb->getPointer(); - const auto& box = patch->getBox(); + auto const& box = patch->getBox(); - auto lb_view = core::NdArrayView(load_balancer_val, - layout.nbrCells()); + auto lb_view = core::make_array_view(load_balancer_val, layout.nbrCells()); auto _ = resourcesManager->setOnPatch(*patch, ions); @@ -73,64 +73,17 @@ void ConcreteLoadBalancerHybridStrategyHomogeneous::compute( // to get the AMRLocatStart and AMRLocalEnd. // Then, we build "by hand" the local index for the "lb_view" considering that the nbr // of ghost cell for this patch data is null. - auto amr_box = layout.AMRBox(); + auto const amr_box = layout.AMRBox(); // The lb_view is a CellData, meaning that it is dual as the index of an amr box - auto amr_start = amr_box.lower; - auto amr_end = amr_box.upper; - - // nbr of cells in the physical domain - auto nbrCells = layout.nbrCells(); - - - - - if constexpr (dimension == 1) - { - for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - { - auto amr_point{core::Point{i_amr}}; - auto amr_index = amr_point.template toArray(); - - lb_view(i_loc) = 1; - } - } - - - - if constexpr (dimension == 2) - { - for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - { - for (auto j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr) - { - auto amr_point{core::Point{i_amr, j_amr}}; - auto amr_index = amr_point.template toArray(); - - lb_view(i_loc, j_loc) = 1; - std::cout << lb_view(i_loc, j_loc) << std::endl; - } - } - } - - if constexpr (dimension == 3) - { - for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - { - for (auto j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr) - { - for (auto k_loc = 0, k_amr = amr_start[2]; k_loc < nbrCells[2]; - ++k_loc, ++k_amr) - { - auto amr_point{core::Point{i_amr, j_amr, k_amr}}; - auto amr_index = amr_point.template toArray(); + core::Box local_box{ + core::Point{core::ConstArray()}, + core::Point{ + core::generate([](auto const& nCell) { return nCell - 1; }, layout.nbrCells())}}; - lb_view(i_loc, j_loc, k_loc) = 1; - } - } - } - } + for (auto const& idx : local_box) + lb_view(idx) = 1; } } diff --git a/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp b/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp index 6965a0f1a..3eea54a7a 100644 --- a/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp +++ b/src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp @@ -8,11 +8,14 @@ #include +#include "core/logger.hpp" +#include "core/utilities/types.hpp" +#include "core/data/ndarray/ndarray_vector.hpp" + +#include "amr/types/amr_types.hpp" #include "amr/load_balancing/load_balancer_hybrid_strategy.hpp" #include "amr/physical_models/physical_model.hpp" -#include "amr/types/amr_types.hpp" #include "amr/resources_manager/amr_utils.hpp" -#include "core/data/ndarray/ndarray_vector.hpp" @@ -25,14 +28,16 @@ class ConcreteLoadBalancerHybridStrategyNPPC : public LoadBalancerHybridStrategy public: using HybridModel = typename PHARE_T::HybridModel_t; using gridlayout_type = typename HybridModel::gridlayout_type; + using amr_types = typename HybridModel::amr_types; + using level_t = typename amr_types::level_t; + using cell_data_t = SAMRAI::pdat::CellData; ConcreteLoadBalancerHybridStrategyNPPC(int const id) : id_{id} { } - void compute(SAMRAI::hier::PatchLevel& level, - PHARE::solver::IPhysicalModel& model) override; + void compute(level_t& level, PHARE::solver::IPhysicalModel& model) override; private: @@ -43,7 +48,7 @@ class ConcreteLoadBalancerHybridStrategyNPPC : public LoadBalancerHybridStrategy template void ConcreteLoadBalancerHybridStrategyNPPC::compute( - SAMRAI::hier::PatchLevel& level, PHARE::solver::IPhysicalModel& model) + level_t& level, PHARE::solver::IPhysicalModel& model) { static auto constexpr dimension = HybridModel::dimension; auto& hybridModel = dynamic_cast(model); @@ -56,11 +61,10 @@ void ConcreteLoadBalancerHybridStrategyNPPC::compute( { auto const& layout = layoutFromPatch(*patch); - auto patch_data_lb - = dynamic_cast*>(patch->getPatchData(this->id_).get()); + auto patch_data_lb = dynamic_cast(patch->getPatchData(this->id_).get()); auto load_balancer_val = patch_data_lb->getPointer(); - const auto& box = patch->getBox(); + auto const& box = patch->getBox(); auto lb_view = core::NdArrayView(load_balancer_val, layout.nbrCells()); @@ -74,98 +78,29 @@ void ConcreteLoadBalancerHybridStrategyNPPC::compute( // to get the AMRLocatStart and AMRLocalEnd. // Then, we build "by hand" the local index for the "lb_view" considering that the nbr // of ghost cell for this patch data is null. - auto amr_box = layout.AMRBox(); + auto const amr_box = layout.AMRBox(); // The lb_view is a CellData, meaning that it is dual as the index of an amr box - auto amr_start = amr_box.lower; - auto amr_end = amr_box.upper; - - // nbr of cells in the physical domain - auto nbrCells = layout.nbrCells(); - - - - - if constexpr (dimension == 1) - { - for (std::uint32_t i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - { - auto amr_point{core::Point{i_amr}}; - auto amr_index = amr_point.template toArray(); - - std::size_t nbr = 0; - - for (auto& pop : ions) - { - const auto& domainParticles = pop.domainParticles(); - - nbr += domainParticles.nbr_particles_in(amr_index); - } - lb_view(i_loc) = nbr; - } - } + core::Box local_box{ + core::Point{core::ConstArray()}, + core::Point{ + core::generate([](auto const& nCell) { return nCell - 1; }, layout.nbrCells())}}; + auto amr_iter = amr_box.begin(); + auto lcl_iter = local_box.begin(); - - if constexpr (dimension == 2) - { - for (std::uint32_t i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - { - for (std::uint32_t j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr) - { - auto amr_point{core::Point{i_amr, j_amr}}; - auto amr_index = amr_point.template toArray(); - - std::size_t nbr = 0; - - for (auto& pop : ions) - { - const auto& domainParticles = pop.domainParticles(); - - nbr += domainParticles.nbr_particles_in(amr_index); - } - - lb_view(i_loc, j_loc) = nbr; - } - } - } - - - if constexpr (dimension == 3) - { - for (std::uint32_t i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - { - for (std::uint32_t j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr) - { - for (std::uint32_t k_loc = 0, k_amr = amr_start[2]; k_loc < nbrCells[2]; - ++k_loc, ++k_amr) - { - auto amr_point{core::Point{i_amr, j_amr, k_amr}}; - auto amr_index = amr_point.template toArray(); - - std::size_t nbr = 0; - - for (auto& pop : ions) - { - const auto& domainParticles = pop.domainParticles(); - - nbr += domainParticles.nbr_particles_in(amr_index); - } - - lb_view(i_loc, j_loc, k_loc) = nbr; - } - } - } - } + for (; lcl_iter != local_box.end(); ++amr_iter, ++lcl_iter) + lb_view(*lcl_iter) = core::sum_from(ions, [&](auto const& pop) { + return pop.domainParticles().nbr_particles_in((*amr_iter).toArray()); + }); } // TODO here, we have the lb_view value correctly set on all patches. we also know the id_ - // so this is where we should call setWorkloadPatchDataIndex... which is a method of the CascadePartitioner - // lb_view is a local container containing the datz - // the loadbalancezrmanager knows the id, as well as the loadbalancerestimator - // and the loadbalancerestimator is a cascadpartotioner - + // so this is where we should call setWorkloadPatchDataIndex... which is a method of the + // CascadePartitioner lb_view is a local container containing the datz the loadbalancezrmanager + // knows the id, as well as the loadbalancerestimator and the loadbalancerestimator is a + // cascadpartotioner } } // namespace PHARE::amr diff --git a/src/amr/load_balancing/load_balancer_estimator.hpp b/src/amr/load_balancing/load_balancer_estimator.hpp index 8b0dc8ef3..780edee1a 100644 --- a/src/amr/load_balancing/load_balancer_estimator.hpp +++ b/src/amr/load_balancing/load_balancer_estimator.hpp @@ -25,7 +25,7 @@ class LoadBalancerEstimator virtual ~LoadBalancerEstimator() = default; virtual void estimate(SAMRAI::hier::PatchLevel& level, - PHARE::solver::IPhysicalModel& model) + solver::IPhysicalModel& model) = 0; diff --git a/src/amr/load_balancing/load_balancer_estimator_hybrid.hpp b/src/amr/load_balancing/load_balancer_estimator_hybrid.hpp index dc87cfa9b..fd551e9a3 100644 --- a/src/amr/load_balancing/load_balancer_estimator_hybrid.hpp +++ b/src/amr/load_balancing/load_balancer_estimator_hybrid.hpp @@ -3,172 +3,44 @@ #include #include -#include -#include "load_balancer_estimator.hpp" -// #include "amr/resources_manager/amr_utils.hpp" + #include "amr/physical_models/physical_model.hpp" -// #include "core/data/ndarray/ndarray_vector.hpp" -// #include "amr/resources_manager/amr_utils.hpp" -// #include "core/utilities/point/point.hpp" + +#include "load_balancer_estimator.hpp" #include "load_balancer_hybrid_strategy.hpp" #include "load_balancer_hybrid_strategy_factory.hpp" - - namespace PHARE::amr { template class LoadBalancerEstimatorHybrid : public LoadBalancerEstimator { - using HybridModel = typename PHARE_T::HybridModel_t; - using gridlayout_type = typename HybridModel::gridlayout_type; - - + using HybridModel = typename PHARE_T::HybridModel_t; + using amr_types = typename HybridModel::amr_types; + using level_t = typename amr_types::level_t; public: - // LoadBalancerEstimatorHybrid(int const id) LoadBalancerEstimatorHybrid(std::string strategy_name, int const id) : LoadBalancerEstimator{id} , strat_{LoadBalancerHybridStrategyFactory::create(strategy_name, id)} { } - ~LoadBalancerEstimatorHybrid() = default; // the implementation of a virtual class NEEDS a dtor + // the implementation of a virtual class NEEDS a dtor + ~LoadBalancerEstimatorHybrid() = default; - void estimate(SAMRAI::hier::PatchLevel& level, - solver::IPhysicalModel& model) override; + void estimate(level_t& level, solver::IPhysicalModel& model) override + { + strat_->compute(level, model); + } private: std::unique_ptr> strat_; }; - - -template -inline void -LoadBalancerEstimatorHybrid::estimate(SAMRAI::hier::PatchLevel& level, - solver::IPhysicalModel& model) -{ - strat_->compute(level, model); - - // static auto constexpr dimension = HybridModel::dimension; - // auto& hybridModel = dynamic_cast(model); - // auto& resourcesManager = hybridModel.resourcesManager; - // auto& ions = hybridModel.state.ions; - - // bool constexpr c_ordering = false; - - // for (auto& patch : level) - // { - // auto const& layout = layoutFromPatch(*patch); - - // auto patch_data_lb - // = - // dynamic_cast*>(patch->getPatchData(this->id_).get()); - // auto load_balancer_val = patch_data_lb->getPointer(); - - // const auto& box = patch->getBox(); - - // auto lb_view = core::NdArrayView(load_balancer_val, - // layout.nbrCells()); - - // auto _ = resourcesManager->setOnPatch(*patch, ions); - - // // The view on "load_balancer_val" do not have any ghost cells, meaning that this patch - // // data lies on a box defind by the nbr of cells in the physical domain - // // As the nbr of ghost cells in the box associated to the load balancer patch data is - // // null, we hence loop on an AMR index (then needing to firstly get the AMR box) - // // to get the AMRLocatStart and AMRLocalEnd. - // // Then, we build "by hand" the local index for the "lb_view" considering that the nbr - // // of ghost cell for this patch data is null. - // auto amr_box = layout.AMRBox(); - - // // The lb_view is a CellData, meaning that it is dual as the index of an amr box - // auto amr_start = amr_box.lower; - // auto amr_end = amr_box.upper; - - // // nbr of cells in the physical domain - // auto nbrCells = layout.nbrCells(); - - - // if constexpr (dimension == 1) - // { - // for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - // { - // auto amr_point{core::Point{i_amr}}; - // auto amr_index = amr_point.template toArray(); - - // auto nbr = 0; - - // for (auto& pop : ions) - // { - // const auto& domainParticles = pop.domainParticles(); - - // nbr += domainParticles.nbr_particles_in(amr_index); - // } - - // lb_view(i_loc) = nbr; - // } - // } - - - // if constexpr (dimension == 2) - // { - // for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - // { - // for (auto j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr) - // { - // auto amr_point{core::Point{i_amr, j_amr}}; - // auto amr_index = amr_point.template toArray(); - - // auto nbr = 0; - - // for (auto& pop : ions) - // { - // const auto& domainParticles = pop.domainParticles(); - - // nbr += domainParticles.nbr_particles_in(amr_index); - // } - - // lb_view(i_loc, j_loc) = nbr; - // } - // } - // } - - - // if constexpr (dimension == 3) - // { - // for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr) - // { - // for (auto j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr) - // { - // for (auto k_loc = 0, k_amr = amr_start[2]; k_loc < nbrCells[2]; - // ++k_loc, ++k_amr) - // { - // auto amr_point{core::Point{i_amr, j_amr, k_amr}}; - // auto amr_index = amr_point.template toArray(); - - // auto nbr = 0; - - // for (auto& pop : ions) - // { - // const auto& domainParticles = pop.domainParticles(); - - // nbr += domainParticles.nbr_particles_in(amr_index); - // } - - // lb_view(i_loc, j_loc, k_loc) = nbr; - // } - // } - // } - // } - // } -} - } // namespace PHARE::amr #endif diff --git a/src/amr/load_balancing/load_balancer_hybrid_strategy.hpp b/src/amr/load_balancing/load_balancer_hybrid_strategy.hpp index 59edef854..a497e4567 100644 --- a/src/amr/load_balancing/load_balancer_hybrid_strategy.hpp +++ b/src/amr/load_balancing/load_balancer_hybrid_strategy.hpp @@ -14,10 +14,14 @@ namespace PHARE::amr template class LoadBalancerHybridStrategy { + using HybridModel = typename PHARE_T::HybridModel_t; + using amr_types = typename HybridModel::amr_types; + using level_t = typename amr_types::level_t; + public: - virtual void compute(SAMRAI::hier::PatchLevel& level, - PHARE::solver::IPhysicalModel& model) - = 0; + virtual ~LoadBalancerHybridStrategy() {} + + virtual void compute(level_t& level, PHARE::solver::IPhysicalModel& model) = 0; }; diff --git a/src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp b/src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp index f85a74f09..d03f283a9 100644 --- a/src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp +++ b/src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp @@ -1,4 +1,3 @@ - #ifndef LOAD_BALANCER_HYBRID_STRATEGY_FACTORY_HPP #define LOAD_BALANCER_HYBRID_STRATEGY_FACTORY_HPP @@ -7,7 +6,7 @@ #include "amr/load_balancing/load_balancer_hybrid_strategy.hpp" #include "amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp" - +#include "amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp" namespace PHARE::amr @@ -26,13 +25,15 @@ class LoadBalancerHybridStrategyFactory else if (strat_name == "homogeneous") { - return std::make_unique>(id); + return std::make_unique>(id); } return nullptr; } }; + } // namespace PHARE::amr + #endif diff --git a/src/amr/load_balancing/load_balancer_manager.hpp b/src/amr/load_balancing/load_balancer_manager.hpp index d3accc7bc..dd89ff97a 100644 --- a/src/amr/load_balancing/load_balancer_manager.hpp +++ b/src/amr/load_balancing/load_balancer_manager.hpp @@ -7,11 +7,9 @@ #include #include -// #include "phare_core.hpp" + #include "initializer/data_provider.hpp" #include "load_balancer_estimator.hpp" -// #include "amr/resources_manager/amr_utils.hpp" -// #include "amr/solvers/solver.hpp" @@ -21,7 +19,6 @@ template class LoadBalancerManager { public: - // LoadBalancerManager(int const maxLevelNumber) LoadBalancerManager(PHARE::initializer::PHAREDict const& dict) : dim_{SAMRAI::tbox::Dimension{dim}} , loadBalancerVar_{std::make_shared>( @@ -31,8 +28,7 @@ class LoadBalancerManager , id_{variableDatabase_->registerVariableAndContext(loadBalancerVar_, context_, SAMRAI::hier::IntVector::getZero(dim_))} , maxLevelNumber_{dict["simulation"]["AMR"]["max_nbr_levels"].template to()} - // , loadBalancerEstimators_(maxLevelNumber, nullptr){}; - , loadBalancerEstimators_(maxLevelNumber_, nullptr){}; + , loadBalancerEstimators_(maxLevelNumber_){}; ~LoadBalancerManager() { variableDatabase_->removeVariable("LoadBalancerVariable"); }; diff --git a/src/amr/resources_manager/amr_utils.hpp b/src/amr/resources_manager/amr_utils.hpp index 4faf3bb39..68efb7896 100644 --- a/src/amr/resources_manager/amr_utils.hpp +++ b/src/amr/resources_manager/amr_utils.hpp @@ -138,6 +138,7 @@ namespace amr SAMRAI::tbox::Dimension const dim{dimension}; + assert(patch.getPatchGeometry()); // We get geometry information from the patch, such as meshSize, and physical origin auto patchGeom = std::dynamic_pointer_cast( patch.getPatchGeometry()); diff --git a/src/core/data/grid/gridlayout.hpp b/src/core/data/grid/gridlayout.hpp index d737adab3..1bffb426a 100644 --- a/src/core/data/grid/gridlayout.hpp +++ b/src/core/data/grid/gridlayout.hpp @@ -279,7 +279,7 @@ namespace core auto xyz = tuple_fixed_type, dimension>{}; - for (const auto& indiceTuple : indices) + for (auto const& indiceTuple : indices) std::apply( [&](auto const&... args) { emplace_back( diff --git a/src/core/data/ions/ions.hpp b/src/core/data/ions/ions.hpp index 6772d3316..e83a44768 100644 --- a/src/core/data/ions/ions.hpp +++ b/src/core/data/ions/ions.hpp @@ -26,6 +26,7 @@ namespace core class Ions { public: + using value_type = IonPopulation; using field_type = typename IonPopulation::field_type; using vecfield_type = typename IonPopulation::vecfield_type; using Float = typename field_type::type; diff --git a/src/core/data/ndarray/ndarray_vector.hpp b/src/core/data/ndarray/ndarray_vector.hpp index c9bef9837..940fabe60 100644 --- a/src/core/data/ndarray/ndarray_vector.hpp +++ b/src/core/data/ndarray/ndarray_vector.hpp @@ -186,6 +186,17 @@ class NdArrayView : NdArrayViewer }; +template +auto make_array_view(DataType* data, std::array shape) +{ + return NdArrayView{data, shape}; +} + +template +auto make_array_view(DataType const* const data, std::array shape) +{ + return NdArrayView{data, shape}; +} template diff --git a/src/core/utilities/box/box.hpp b/src/core/utilities/box/box.hpp index fd3e1fe09..87472e75c 100644 --- a/src/core/utilities/box/box.hpp +++ b/src/core/utilities/box/box.hpp @@ -158,8 +158,8 @@ class box_iterator } public: - Point operator*() { return index_; } - + auto& operator*() const { return index_; } + auto operator->() const { return &index_; } void increment(std::size_t idim) { diff --git a/src/core/utilities/types.hpp b/src/core/utilities/types.hpp index 485ad3e87..189962af9 100644 --- a/src/core/utilities/types.hpp +++ b/src/core/utilities/types.hpp @@ -256,6 +256,17 @@ NO_DISCARD Return sum(Container const& container, Return r = 0) return std::accumulate(container.begin(), container.end(), r); } +template +NO_DISCARD auto sum_from(Container const& container, F fn) +{ + using value_type = typename Container::value_type; + using return_type = std::decay_t>; + return_type sum = 0; + for (auto const& el : container) + sum += fn(el); + return sum; +} + @@ -300,13 +311,13 @@ NO_DISCARD auto generate(F&& f, std::vector&& v) } template -NO_DISCARD auto constexpr generate_array__(F& f, std::array& arr) +NO_DISCARD auto constexpr generate_array__(F& f, std::array const& arr) { return f(arr[Idx]); } template -NO_DISCARD auto constexpr generate_array_(F& f, std::array& arr, +NO_DISCARD auto constexpr generate_array_(F& f, std::array const& arr, std::integer_sequence) { return std::array{generate_array__(f, arr)...}; diff --git a/src/diagnostic/detail/h5writer.hpp b/src/diagnostic/detail/h5writer.hpp index 2cb191d04..76d1c506b 100644 --- a/src/diagnostic/detail/h5writer.hpp +++ b/src/diagnostic/detail/h5writer.hpp @@ -132,7 +132,7 @@ class H5Writer template static void writeAttributeDict(HighFiveFile& h5, Dict dict, std::string path) { - dict.visit([&](std::string const& key, const auto& val) { + dict.visit([&](std::string const& key, auto const& val) { h5.write_attributes_per_mpi(path, key, val); }); } diff --git a/src/simulator/simulator.hpp b/src/simulator/simulator.hpp index 508d9e23f..012342905 100644 --- a/src/simulator/simulator.hpp +++ b/src/simulator/simulator.hpp @@ -266,7 +266,7 @@ void Simulator::hybrid_init(initializer::PHAREDict auto lbm_ = std::make_unique>(dict); - auto lbe_ = std::make_unique>( + auto lbe_ = std::make_shared>( dict["simulation"]["AMR"]["loadbalancing"].template to(), lbm_->getId()); lbm_->addLoadBalancerEstimator(0, maxLevelNumber_ - 1, std::move(lbe_));