13 #include <system_error> 24 #include "libmesh/checkpoint_io.h" 25 #include "libmesh/enum_xdr_mode.h" 26 #include "libmesh/utility.h" 44 params.
addParam<
unsigned int>(
"num_files", 2,
"Number of the restart files to save");
48 "This will be appended to the file_base to create the directory name for checkpoint files.");
51 "wall_time_interval", 600,
"The target wall time interval (in seconds) at which to output");
64 _num_files(getParam<unsigned
int>(
"num_files")),
65 _suffix(getParam<
std::string>(
"suffix"))
69 const auto & execute_on = getParam<ExecFlagEnum>(
"execute_on");
72 std::vector<ExecFlagEnum> valid_execute_on_values(7);
76 valid_execute_on_values[0] = valid_execute_on_value;
78 valid_execute_on_values[1] = valid_execute_on_value;
80 valid_execute_on_values[2] = valid_execute_on_value;
82 valid_execute_on_values[3] = valid_execute_on_value;
84 valid_execute_on_values[4] = valid_execute_on_value;
86 valid_execute_on_values[5] = valid_execute_on_value;
88 valid_execute_on_values[6] = valid_execute_on_value;
92 auto it = std::find(valid_execute_on_values.begin(), valid_execute_on_values.end(), execute_on);
93 const bool is_valid_value = (it != valid_execute_on_values.end());
96 "The checkpoint system may only be used with execute_on values ",
97 "INITIAL, TIMESTEP_END, and FINAL, not '",
113 std::ostringstream
output;
134 if (!should_output_parent)
140 if (should_output_signal)
142 _console <<
"Unix signal SIGUSR1 detected. Outputting checkpoint file.\n";
150 if (should_output_wall_time)
165 return should_output;
173 Utility::mkdir(cp_dir.c_str());
176 const auto current_file =
filename();
180 CheckpointIO io(
mesh,
true);
194 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
199 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
212 const auto remove_file = [
this](
const std::filesystem::path & path)
216 if (!std::filesystem::remove(path,
err))
217 mooseWarning(
"Error during the deletion of checkpoint file\n",
218 std::filesystem::absolute(path),
222 const auto dir = path.parent_path();
223 if (std::filesystem::is_empty(dir))
224 if (!std::filesystem::remove(dir,
err))
225 mooseError(
"Error during the deletion of checkpoint directory\n",
226 std::filesystem::absolute(dir),
241 for (
const auto & path : delete_files.
restart)
247 CheckpointIO::cleanup(delete_files.
checkpoint,
static const std::string & checkpointSuffix()
The file suffix for the checkpoint mesh.
virtual bool shouldOutput() override
Checks if the output method should be executed.
A MultiMooseEnum object to hold "execute_on" flags.
Checkpoint(const InputParameters ¶meters)
Class constructor.
A structure for storing the various output files associated with checkpoint output.
CheckpointType
Enumerated type for determining what type of checkpoint this is.
virtual bool onInterval()
Returns true if the output interval is satisfied.
bool isDistributedMesh() const
Returns the final Mesh distribution type.
std::filesystem::path restartFolderBase(const std::filesystem::path &folder_base) const
The file suffix for restartable data.
std::string checkpoint
Filename for CheckpointIO file (the mesh)
const Parallel::Communicator & comm() const
std::string _file_base
The base filename from the input paramaters.
void updateCheckpointFiles(CheckpointFileNames file_struct)
const std::string _suffix
Directory suffix.
std::vector< std::filesystem::path > writeRestartableMetaData(const RestartableDataMapName &name, const std::filesystem::path &folder_base)
Writes the restartable meta data for name with a folder base of folder_base.
const ExecFlagType EXEC_TIMESTEP_END
registerMooseObject("MooseApp", Checkpoint)
virtual bool shouldOutput() override
Determines if the checkpoint should write out to a file.
Real _wall_time_since_last_output
time in seconds since last output
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
unsigned int _padding
Number of digits to pad the extensions.
processor_id_type size() const
virtual std::string filename() override
Returns the base filename for the checkpoint files.
CheckpointType _checkpoint_type
Determines if this checkpoint is an autosave, and what kind of autosave it is.
virtual void output() override
Outputs a checkpoint file.
EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
std::vector< std::filesystem::path > backup(const std::filesystem::path &folder_base)
Backs up the application to the folder folder_base.
ExecFlagType _current_execute_flag
Current execute on flag.
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
static InputParameters validParams()
std::vector< std::filesystem::path > restart
Filenames for restartable data.
MooseApp & _app
The MOOSE application this is associated with.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Real _wall_time_interval
Target wall time between outputs in seconds.
void setWallTimeIntervalFromCommandLineParam()
Function to set the wall time interval based on value of command line parameter (used for testing onl...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::deque< CheckpointFileNames > _file_names
Vector of checkpoint filename structures.
virtual MooseMesh & mesh() override
int interrupt_signal_number
Used by the signal handler to determine if we should write a checkpoint file out at any point during ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
An outputter with filename support.
virtual int timeStep()
Get the current time step.
processor_id_type processor_id() const
std::string directory() const
Retrieve the checkpoint output directory.
const ExecFlagType EXEC_FINAL
static InputParameters validParams()
void ErrorVector unsigned int
unsigned int _num_files
Max no. of output files to store.
const ExecFlagType EXEC_INITIAL