14#include <system_error>
25#include "libmesh/checkpoint_io.h"
26#include "libmesh/enum_xdr_mode.h"
27#include "libmesh/utility.h"
42 params.
addParam<
unsigned int>(
"num_files", 2,
"Number of the restart files to save");
46 "This will be appended to the file_base to create the directory name for checkpoint files.");
49 "wall_time_interval", 3600,
"The target wall time interval (in seconds) at which to output");
61 _num_files(getParam<unsigned
int>(
"num_files")),
62 _suffix(getParam<
std::string>(
"suffix"))
101 if (!should_output_parent)
107 if (should_output_signal)
109 _console <<
"Unix signal SIGUSR1 detected. Outputting checkpoint file.\n";
117 if (should_output_wall_time)
124 return should_output;
135 const auto current_file =
filename();
143 curr_file_struct.
restart.insert(
144 curr_file_struct.
restart.end(), mesh_paths.begin(), mesh_paths.end());
150 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
155 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
184 const auto remove_file = [
this](
const std::filesystem::path & path)
188 if (!std::filesystem::remove(path,
err))
189 mooseWarning(
"Error during the deletion of checkpoint file\n",
190 std::filesystem::absolute(path),
194 const auto dir = path.parent_path();
195 if (std::filesystem::is_empty(dir))
196 if (!std::filesystem::remove(dir,
err))
197 mooseError(
"Error during the deletion of checkpoint directory\n",
198 std::filesystem::absolute(dir),
213 for (
const auto & path : delete_files.
restart)
227 const auto & execute_on = getParam<ExecFlagEnum>(
"execute_on");
229 for (
const auto & value : execute_on)
230 if (!allowed.count(value))
234 " is not allowed. Allowed flags are INITIAL, TIMESTEP_END, and FINAL.");
240 static const unsigned int console_field_width = 27;
241 std::stringstream checkpoint_info;
243 std::stringstream interval_info_ss;
245 const std::string interval_info = interval_info_ss.str();
247 checkpoint_info << std::left << std::setw(console_field_width)
248 <<
" Wall Time Interval:" << interval_info <<
"\n";
250 const std::string user_info =
"Outputs/" +
name();
252 checkpoint_info << std::left << std::setw(console_field_width) <<
" Checkpoint:" << user_info
255 checkpoint_info << std::left << std::setw(console_field_width)
256 <<
" # Checkpoints Kept:" << std::to_string(
_num_files) <<
"\n";
257 std::string exec_on_values =
"";
259 exec_on_values += item.name() +
" ";
260 checkpoint_info << std::left << std::setw(console_field_width)
261 <<
" Execute On:" << exec_on_values <<
"\n";
263 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)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
OStreamProxy err(std::cerr)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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.