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;
132 Utility::mkdir(cp_dir.c_str());
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)
219 CheckpointIO::cleanup(delete_files.
checkpoint,
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.");
241 std::stringstream checkpoint_info;
243 std::stringstream interval_info_ss;
245 const std::string interval_info = interval_info_ss.str();
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
256 <<
" # Checkpoints Kept:" << std::to_string(
_num_files) <<
"\n";
257 std::string exec_on_values =
"";
259 exec_on_values += item.name() +
" ";
261 <<
" Execute On:" << exec_on_values <<
"\n";
263 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.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
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.
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 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.
virtual std::vector< std::filesystem::path > writeRecoveryFiles(const std::filesystem::path &file_base)
Write the mesh files needed for recovery/checkpointing.
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
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.
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.
void mooseWarning(Args &&... args) const
const std::string & name() const
Get the name of the class.
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.
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
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
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
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 ...
unsigned int _num_files
Max no. of output files to store.
const ExecFlagType EXEC_INITIAL