Skip to content

Commit

Permalink
Merge pull request #1257 from LLNL/tupek/refactor_checkpoint_load_fro…
Browse files Browse the repository at this point in the history
…m_disk

Refactor state loading to reduce chances of future bug being added.
  • Loading branch information
tupek2 authored Nov 14, 2024
2 parents dc61e07 + b04f468 commit 5169831
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
19 changes: 12 additions & 7 deletions src/serac/physics/base_physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void BasePhysics::saveSummary(axom::sidre::DataStore& datastore, const double t)
}
}

FiniteElementState BasePhysics::loadCheckpointedState(const std::string& state_name, int cycle) const
FiniteElementState BasePhysics::loadCheckpointedState(const std::string& state_name, int cycle)
{
if (checkpoint_to_disk_) {
// See if the requested cycle has been checkpointed previously
Expand All @@ -356,16 +356,21 @@ FiniteElementState BasePhysics::loadCheckpointedState(const std::string& state_n
return checkpoint_states_.at(state_name)[static_cast<size_t>(cycle)];
}

std::unordered_map<std::string, FiniteElementState> BasePhysics::getCheckpointedStates(int cycle_to_load) const
void BasePhysics::loadCheckpointedStatesFromDisk(int cycle_to_load)
{
std::vector<FiniteElementState*> previous_states_ptrs;
for (const auto& state_name : stateNames()) {
previous_states_ptrs.emplace_back(const_cast<FiniteElementState*>(&state(state_name)));
}
StateManager::loadCheckpointedStates(cycle_to_load, previous_states_ptrs);
}

std::unordered_map<std::string, FiniteElementState> BasePhysics::getCheckpointedStates(int cycle_to_load)
{
std::unordered_map<std::string, FiniteElementState> previous_states_map;
std::vector<FiniteElementState*> previous_states_ptrs;

if (checkpoint_to_disk_) {
for (const auto& state_name : stateNames()) {
previous_states_ptrs.emplace_back(const_cast<FiniteElementState*>(&state(state_name)));
}
StateManager::loadCheckpointedStates(cycle_to_load, previous_states_ptrs);
loadCheckpointedStatesFromDisk(cycle_to_load);
for (const auto& state_name : stateNames()) {
previous_states_map.emplace(state_name, state(state_name));
}
Expand Down
13 changes: 10 additions & 3 deletions src/serac/physics/base_physics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ class BasePhysics {
*/
virtual void outputStateToDisk(std::optional<std::string> paraview_output_dir = {}) const;

/**
* @brief load checkpointed states from disk into states array
*
* @param cycle The cycle to retrieve state from
*/
void loadCheckpointedStatesFromDisk(int cycle);

/**
* @brief Accessor for getting a single named finite element state primal solution from the physics modules at a given
* checkpointed cycle index
Expand All @@ -404,7 +411,7 @@ class BasePhysics {
* @param cycle The cycle to retrieve state from
* @return The named primal Finite Element State
*/
FiniteElementState loadCheckpointedState(const std::string& state_name, int cycle) const;
FiniteElementState loadCheckpointedState(const std::string& state_name, int cycle);

/**
* @brief Accessor for getting a single named finite element dual solution from the physics modules at a given
Expand All @@ -415,7 +422,7 @@ class BasePhysics {
* @return The named Finite Element Dual
*/
virtual FiniteElementDual loadCheckpointedDual([[maybe_unused]] const std::string& state_name,
[[maybe_unused]] int cycle) const
[[maybe_unused]] int cycle)
{
SLIC_ERROR_ROOT(axom::fmt::format("loadCheckpointedDual not enabled in physics module {}", name_));
return *duals_[0];
Expand Down Expand Up @@ -486,7 +493,7 @@ class BasePhysics {
* @param cycle The cycle to retrieve state from
* @return A map containing the primal field names and their associated FiniteElementStates at the requested cycle
*/
std::unordered_map<std::string, FiniteElementState> getCheckpointedStates(int cycle) const;
std::unordered_map<std::string, FiniteElementState> getCheckpointedStates(int cycle);

/// @brief Name of the physics module
std::string name_ = {};
Expand Down
2 changes: 1 addition & 1 deletion src/serac/physics/solid_mechanics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ class SolidMechanics<order, dim, Parameters<parameter_space...>, std::integer_se
}

/// @overload
FiniteElementDual loadCheckpointedDual(const std::string& dual_name, int cycle) const override
FiniteElementDual loadCheckpointedDual(const std::string& dual_name, int cycle) override
{
if (dual_name == "reactions") {
auto checkpointed_sol = getCheckpointedStates(cycle);
Expand Down

0 comments on commit 5169831

Please sign in to comment.