31 void load_map(
const std::string &name,
double *data,
int series_number = -1)
34 throw std::runtime_error(
"HDF5Input::map: The map '" + name +
"' has not been written to the file '" +
38 if (series_number < 0) {
39 size_t max_series = 0;
40 for (
const auto &child : super_group.child_names()) {
41 if (!super_group.child_is_group(child))
continue;
42 size_t grp_num = std::stoul(child);
43 if (grp_num > max_series) {
47 series_number =
static_cast<int>(max_series);
49 if (!super_group.has_group(std::to_string(series_number)))
50 throw std::runtime_error(
"HDF5Input::map: The map '" + name +
"' does not have series number " +
51 std::to_string(series_number) +
" in the file '" +
file_name +
"'.");
53 auto group = super_group.open_group(std::to_string(series_number));
55 auto dataset = group.open_dataset(
"data");
56 auto dataspace = dataset.dataspace();
57 std::vector<double> temp_data(dataspace.size());
58 dataset.read(temp_data);
59 std::copy(temp_data.begin(), temp_data.end(), data);
68 std::vector<double>
load_map(
const std::string &name,
int series_number = -1)
71 throw std::runtime_error(
"HDF5Input::map: The map '" + name +
"' has not been written to the file '" +
75 if (series_number < 0) {
76 size_t max_series = 0;
77 for (
const auto &child : super_group.child_names()) {
78 if (!super_group.child_is_group(child))
continue;
79 size_t grp_num = std::stoul(child);
80 if (grp_num > max_series) {
84 series_number =
static_cast<int>(max_series);
86 if (!super_group.has_group(std::to_string(series_number)))
87 throw std::runtime_error(
"HDF5Input::map: The map '" + name +
"' does not have series number " +
88 std::to_string(series_number) +
" in the file '" +
file_name +
"'.");
90 auto group = super_group.open_group(std::to_string(series_number));
92 auto dataset = group.open_dataset(
"data");
93 auto dataspace = dataset.dataspace();
94 std::vector<double> temp_data(dataspace.size());
95 dataset.read(temp_data);
107 template <
size_t dim>
108 std::vector<double>
load_map_coord(
const std::string &name,
int series_number = -1)
111 throw std::runtime_error(
"HDF5Input::map: The map '" + name +
"' has not been written to the file '" +
115 if (series_number < 0) {
116 size_t max_series = 0;
117 for (
const auto &child : super_group.child_names()) {
118 if (!super_group.child_is_group(child))
continue;
119 size_t grp_num = std::stoul(child);
120 if (grp_num > max_series) {
121 max_series = grp_num;
124 series_number =
static_cast<int>(max_series);
126 if (!super_group.has_group(std::to_string(series_number)))
127 throw std::runtime_error(
"HDF5Input::map: The map '" + name +
"' does not have series number " +
128 std::to_string(series_number) +
" in the file '" +
file_name +
"'.");
130 auto group = super_group.open_group(std::to_string(series_number));
132 auto dataset = group.open_dataset(
"coordinates");
133 auto dataspace = dataset.dataspace();
136 std::vector<coord_type> compound_data(dataspace.size());
137 dataset.read(compound_data);
139 std::vector<double> result;
140 result.reserve(dataspace.size() * dim);
141 for (
const auto &pt : compound_data)
142 for (
size_t d = 0; d < dim; ++d)
143 result.push_back(pt[d]);
155 template <
typename Coordinates>
void load_map(
const std::string &name,
double *data,
const Coordinates &coordinates)
161 template <
typename T> std::vector<T>
load_scalar(
const std::string &name)
164 throw std::runtime_error(
"HDF5Input::scalar: The scalar '" + name +
"' has not been written to the file '" +
169 std::vector<T> value(dataspace.size());
179 template <
typename Coordinates>
183 throw std::runtime_error(
"HDF5Input::map: The coordinates '" + coord_name +
184 "' have not been written to the file '" +
file_name +
"'.");
186 const auto in_data =
make_grid(coordinates);
188 using ctype =
typename Coordinates::ctype;
190 std::vector<cortype> file_data(coordinates.size());
193 const auto dataspace = dataset.
dataspace();
194 if (dataspace.size() != (hssize_t)coordinates.size())
195 throw std::runtime_error(
"HDF5Input::map: The coordinates '" + coord_name +
"' in the file '" +
file_name +
196 "' have incorrect size (" + std::to_string(dataspace.size()) +
197 "), not matching the provided coordinates (" + std::to_string(coordinates.size()) +
199 dataset.read(file_data);
201 for (
size_t i = 0; i < coordinates.size(); ++i) {
202 for (
size_t j = 0; j < Coordinates::dim; ++j) {
203 if (std::abs(file_data[i][j] - in_data[i][j]) > 1e-12) {
204 throw std::runtime_error(
"HDF5Input::map: The coordinates '" + coord_name +
205 "' do not match the coordinates in the file '" +
file_name +
"'.");
Dataspace dataspace() const
Definition dataset.hh:31
Dataset open_dataset(const std::string &name)
Definition group.hh:71
bool has_dataset(const std::string &name) const
Definition group.hh:42
bool has_group(const std::string &name) const
Definition group.hh:41
Group open_group(const std::string &name)
Definition group.hh:34
std::array< T, N > array
Definition kokkos.hh:133
Definition complex_math.hh:10
auto make_grid(const Coordinates &coordinates)
Definition coordinates.hh:388