16 #include <system_error> 34 value.setNotStored({});
37 char id[] = {
'R',
'D'};
38 header_stream.write(
id, 2);
42 dataStore(header_stream, file_version,
nullptr);
46 dataStore(header_stream, compare_hash_code,
nullptr);
50 dataStore(header_stream, n_procs,
nullptr);
54 dataStore(header_stream, num_data,
nullptr);
60 dataStore(header_stream, n_data,
nullptr);
68 const std::size_t data_start_position =
static_cast<std::size_t
>(data_stream.tellp());
69 data.store(data_stream);
70 std::size_t data_size =
static_cast<std::size_t
>(data_stream.tellp()) - data_start_position;
73 mooseAssert(data.name().size(),
"Empty name");
74 std::string
name = data.name();
75 std::string type = data.typeId().name();
76 std::size_t type_hash_code = data.typeId().hash_code();
77 bool has_context = data.hasContext();
79 dataStore(header_stream, data_size,
nullptr);
80 dataStore(header_stream, type_hash_code,
nullptr);
82 dataStore(header_stream, has_context,
nullptr);
86 std::vector<std::filesystem::path>
93 const auto dir = header_file.parent_path();
94 mooseAssert(dir == data_file.parent_path(),
"Inconsistent directories");
95 if (!std::filesystem::exists(dir))
98 if (!std::filesystem::create_directory(dir,
err))
99 mooseError(
"Unable to create restart directory\n",
100 std::filesystem::absolute(dir),
107 std::vector<std::filesystem::path> paths;
110 auto open = [&paths](
const std::filesystem::path & filename)
112 std::ofstream stream;
113 stream.open(filename.c_str(), std::ios::out | std::ios::binary);
114 if (!stream.is_open())
116 "Unable to open restart file ", std::filesystem::absolute(filename),
" for writing");
117 paths.push_back(filename);
122 auto header_stream = open(header_file);
123 auto data_stream = open(data_file);
124 write(header_stream, data_stream);
128 const auto data_write_time = std::filesystem::last_write_time(header_file);
129 std::filesystem::last_write_time(dir, data_write_time);
std::string name(const ElemQuality q)
void write(std::ostream &header_stream, std::ostream &data_stream)
Writes the restartable data to header stream header_stream and data stream data_stream.
static const std::string & restartableDataFile()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static const unsigned int CURRENT_BACKUP_FILE_VERSION
The current version for the backup file.
std::size_t dataSize() const
static const std::string & restartableHeaderFile()
Base class for MOOSE-based applications.
int COMPARE_HASH_CODE_TYPE
The type to used for comparing hash codes (sanity checking)
RestartableDataMap & currentData(const THREAD_ID tid)
Storage for restartable data that is ordered based on insertion order.
RestartableDataWriter(MooseApp &app, RestartableDataMap &data)
processor_id_type n_processors() const
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
IntRange< T > make_range(T beg, T end)
void dataStore(std::ostream &stream, PenetrationInfo *&pinfo, void *context)