Skip to content

Commit

Permalink
Add option to overwrite or not the checkpoint files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rombur committed Feb 22, 2024
1 parent 9316081 commit a358809
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ The following options are available:
* time\_steps\_between\_checkpoint: number of time steps after which
checkpointing is performed (required)
* filename\_prefix: prefix of the checkpoint files (required)
* overwrite\_files: if true the checkpoint files are overwritten by newer
ones. If false, the time steps is added to the filename prefix (required)
* restart (optional):
* filename\_prefix: prefix of the restart files (required)
* verbose\_output: true or false (default value: false)
Expand Down
23 changes: 18 additions & 5 deletions application/adamantine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,

unsigned int time_steps_checkpoint = std::numeric_limits<unsigned int>::max();
std::string checkpoint_filename;
bool checkpoint_overwrite = true;
if (checkpoint_optional_database)
{
auto checkpoint_database = checkpoint_optional_database.get();
Expand All @@ -965,6 +966,8 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
// PropertyTreeInput checkpoint.filename_prefix
checkpoint_filename =
checkpoint_database.get<std::string>("filename_prefix");
// PropertyTreeInput checkpoint.overwrite_files
checkpoint_overwrite = checkpoint_database.get<bool>("overwrite_files");
}

bool restart = false;
Expand Down Expand Up @@ -1223,8 +1226,12 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
{
std::cout << "Checkpoint reached" << std::endl;
}
thermal_physics->save_checkpoint(checkpoint_filename, temperature);
std::ofstream file{checkpoint_filename + "_time.txt"};
std::string filename_prefix =
checkpoint_overwrite
? checkpoint_filename
: checkpoint_filename + '_' + std::to_string(n_time_step);
thermal_physics->save_checkpoint(filename_prefix, temperature);
std::ofstream file{filename_prefix + "_time.txt"};
boost::archive::text_oarchive oa{file};
oa << time;
oa << n_time_step;
Expand Down Expand Up @@ -1551,6 +1558,7 @@ run_ensemble(MPI_Comm const &global_communicator,
dealii::Utilities::MPI::this_mpi_process(global_communicator);
unsigned int time_steps_checkpoint = std::numeric_limits<unsigned int>::max();
std::string checkpoint_filename;
bool checkpoint_overwrite = true;
if (checkpoint_optional_database)
{
auto checkpoint_database = checkpoint_optional_database.get();
Expand All @@ -1561,6 +1569,8 @@ run_ensemble(MPI_Comm const &global_communicator,
checkpoint_filename =
checkpoint_database.get<std::string>("filename_prefix") + '_' +
std::to_string(global_rank);
// PropertyTreeInput checkpoint.overwrite_files
checkpoint_overwrite = checkpoint_database.get<bool>("overwrite_files");
}

bool restart = false;
Expand Down Expand Up @@ -2137,14 +2147,17 @@ run_ensemble(MPI_Comm const &global_communicator,
{
std::cout << "Checkpoint reached" << std::endl;
}
std::string filename_prefix =
checkpoint_overwrite
? checkpoint_filename
: checkpoint_filename + '_' + std::to_string(n_time_step);
for (unsigned int member = 0; member < local_ensemble_size; ++member)
{
thermal_physics_ensemble[member]->save_checkpoint(
checkpoint_filename + '_' +
std::to_string(first_local_member + member),
filename_prefix + '_' + std::to_string(first_local_member + member),
solution_augmented_ensemble[member].block(base_state));
}
std::ofstream file{checkpoint_filename + "_time.txt"};
std::ofstream file{filename_prefix + "_time.txt"};
boost::archive::text_oarchive oa{file};
oa << time;
oa << n_time_step;
Expand Down
1 change: 1 addition & 0 deletions tests/test_integration_3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ BOOST_AUTO_TEST_CASE(integration_3D_checkpoint_restart)

// First run with checkpoint of the solution halfway through the solution
database.put("checkpoint.filename_prefix", checkpoint_filename);
database.put("checkpoint.overwrite_files", true);
database.put("checkpoint.time_steps_between_checkpoint", 80);
auto [temperature_1, displacement_1] =
run<3, dealii::MemorySpace::Host>(communicator, database, timers);
Expand Down
1 change: 1 addition & 0 deletions tests/test_integration_3d_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ BOOST_AUTO_TEST_CASE(integration_3D_checkpoint_restart_device)

// First run with checkpoint of the solution halfway through the solution
database.put("checkpoint.filename_prefix", checkpoint_filename);
database.put("checkpoint.overwrite_files", true);
database.put("checkpoint.time_steps_between_checkpoint", 80);
auto [temperature_1, displacement_1] =
run<3, dealii::MemorySpace::Host>(communicator, database, timers);
Expand Down

0 comments on commit a358809

Please sign in to comment.