14 #include <system_error> 25 #include "libmesh/checkpoint_io.h" 26 #include "libmesh/enum_xdr_mode.h" 27 #include "libmesh/utility.h" 47 params.
addParam<
unsigned int>(
"num_files", 2,
"Number of the restart files to save");
51 "This will be appended to the file_base to create the directory name for checkpoint files.");
54 "wall_time_interval", 3600,
"The target wall time interval (in seconds) at which to output");
58 "wall_time_checkpoint",
true,
"Whether to enable checkpoints based on elapsed wall time");
71 _num_files(getParam<unsigned
int>(
"num_files")),
72 _suffix(getParam<
std::string>(
"suffix"))
86 if (!getParam<bool>(
"wall_time_checkpoint"))
115 if (!should_output_parent)
121 if (should_output_signal)
123 _console <<
"Unix signal SIGUSR1 detected. Outputting checkpoint file.\n";
131 if (should_output_wall_time)
146 return should_output;
154 Utility::mkdir(cp_dir.c_str());
157 const auto current_file =
filename();
175 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
180 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
209 const auto remove_file = [
this](
const std::filesystem::path & path)
213 if (!std::filesystem::remove(path,
err))
214 mooseWarning(
"Error during the deletion of checkpoint file\n",
215 std::filesystem::absolute(path),
219 const auto dir = path.parent_path();
220 if (std::filesystem::is_empty(dir))
221 if (!std::filesystem::remove(dir,
err))
222 mooseError(
"Error during the deletion of checkpoint directory\n",
223 std::filesystem::absolute(dir),
238 for (
const auto & path : delete_files.
restart)
244 CheckpointIO::cleanup(delete_files.
checkpoint,
252 const auto & execute_on = getParam<ExecFlagEnum>(
"execute_on");
254 for (
const auto &
value : execute_on)
255 if (!allowed.count(
value))
259 " is not allowed. Allowed flags are INITIAL, TIMESTEP_END, and FINAL.");
266 std::stringstream checkpoint_info;
268 std::string interval_info;
269 if (getParam<bool>(
"wall_time_checkpoint"))
271 std::stringstream interval_info_ss;
273 interval_info = interval_info_ss.str();
276 interval_info =
"Disabled";
279 <<
" Wall Time Interval:" << interval_info <<
"\n";
281 std::string user_info;
283 user_info =
"Disabled";
285 user_info =
"Outputs/" +
name();
288 <<
" User Checkpoint:" << user_info <<
"\n";
290 if (!((interval_info ==
"Disabled") && (user_info ==
"Disabled")))
293 <<
" # Checkpoints Kept:" << std::to_string(
_num_files) <<
"\n";
294 std::string exec_on_values =
"";
296 exec_on_values += item.name() +
" ";
298 <<
" Execute On:" << exec_on_values <<
"\n";
301 return checkpoint_info;
static const std::string & checkpointSuffix()
The file suffix for the checkpoint mesh.
virtual bool shouldOutput() override
Checks if the output method should be executed.
virtual void write(const std::string &name) override
A MultiMooseEnum object to hold "execute_on" flags.
Checkpoint(const InputParameters ¶meters)
Class constructor.
ExecFlagEnum _execute_on
The common Execution types; this is used as the default execution type for everything except system i...
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.
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)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
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
virtual const std::string & name() const
Get the name of the class.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
void validateExecuteOn() const
Determines if the requested values of execute_on are valid for checkpoints.
static const unsigned int console_field_width
Width used for printing simulation information.
auto max(const L &left, const R &right)
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.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual void output() override
Outputs a checkpoint file.
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
libMesh::EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
const MeshBase & get_mesh() const
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.
std::stringstream checkpointInfo() const
Gathers and records information used later for console output.
processor_id_type processor_id() const
virtual bool isDistributedMesh() const
Returns the final Mesh distribution type.
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