14#include <system_error>
25#include "libmesh/checkpoint_io.h"
26#include "libmesh/enum_xdr_mode.h"
27#include "libmesh/utility.h"
40 params.
addParam<
unsigned int>(
"num_files", 2,
"Number of the restart files to save");
44 "This will be appended to the file_base to create the directory name for checkpoint files.");
47 "wall_time_interval", 3600,
"The target wall time interval (in seconds) at which to output");
59 _num_files(getParam<unsigned
int>(
"num_files")),
60 _suffix(getParam<
std::string>(
"suffix"))
99 if (!should_output_parent)
105 if (should_output_signal)
107 _console <<
"Unix signal SIGUSR1 detected. Outputting checkpoint file.\n";
115 if (should_output_wall_time)
122 return should_output;
133 const auto current_file =
filename();
141 curr_file_struct.
restart.insert(
142 curr_file_struct.
restart.end(), mesh_paths.begin(), mesh_paths.end());
148 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
153 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
182 const auto remove_file = [
this](
const std::filesystem::path & path)
186 if (!std::filesystem::remove(path, err))
187 mooseWarning(
"Error during the deletion of checkpoint file\n",
188 std::filesystem::absolute(path),
192 const auto dir = path.parent_path();
193 if (std::filesystem::is_empty(dir))
194 if (!std::filesystem::remove(dir, err))
195 mooseError(
"Error during the deletion of checkpoint directory\n",
196 std::filesystem::absolute(dir),
211 for (
const auto & path : delete_files.
restart)
225 const auto & execute_on = getParam<ExecFlagEnum>(
"execute_on");
227 for (
const auto & value : execute_on)
228 if (!allowed.count(value))
232 " is not allowed. Allowed flags are INITIAL, TIMESTEP_END, and FINAL.");
238 static const unsigned int console_field_width = 27;
239 std::stringstream checkpoint_info;
241 std::stringstream interval_info_ss;
243 const std::string interval_info = interval_info_ss.str();
245 checkpoint_info << std::left << std::setw(console_field_width)
246 <<
" Wall Time Interval:" << interval_info <<
"\n";
248 const std::string user_info =
"Outputs/" +
name();
250 checkpoint_info << std::left << std::setw(console_field_width) <<
" Checkpoint:" << user_info
253 checkpoint_info << std::left << std::setw(console_field_width)
254 <<
" # Checkpoints Kept:" << std::to_string(
_num_files) <<
"\n";
255 std::string exec_on_values =
"";
257 exec_on_values += item.name() +
" ";
258 checkpoint_info << std::left << std::setw(console_field_width)
259 <<
" Execute On:" << exec_on_values <<
"\n";
261 return checkpoint_info;
registerMooseObject("MooseApp", Checkpoint)
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
const ExecFlagType EXEC_TIMESTEP_END
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_FINAL
void ErrorVector unsigned int
void updateCheckpointFiles(CheckpointFileNames file_struct)
std::stringstream checkpointInfo() const
Gathers and records information used later for console output.
void validateExecuteOn() const
Determines if the requested values of execute_on are valid for checkpoints.
std::string directory() const
Retrieve the checkpoint output directory.
virtual std::string filename() override
Returns the base filename for the checkpoint files.
virtual void output() override
Outputs a checkpoint file.
virtual bool shouldOutput() override
Determines if the checkpoint should write out to a file.
static InputParameters validParams()
Checkpoint(const InputParameters ¶meters)
Class constructor.
std::deque< CheckpointFileNames > _file_names
Vector of checkpoint filename structures.
const std::string _suffix
Directory suffix.
unsigned int _num_files
Max no. of output files to store.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
A MultiMooseEnum object to hold "execute_on" flags.
virtual MooseMesh & mesh() override
An outputter with filename support.
unsigned int _padding
Number of digits to pad the extensions.
static InputParameters validParams()
virtual bool shouldOutput() override
Checks if the output method should be executed.
std::string _file_base
The base filename from the input paramaters.
std::vector< std::filesystem::path > backup(const std::filesystem::path &folder_base)
Backs up the application to the folder folder_base.
static const std::string & checkpointSuffix()
The file suffix for the checkpoint mesh.
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.
std::filesystem::path restartFolderBase(const std::filesystem::path &folder_base) const
The file suffix for restartable data.
const std::string & name() const
Get the name of the class.
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 ...
virtual std::vector< std::filesystem::path > writeRecoveryFiles(const std::filesystem::path &file_base)
Write the mesh files needed for recovery/checkpointing.
virtual bool isDistributedMesh() const
Returns the final Mesh distribution type.
MooseApp & _app
The MOOSE application this is associated with.
Real _wall_time_since_last_output
time in seconds since last output
Real _wall_time_interval
Target wall time between outputs in seconds.
ExecFlagEnum _execute_on
The common Execution types; this is used as the default execution type for everything except system i...
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
void setWallTimeIntervalFromCommandLineParam()
Function to set the wall time interval based on value of command line parameter (used for testing onl...
virtual int timeStep()
Get the current time step.
ExecFlagType _current_execute_flag
Current execute on flag.
virtual bool onInterval()
Returns true if the output interval is satisfied.
processor_id_type size() const
static void cleanup(const std::string &input_name, processor_id_type n_procs)
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
volatile std::sig_atomic_t interrupt_signal_number
Used by the signal handler to determine if we should write a checkpoint file out at any point during ...
int mkdir(const char *pathname)
A structure for storing the various output files associated with checkpoint output.
std::string checkpoint
Filename for CheckpointIO file (the mesh)
std::vector< std::filesystem::path > restart
Filenames for restartable data.