37 double interval_ = 0.01;
38 std::filesystem::path directory_;
42 const std::filesystem::path &output_directory)
45 result.load_ = runtime.value(
"checkpoint_load",
false);
46 result.save_ = runtime.value(
"checkpoint_save",
false);
47 result.cycle_ = runtime.value(
"checkpoint_cycle", 0);
48 result.interval_ = runtime.value(
"checkpoint_dt", 0.01);
50 const auto folder = runtime.value(
"checkpoints_folder", std::string(
"Checkpoints"));
53 throw std::invalid_argument(
"runTime.checkpoints_folder must not be empty");
55 result.directory_ = output_directory / folder;
57 if ((result.load_ || result.save_) && result.interval_ <= 0.0)
59 throw std::invalid_argument(
"runTime.checkpoint_dt must be greater than zero");
61 if (result.load_ && result.cycle_ <= 0)
63 throw std::invalid_argument(
64 "runTime.checkpoint_cycle must be greater than zero when checkpoint_load is true");
71 int Cycle()
const {
return cycle_; }
73 const std::filesystem::path &
Directory()
const {
return directory_; }
77 return directory_ / (
"Cycle" + std::to_string(cycle));
83 (
"checkpoint_cycle_" + std::to_string(cycle) +
".json");
86 std::filesystem::path
RankFile(
int cycle,
int rank)
const
88 std::ostringstream filename;
89 filename <<
"checkpoint_cycle_" << cycle <<
"."
90 << std::setw(8) << std::setfill(
'0') << rank <<
".chk";
94 static nlohmann::json
Metadata(
double time,
int cycle,
97 return {{
"format_version", 2},
98 {
"state_format",
"raw_vector_v1"},
99 {
"state_representation",
"conservative"},
100 {
"geometry", compatibility.
axisymmetric ?
"axisymmetric" :
"cartesian"},
105 {
"order", compatibility.
order},
116 if (!metadata.contains(
"format_version"))
120 throw std::invalid_argument(
121 "Legacy checkpoint cannot establish axisymmetric conservative-state semantics");
125 const int format_version = metadata.value(
"format_version", 0);
126 if (format_version != 1 && format_version != 2)
128 throw std::invalid_argument(
"Unsupported checkpoint metadata format version");
130 if (metadata.value(
"state_format", std::string()) !=
"raw_vector_v1")
132 throw std::invalid_argument(
"Unsupported checkpoint state format");
136 throw std::invalid_argument(
137 "Version 1 checkpoint cannot establish whether an axisymmetric state stores U or rU");
139 if (format_version == 2)
141 if (metadata.value(
"state_representation", std::string()) !=
"conservative")
143 throw std::invalid_argument(
"Unsupported checkpoint state representation");
145 const std::string expected_geometry =
147 if (metadata.value(
"geometry", std::string()) != expected_geometry)
149 throw std::invalid_argument(
150 "Checkpoint is incompatible with the current run: geometry differs");
153 if (metadata.value(
"real_bytes", 0) != expected.
real_bytes)
155 throw std::invalid_argument(
"Checkpoint floating-point representation differs");
158 const auto require_equal = [&metadata](
const char *name,
long long value)
160 if (!metadata.contains(name) || metadata.at(name).get<
long long>() != value)
162 throw std::invalid_argument(
163 "Checkpoint is incompatible with the current run: " + std::string(name) +
167 require_equal(
"mpi_ranks", expected.
mpi_ranks);
168 require_equal(
"order", expected.
order);
169 require_equal(
"dimension", expected.
dimension);
172 require_equal(
"global_dofs", expected.
global_dofs);
Definition CheckpointConfig.hpp:32
static nlohmann::json Metadata(double time, int cycle, const CheckpointCompatibility &compatibility)
Definition CheckpointConfig.hpp:94
int Cycle() const
Definition CheckpointConfig.hpp:71
static CheckpointConfig FromRuntime(const nlohmann::json &runtime, const std::filesystem::path &output_directory)
Definition CheckpointConfig.hpp:41
bool LoadEnabled() const
Definition CheckpointConfig.hpp:69
double Interval() const
Definition CheckpointConfig.hpp:72
std::filesystem::path RankFile(int cycle, int rank) const
Definition CheckpointConfig.hpp:86
const std::filesystem::path & Directory() const
Definition CheckpointConfig.hpp:73
std::filesystem::path CycleDirectory(int cycle) const
Definition CheckpointConfig.hpp:75
bool SaveEnabled() const
Definition CheckpointConfig.hpp:70
std::filesystem::path MetadataFile(int cycle) const
Definition CheckpointConfig.hpp:80
static bool ValidateMetadata(const nlohmann::json &metadata, const CheckpointCompatibility &expected)
Definition CheckpointConfig.hpp:113
Definition AxisymmetricGeometry.hpp:15
Definition CheckpointConfig.hpp:20
int dimension
Definition CheckpointConfig.hpp:23
int num_equations
Definition CheckpointConfig.hpp:24
bool axisymmetric
Definition CheckpointConfig.hpp:28
int real_bytes
Definition CheckpointConfig.hpp:25
int order
Definition CheckpointConfig.hpp:22
long long global_elements
Definition CheckpointConfig.hpp:26
int mpi_ranks
Definition CheckpointConfig.hpp:21
long long global_dofs
Definition CheckpointConfig.hpp:27