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
5 changes: 3 additions & 2 deletions pyphare/pyphare/pharein/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@


def all_timestamps(sim):
nbr_dump_step = int(sim.final_time / sim.time_step) + 1
return sim.time_step * np.arange(nbr_dump_step)
init_time = sim.start_time()
nbr_dump_step = int((sim.final_time - init_time) / sim.time_step) + 1
return (sim.time_step * np.arange(nbr_dump_step)) + init_time
Copy link
Member Author

Choose a reason for hiding this comment

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

updated to work with restarts



# ------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ namespace amr
static constexpr std::size_t rootLevelNumber = 0;


HybridHybridMessengerStrategy(std::shared_ptr<ResourcesManagerT> manager,
HybridHybridMessengerStrategy(std::shared_ptr<ResourcesManagerT> const& manager,
int const firstLevel)
: HybridMessengerStrategy<HybridModel>{stratName}
, resourcesManager_{std::move(manager)}
, resourcesManager_{manager}
, firstLevel_{firstLevel}
{
resourcesManager_->registerResources(Jold_);
Expand Down
19 changes: 10 additions & 9 deletions src/amr/messengers/messenger_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ class MessengerFactory
{
if (messengerName == HybridHybridMessengerStrategy_t::stratName)
{
auto resourcesManager = dynamic_cast<HybridModel const&>(coarseModel).resourcesManager;
auto& resourcesManager = dynamic_cast<HybridModel const&>(coarseModel).resourcesManager;

auto messengerStrategy = std::make_unique<HybridHybridMessengerStrategy_t>(
std::move(resourcesManager), firstLevel);
auto messengerStrategy
= std::make_unique<HybridHybridMessengerStrategy_t>(resourcesManager, firstLevel);

return std::make_unique<HybridMessenger<HybridModel>>(std::move(messengerStrategy));
}
Expand All @@ -97,13 +97,15 @@ class MessengerFactory
else if (messengerName == MHDHybridMessengerStrategy<MHDModel, HybridModel>::stratName)
{
// caution we move them so don't put a ref
auto mhdResourcesManager = dynamic_cast<MHDModel const&>(coarseModel).resourcesManager;
auto hybridResourcesManager
auto& mhdResourcesManager = dynamic_cast<MHDModel const&>(coarseModel).resourcesManager;
auto& hybridResourcesManager
= dynamic_cast<HybridModel const&>(fineModel).resourcesManager;
if (hybridResourcesManager.get() != mhdResourcesManager.get())
throw std::runtime_error("Multiple ResourceManagers in use");

auto messengerStrategy
= std::make_unique<MHDHybridMessengerStrategy<MHDModel, HybridModel>>(
std::move(mhdResourcesManager), std::move(hybridResourcesManager), firstLevel);
mhdResourcesManager, firstLevel);

return std::make_unique<HybridMessenger<HybridModel>>(std::move(messengerStrategy));
}
Expand All @@ -113,10 +115,9 @@ class MessengerFactory

else if (messengerName == MHDMessenger<MHDModel>::stratName)
{
auto mhdResourcesManager = dynamic_cast<MHDModel const&>(coarseModel).resourcesManager;
auto& mhdResourcesManager = dynamic_cast<MHDModel const&>(coarseModel).resourcesManager;

return std::make_unique<MHDMessenger<MHDModel>>(std::move(mhdResourcesManager),
firstLevel);
return std::make_unique<MHDMessenger<MHDModel>>(mhdResourcesManager, firstLevel);
}
else
return {};
Expand Down
20 changes: 10 additions & 10 deletions src/amr/messengers/mhd_hybrid_messenger_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ namespace amr
using VecFieldT = decltype(std::declval<HybridModel>().state.electromag.E);
using IPhysicalModel = typename HybridModel::Interface;

using resources_manager_type = HybridModel::resources_manager_type;
static_assert(
std::is_same_v<resources_manager_type, typename MHDModel::resources_manager_type>);

public:
static std::string const stratName;

MHDHybridMessengerStrategy(
std::shared_ptr<typename MHDModel::resources_manager_type> mhdResourcesManager,
std::shared_ptr<typename HybridModel::resources_manager_type> hybridResourcesManager,
int const firstLevel)
MHDHybridMessengerStrategy(std::shared_ptr<resources_manager_type> const& resourcesManager,
int const firstLevel)
: HybridMessengerStrategy<HybridModel>{stratName}
, mhdResourcesManager_{std::move(mhdResourcesManager)}
, hybridResourcesManager_{std::move(hybridResourcesManager)}
, resourcesManager_{resourcesManager}
, firstLevel_{firstLevel}
{
hybridResourcesManager_->registerResources(EM_old_);
resourcesManager_->registerResources(EM_old_);
}

/**
Expand All @@ -41,7 +42,7 @@ namespace amr
{
// hybModel.resourcesManager->allocate(EM_old_.E, patch, allocateTime);
// hybModel.resourcesManager->allocate(EM_old_.B, patch, allocateTime);
hybridResourcesManager_->allocate(EM_old_, patch, allocateTime);
resourcesManager_->allocate(EM_old_, patch, allocateTime);
}

void registerQuantities(
Expand Down Expand Up @@ -150,8 +151,7 @@ namespace amr
private:
using Electromag = decltype(std::declval<HybridModel>().state.electromag);

std::shared_ptr<typename MHDModel::resources_manager_type> mhdResourcesManager_;
std::shared_ptr<typename HybridModel::resources_manager_type> hybridResourcesManager_;
std::shared_ptr<resources_manager_type> resourcesManager_;
int const firstLevel_;
Electromag EM_old_{stratName + "_EM_old"};
};
Expand Down
17 changes: 9 additions & 8 deletions src/amr/messengers/mhd_messenger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ namespace amr
template<typename MHDModel>
class MHDMessenger : public IMessenger<typename MHDModel::Interface>
{
using resources_manager_type = MHDModel::resources_manager_type;

public:
using IPhysicalModel = typename MHDModel::Interface;
MHDMessenger(std::shared_ptr<typename MHDModel::resources_manager_type> resourcesManager,
int const firstLevel)
: resourcesManager_{std::move(resourcesManager)}
MHDMessenger(std::shared_ptr<resources_manager_type> resourcesManager, int const firstLevel)
: resourcesManager_{resourcesManager}
, firstLevel_{firstLevel}
{
}
Expand All @@ -48,7 +49,7 @@ namespace amr
}


static const std::string stratName;
static std::string const stratName;

std::string fineModelName() const override { return MHDModel::model_name; }

Expand Down Expand Up @@ -77,15 +78,15 @@ namespace amr


void regrid(std::shared_ptr<SAMRAI::hier::PatchHierarchy> const& /*hierarchy*/,
const int /*levelNumber*/,
int const /*levelNumber*/,
std::shared_ptr<SAMRAI::hier::PatchLevel> const& /*oldLevel*/,
IPhysicalModel& /*model*/, double const /*initDataTime*/) override
{
}


void firstStep(IPhysicalModel& /*model*/, SAMRAI::hier::PatchLevel& /*level*/,
const std::shared_ptr<SAMRAI::hier::PatchHierarchy>& /*hierarchy*/,
std::shared_ptr<SAMRAI::hier::PatchHierarchy> const& /*hierarchy*/,
double const /*currentTime*/, double const /*prevCoarserTIme*/,
double const /*newCoarserTime*/) final
{
Expand Down Expand Up @@ -124,13 +125,13 @@ namespace amr


private:
std::shared_ptr<typename MHDModel::resources_manager_type> resourcesManager_;
std::shared_ptr<resources_manager_type> resourcesManager_;
int const firstLevel_;
};


template<typename MHDModel>
const std::string MHDMessenger<MHDModel>::stratName = "MHDModel-MHDModel";
std::string const MHDMessenger<MHDModel>::stratName = "MHDModel-MHDModel";
} // namespace amr
} // namespace PHARE
#endif
4 changes: 0 additions & 4 deletions src/amr/physical_models/hybrid_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class HybridModel : public IPhysicalModel<AMR_Types>
}


auto patch_data_ids() const { return resourcesManager->restart_patch_data_ids(*this); }


/**
Expand Down Expand Up @@ -137,9 +136,6 @@ void HybridModel<GridLayoutT, Electromag, Ions, Electrons, AMR_Types, Grid_t>::i

state.electromag.initialize(layout);
}


resourcesManager->registerForRestarts(*this);
}


Expand Down
1 change: 1 addition & 0 deletions src/amr/physical_models/mhd_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace solver
}



virtual ~MHDModel() override = default;

core::MHDState<VecFieldT> state;
Expand Down
33 changes: 13 additions & 20 deletions src/amr/resources_manager/resources_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,32 +290,27 @@ namespace amr
}


template<typename ResourcesView>
void registerForRestarts(ResourcesView const& view) const
void registerForRestarts() const
{
auto pdrm = SAMRAI::hier::PatchDataRestartManager::getManager();

for (auto const& id : restart_patch_data_ids(view))
for (auto const& id : restart_patch_data_ids())
pdrm->registerPatchDataForRestart(id);
}

template<typename ResourcesView>
NO_DISCARD auto restart_patch_data_ids(ResourcesView const& view) const
{
// true for now with https://github.com/PHAREHUB/PHARE/issues/664
constexpr bool ALL_IDS = true;

NO_DISCARD auto restart_patch_data_ids() const
{ // see https://github.com/PHAREHUB/PHARE/issues/664
std::vector<int> ids;
for (auto const& [key, info] : nameToResourceInfo_)
ids.emplace_back(info.id);
return ids;
}

if constexpr (ALL_IDS)
{ // get all registered ids to save
for (auto const& [key, info] : nameToResourceInfo_)
ids.emplace_back(info.id);
}
else
{ // this is the case when transient datas not to be saved
getIDs_(view, ids);
}
template<typename ResourcesView> // this function is never called
NO_DISCARD auto restart_patch_data_ids(ResourcesView const& view) const
{
std::vector<int> ids;
getIDs_(view, ids);
return ids;
}

Expand Down Expand Up @@ -399,8 +394,6 @@ namespace amr
}
else
{
static_assert(has_sub_resources_v<ResourcesView>);

if constexpr (has_runtime_subresourceview_list<ResourcesView>::value)
{
for (auto& resourcesUser : obj.getRunTimeResourcesViewList())
Expand Down
47 changes: 33 additions & 14 deletions src/restarts/detail/h5writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,52 @@


#include "core/utilities/mpi_utils.hpp"

#include "restarts/restarts_props.hpp"
#include "restarts/restarts_manager.hpp"

#include "initializer/data_provider.hpp"

#include "hdf5/detail/h5/h5_file.hpp"

namespace PHARE::restarts::h5
{
template<typename ModelView>
template<typename Hierarchy, typename ResourceManager_t>
class Writer
{
public:
using This = Writer<ModelView>;
using This = Writer<Hierarchy, ResourceManager_t>;


template<typename Hierarchy, typename Model>
Writer(Hierarchy const& hier, Model const& model, std::string const filePath)
: path_{filePath}
, modelView_{hier, model}
Writer(Hierarchy const& hier, ResourceManager_t const& resman, std::string const filePath)
: hierarchy_{hier}
, resman_{resman}
, path_{filePath}
{
}

~Writer() {}


template<typename Hierarchy, typename Model>
static auto make_unique(Hierarchy const& hier, Model const& model,

static auto make_unique(Hierarchy const& hier, ResourceManager_t const& resman,
initializer::PHAREDict const& dict)
{
std::string filePath = dict["filePath"].template to<std::string>();
return std::make_unique<This>(hier, model, filePath);
return std::make_unique<This>(hier, resman, filePath);
}


void dump(RestartsProperties const& properties, double timestamp)
{
auto restart_file
= modelView_.writeRestartFile(ModelView::restartFilePathForTime(path_, timestamp));
auto restart_file = writeRestartFile(restartFilePathForTime(path_, timestamp));

// write model patch_data_ids to file with highfive
// SAMRAI restart files are PER RANK
PHARE::hdf5::h5::HighFiveFile h5File{restart_file, HighFive::File::ReadWrite,
/*para=*/false};

auto patch_ids = modelView_.patch_data_ids();
auto const& patch_ids = patch_data_ids();
h5File.create_data_set<int>("/phare/patch/ids", patch_ids.size());
h5File.write_data_set("/phare/patch/ids", patch_ids);

Expand All @@ -55,12 +59,27 @@ class Writer
core::mpi::barrier();
}

auto& modelView() { return modelView_; }


private:
NO_DISCARD auto writeRestartFile(std::string const& path) const
{
return hierarchy_.writeRestartFile(path);
}

NO_DISCARD auto static restartFilePathForTime(std::string path, double timestamp)
{
return Hierarchy::restartFilePathForTime(path, timestamp);
}


NO_DISCARD auto patch_data_ids() const { return resman_.restart_patch_data_ids(); }



Hierarchy const& hierarchy_;
ResourceManager_t const& resman_;
std::string const path_;
ModelView const modelView_;
};


Expand Down
10 changes: 4 additions & 6 deletions src/restarts/restarts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#if PHARE_HAS_HIGHFIVE

#include "restarts_model_view.hpp"
#include "restarts/detail/h5writer.hpp"

#endif
Expand All @@ -32,14 +31,13 @@ struct NullOpRestartsManager : public IRestartsManager

struct RestartsManagerResolver
{
template<typename Hierarchy, typename Model>
template<typename Hierarchy, typename ResourceManager_t>
NO_DISCARD static std::unique_ptr<IRestartsManager>
make_unique(Hierarchy& hier, Model& model, initializer::PHAREDict const& dict)
make_unique(Hierarchy& hier, ResourceManager_t& resman, initializer::PHAREDict const& dict)
{
#if PHARE_HAS_HIGHFIVE
using ModelView_t = ModelView<Hierarchy, Model>;
using Writer_t = h5::Writer<ModelView_t>;
return RestartsManager<Writer_t>::make_unique(hier, model, dict);
using Writer_t = h5::Writer<Hierarchy, ResourceManager_t>;
return RestartsManager<Writer_t>::make_unique(hier, resman, dict);
#else
return std::make_unique<NullOpRestartsManager>();
#endif
Expand Down
Loading