Skip to content

Commit

Permalink
Merge pull request #28062 from pbehne/missing_subapp_checkpoint
Browse files Browse the repository at this point in the history
Ensure duplicates are not added to list of checkpoint files.
  • Loading branch information
GiudGiud authored Jul 11, 2024
2 parents f1f4c31 + 5167b9e commit 366d996
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions framework/include/outputs/Checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ struct CheckpointFileNames

/// Filenames for restartable data
std::vector<std::filesystem::path> restart;

bool operator==(const CheckpointFileNames & rhs) const
{
// Compare the relevant members for equality
return (this->checkpoint == rhs.checkpoint) && (this->restart == rhs.restart);
}
};

/**
Expand Down
18 changes: 17 additions & 1 deletion framework/src/outputs/Checkpoint.C
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,23 @@ Checkpoint::output()
void
Checkpoint::updateCheckpointFiles(CheckpointFileNames file_struct)
{
// Update the list of stored files
// It is possible to have already written a checkpoint with the same file
// names contained in file_struct. If this is the case, file_struct will
// already be stored in _file_names. When this happens, the current state of
// the simulation is likely different than the state when the duplicately
// named checkpoint was last written. Because of this, we want to go ahead and
// rewrite the duplicately named checkpoint, overwritting the files
// representing the old state. For accurate bookkeeping, we will delete the
// existing instance of file_struct from _file_names and re-append it to the
// end of _file_names (to keep the order in which checkpoints are written
// accurate).

const auto it = std::find(_file_names.begin(), _file_names.end(), file_struct);
// file_struct was found in _file_names.
// Delete it so it can be re-added as the last element.
if (it != _file_names.end())
_file_names.erase(it);

_file_names.push_back(file_struct);

// Remove the file and the corresponding directory if it's empty
Expand Down
2 changes: 1 addition & 1 deletion test/tests/outputs/checkpoint/checkpoint_child.i
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

[Executioner]
type = Transient
num_steps = 11
num_steps = 2
dt = 0.1
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
Expand Down
2 changes: 1 addition & 1 deletion test/tests/outputs/checkpoint/checkpoint_parent.i
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

[MultiApps]
[sub_app]
type = TransientMultiApp
type = FullSolveMultiApp
input_files = "checkpoint_child.i"
positions = '0 0 0'
[]
Expand Down
15 changes: 15 additions & 0 deletions test/tests/outputs/checkpoint/tests
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,18 @@
expect_err = "Shortcut checkpoint syntax cannot be used with another Checkpoint object in the 'Outputs' block"
[]
[]

[subapp_only_cp]
issues = "#24777"
type = CheckFiles
recover = false
input = checkpoint_parent.i
cli_args = 'Outputs/checkpoint=false sub_app:Outputs/cp/type=Checkpoint sub_app:Outputs/cp/num_files=1 sub_app:Outputs/cp/execute_on=final'
check_files = "checkpoint_parent_out_sub_app0_cp_cp/0003-restart-0.rd/data "
"checkpoint_parent_out_sub_app0_cp_cp/0003-restart-0.rd/header "
"checkpoint_parent_out_sub_app0_cp_cp/0003-mesh.cpa.gz/1/header.gz "
"checkpoint_parent_out_sub_app0_cp_cp/0003-mesh.cpa.gz/1/split-1-0.gz "
"checkpoint_parent_out_sub_app0_cp_cp/0003-mesh.cpa.gz/meta_data_mesh.rd/data "
"checkpoint_parent_out_sub_app0_cp_cp/0003-mesh.cpa.gz/meta_data_mesh.rd/header"
requirement = "The system shall support outputting checkpoint files at the subapp level with checkpoints disabled in the main app"
[]

0 comments on commit 366d996

Please sign in to comment.