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();
153 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
158 curr_file_struct.
restart.insert(curr_file_struct.
restart.begin(), paths.begin(), paths.end());
187 const auto remove_file = [
this](
const std::filesystem::path & path)
191 if (!std::filesystem::remove(path,
err))
192 mooseWarning(
"Error during the deletion of checkpoint file\n",
193 std::filesystem::absolute(path),
197 const auto dir = path.parent_path();
198 if (std::filesystem::is_empty(dir))
199 if (!std::filesystem::remove(dir,
err))
200 mooseError(
"Error during the deletion of checkpoint directory\n",
201 std::filesystem::absolute(dir),
216 for (
const auto & path : delete_files.
restart)
222 CheckpointIO::cleanup(delete_files.
checkpoint,
230 const auto & execute_on = getParam<ExecFlagEnum>(
"execute_on");
232 for (
const auto &
value : execute_on)
233 if (!allowed.count(
value))
237 " is not allowed. Allowed flags are INITIAL, TIMESTEP_END, and FINAL.");
244 std::stringstream checkpoint_info;
246 std::stringstream interval_info_ss;
248 const std::string interval_info = interval_info_ss.str();
251 <<
" Wall Time Interval:" << interval_info <<
"\n";
253 const std::string user_info =
"Outputs/" +
name();
255 checkpoint_info << std::left << std::setw(
console_field_width) <<
" Checkpoint:" << user_info
259 <<
" # Checkpoints Kept:" << std::to_string(
_num_files) <<
"\n";
260 std::string exec_on_values =
"";
262 exec_on_values += item.name() +
" ";
264 <<
" Execute On:" << exec_on_values <<
"\n";
266 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
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.
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
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
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...
int interrupt_signal_number
Used by the signal handler to determine if we should write a checkpoint file out at any point during ...
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