Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : // MOOSE includes 13 : #include "FileOutput.h" 14 : #include "AutoCheckpointAction.h" 15 : 16 : #include <deque> 17 : #include <filesystem> 18 : 19 : /** 20 : * Enumerated type for determining what type of checkpoint this is. 21 : * SYSTEM_CREATED: This type of checkpoint is created automatically by the 22 : * system for the purpose of writing checkpoints at regularly scheduled 23 : * walltime intervals or when sent a signal. 24 : * USER_CREATED: Checkpoint is requested by the user in the input 25 : * file, and can be used by the system to also output at walltime intervals or 26 : * when sent a signal. 27 : */ 28 : enum CheckpointType : unsigned short 29 : { 30 : SYSTEM_CREATED, 31 : USER_CREATED 32 : }; 33 : 34 : class MaterialPropertyStorage; 35 : 36 : /** 37 : * A structure for storing the various output files associated with checkpoint output 38 : */ 39 : struct CheckpointFileNames 40 : { 41 : /// Filename for CheckpointIO file (the mesh) 42 : std::string checkpoint; 43 : 44 : /// Filenames for restartable data 45 : std::vector<std::filesystem::path> restart; 46 : 47 13315 : bool operator==(const CheckpointFileNames & rhs) const 48 : { 49 : // Compare the relevant members for equality 50 13315 : return (this->checkpoint == rhs.checkpoint) && (this->restart == rhs.restart); 51 : } 52 : }; 53 : 54 : /** 55 : * Writes out three things: 56 : * 57 : * 1. A restart file with a `.rd` extendsion that contains a single Backup that has been serialized 58 : * 2. Mesh file(s) in the form of a libMesh Checkpoint file(s) 59 : * 3. Mesh meta-data file... this will be underneath the directory that the Checkpoint mesh creates 60 : * 61 : * These files are written to a directory called output_prefix + _ + "_cp" 62 : */ 63 : class Checkpoint : public FileOutput 64 : { 65 : 66 : friend class AutoCheckpointAction; 67 : 68 : public: 69 : static InputParameters validParams(); 70 : 71 : /** 72 : * Class constructor 73 : * @param parameters 74 : */ 75 : Checkpoint(const InputParameters & parameters); 76 : 77 : /** 78 : * Returns the base filename for the checkpoint files 79 : */ 80 : virtual std::string filename() override; 81 : 82 : /** 83 : * Retrieve the checkpoint output directory 84 : * @return String containing the checkpoint output directory 85 : */ 86 : std::string directory() const; 87 : 88 : /// Sets the autosave flag manually if the object has already been initialized. 89 2829 : void setAutosaveFlag(CheckpointType flag) { _checkpoint_type = flag; } 90 : 91 : /** 92 : * Gathers and records information used later for console output 93 : * @return A stringstream containing the following entries: 94 : * Wall Time Interval : interval length in seconds, if any, otherwise "Disabled" 95 : * User Checkpoint : name of user-define checkpoint, if any, otherwise "Disabled" 96 : * # Checkpoints Kept : value if the 'num_files' parameter 97 : * Execute On : value of the 'execute_on' parameter 98 : */ 99 : std::stringstream checkpointInfo() const; 100 : 101 2029 : bool supportsMaterialPropertyOutput() const override { return true; } 102 : 103 : protected: 104 : /** 105 : * Outputs a checkpoint file. 106 : * Each call to this function creates various files associated with 107 : */ 108 : virtual void output() override; 109 : 110 : /// Determines if the checkpoint should write out to a file. 111 : virtual bool shouldOutput() override; 112 : 113 : private: 114 : void updateCheckpointFiles(CheckpointFileNames file_struct); 115 : 116 : /// Determines if the requested values of execute_on are valid for checkpoints 117 : void validateExecuteOn() const; 118 : 119 : /// Determines if this checkpoint is an autosave, and what kind of autosave it is. 120 : CheckpointType _checkpoint_type; 121 : 122 : /// Max no. of output files to store 123 : unsigned int _num_files; 124 : 125 : /// Directory suffix 126 : const std::string _suffix; 127 : 128 : /// Vector of checkpoint filename structures 129 : std::deque<CheckpointFileNames> _file_names; 130 : };