GCC Code Coverage Report


Directory: gridformat/
File: gridformat/vtk/hdf_unstructured_grid_reader.hpp
Date: 2024-11-10 16:24:00
Exec Total Coverage
Lines: 256 271 94.5%
Functions: 84 124 67.7%
Branches: 367 944 38.9%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 /*!
4 * \file
5 * \ingroup VTK
6 * \brief Reader for the VTK HDF file format for unstructured grids.
7 */
8 #ifndef GRIDFORMAT_VTK_HDF_UNSTRUCTURED_GRID_READER_HPP_
9 #define GRIDFORMAT_VTK_HDF_UNSTRUCTURED_GRID_READER_HPP_
10 #if GRIDFORMAT_HAVE_HIGH_FIVE
11
12 #include <iterator>
13 #include <optional>
14 #include <algorithm>
15 #include <type_traits>
16 #include <concepts>
17 #include <numeric>
18 #include <utility>
19 #include <cassert>
20
21 #include <gridformat/common/field.hpp>
22 #include <gridformat/common/field_transformations.hpp>
23 #include <gridformat/common/concepts.hpp>
24 #include <gridformat/common/exceptions.hpp>
25 #include <gridformat/grid/reader.hpp>
26 #include <gridformat/parallel/concepts.hpp>
27 #include <gridformat/vtk/hdf_common.hpp>
28
29 namespace GridFormat {
30
31 /*!
32 * \ingroup VTK
33 * \brief Reader for the VTK-HDF file format for unstructured grids.
34 */
35 template<Concepts::Communicator Communicator = NullCommunicator>
36 class VTKHDFUnstructuredGridReader : public GridReader {
37 using HDF5File = HDF5::File<Communicator>;
38 static constexpr std::size_t vtk_space_dim = 3;
39 static constexpr bool read_rank_piece_only = !std::is_same_v<Communicator, NullCommunicator>;
40
41 public:
42 2 explicit VTKHDFUnstructuredGridReader() requires(std::is_same_v<Communicator, NullCommunicator>)
43 2 : _comm{}
44 2 {}
45
46 72 explicit VTKHDFUnstructuredGridReader(Communicator comm)
47 72 : _comm{comm}
48 72 {}
49
50 private:
51 1 std::string _name() const override {
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (_is_transient())
53 return "VTKHDFUnstructuredGridReader (transient)";
54
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return "VTKHDFUnstructuredGridReader";
55 }
56
57 74 void _open(const std::string& filename, typename GridReader::FieldNames& field_names) override {
58
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
74 _close();
59
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
74 _file = HDF5File{filename, _comm, HDF5File::read_only};
60
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
74 const auto type = VTKHDF::get_file_type(_file.value());
61
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 44 times.
74 if (type != "UnstructuredGrid")
62 throw ValueError("Incompatible VTK-HDF type: '" + type + "', expected 'UnstructuredGrid'.");
63
64
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
74 VTKHDF::check_version_compatibility(_file.value(), {2, 0});
65
66
4/6
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 44 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 19 times.
✓ Branch 9 taken 25 times.
222 if (_file->exists("VTKHDF/Steps"))
67
2/4
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 19 times.
✗ Branch 6 not taken.
146 _file->visit_attribute("VTKHDF/Steps/NSteps", [&] (auto&& field) {
68 19 _num_steps.emplace();
69 19 field.export_to(_num_steps.value());
70 19 _step_index.emplace(0);
71 });
72
73
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
74 _compute_piece_offsets();
74 192 const auto copy_names_in = [&] (const std::string& group, auto& storage) {
75
4/4
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 4 times.
✓ Branch 6 taken 76 times.
✓ Branch 7 taken 8 times.
132 if (_file->exists(group))
76
4/8
✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 44 times.
✗ Branch 7 not taken.
✓ Branch 13 taken 76 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 76 times.
✗ Branch 17 not taken.
120 std::ranges::copy(_file->dataset_names_in(group), std::back_inserter(storage));
77 };
78
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
148 copy_names_in("VTKHDF/CellData", field_names.cell_fields);
79
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
148 copy_names_in("VTKHDF/PointData", field_names.point_fields);
80
2/4
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
148 copy_names_in("VTKHDF/FieldData", field_names.meta_data_fields);
81 74 }
82
83 74 void _close() override {
84
1/2
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
74 _file = {};
85 74 _num_cells = 0;
86 74 _num_points = 0;
87 74 _cell_offset = 0;
88 74 _point_offset = 0;
89 74 _num_steps = {};
90 74 _step_index = {};
91 74 }
92
93 302 void _compute_piece_offsets() {
94 302 _cell_offset = 0;
95 302 _point_offset = 0;
96
1/2
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
302 _check_communicator_size();
97
2/4
✓ Branch 1 taken 180 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 180 times.
✗ Branch 5 not taken.
604 const auto num_step_cells = _number_of_all_piece_entities("Cells");
98
2/4
✓ Branch 1 taken 180 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 180 times.
✗ Branch 5 not taken.
302 const auto num_step_points = _number_of_all_piece_entities("Points");
99 if constexpr (read_rank_piece_only) {
100
1/2
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
232 const auto my_rank = Parallel::rank(_comm);
101
1/2
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
232 _num_cells = num_step_cells.at(my_rank);
102
1/2
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
232 _num_points = num_step_points.at(my_rank);
103 232 _cell_offset += _accumulate_until(my_rank, num_step_cells);
104 232 _point_offset += _accumulate_until(my_rank, num_step_points);
105 } else {
106 70 _num_cells = _accumulate_until(num_step_cells.size(), num_step_cells);
107 70 _num_points = _accumulate_until(num_step_points.size(), num_step_points);
108 }
109 302 }
110
111 1661 std::size_t _get_part_offset() const {
112 1661 return _is_transient()
113
13/28
✓ Branch 0 taken 874 times.
✓ Branch 1 taken 139 times.
✓ Branch 3 taken 874 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 874 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 874 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 874 times.
✓ Branch 13 taken 139 times.
✓ Branch 14 taken 874 times.
✓ Branch 15 taken 139 times.
✓ Branch 17 taken 874 times.
✓ Branch 18 taken 139 times.
✓ Branch 20 taken 874 times.
✓ Branch 21 taken 139 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
7618 ? _access_file().template read_dataset_to<std::size_t>(
114 "/VTKHDF/Steps/PartOffsets",
115 HDF5::Slice{
116
1/2
✓ Branch 1 taken 874 times.
✗ Branch 2 not taken.
1432 .offset = {_step_index.value()},
117 .count = {1}
118 })
119
2/2
✓ Branch 0 taken 874 times.
✓ Branch 1 taken 139 times.
3322 : std::size_t{0};
120
4/14
✓ Branch 1 taken 874 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 874 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 874 times.
✓ Branch 9 taken 139 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
7389 }
121
122 926 std::size_t _get_step_cells_offset() const {
123 926 return _is_transient()
124
15/30
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 74 times.
✓ Branch 3 taken 472 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 472 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 472 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 472 times.
✓ Branch 13 taken 74 times.
✓ Branch 14 taken 472 times.
✓ Branch 15 taken 74 times.
✓ Branch 17 taken 472 times.
✓ Branch 18 taken 74 times.
✓ Branch 20 taken 472 times.
✓ Branch 21 taken 74 times.
✓ Branch 22 taken 472 times.
✓ Branch 23 taken 74 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
5052 ? _access_file().template read_dataset_to<std::size_t>(
125 "VTKHDF/Steps/CellOffsets",
126 HDF5::Slice{
127
1/2
✓ Branch 1 taken 472 times.
✗ Branch 2 not taken.
800 .offset = {_step_index.value(), 0},
128 .count = {1, 1}
129 })
130
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 74 times.
1852 : std::size_t{0};
131
2/12
✓ Branch 1 taken 472 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 472 times.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
3326 }
132
133 227 std::size_t _get_step_points_offset() const {
134 227 return _is_transient()
135
13/28
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 22 times.
✓ Branch 3 taken 113 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 113 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 113 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 113 times.
✓ Branch 13 taken 22 times.
✓ Branch 14 taken 113 times.
✓ Branch 15 taken 22 times.
✓ Branch 17 taken 113 times.
✓ Branch 18 taken 22 times.
✓ Branch 20 taken 113 times.
✓ Branch 21 taken 22 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
1024 ? _access_file().template read_dataset_to<std::size_t>(
136 "VTKHDF/Steps/PointOffsets",
137 HDF5::Slice{
138
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
190 .offset = {_step_index.value()},
139 .count = {1}
140 })
141
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 22 times.
454 : std::size_t{0};
142
4/14
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 113 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 113 times.
✓ Branch 9 taken 22 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
987 }
143
144 463 std::size_t _get_connectivity_id_offset() const {
145 463 return _is_transient()
146
15/30
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 37 times.
✓ Branch 3 taken 236 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 236 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 236 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 236 times.
✓ Branch 13 taken 37 times.
✓ Branch 14 taken 236 times.
✓ Branch 15 taken 37 times.
✓ Branch 17 taken 236 times.
✓ Branch 18 taken 37 times.
✓ Branch 20 taken 236 times.
✓ Branch 21 taken 37 times.
✓ Branch 22 taken 236 times.
✓ Branch 23 taken 37 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
2526 ? _access_file().template read_dataset_to<std::size_t>(
147 "VTKHDF/Steps/ConnectivityIdOffsets",
148 HDF5::Slice{
149
1/2
✓ Branch 1 taken 236 times.
✗ Branch 2 not taken.
400 .offset = {_step_index.value(), 0},
150 .count = {1, 1}
151 })
152
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 37 times.
926 : std::size_t{0};
153
2/12
✓ Branch 1 taken 236 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 236 times.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
1663 }
154
155 1152 std::size_t _get_cell_data_offset(std::string_view name) const {
156 1152 return _is_transient()
157
8/18
✓ Branch 0 taken 570 times.
✓ Branch 1 taken 114 times.
✓ Branch 3 taken 570 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 570 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 570 times.
✓ Branch 10 taken 114 times.
✓ Branch 12 taken 570 times.
✓ Branch 13 taken 114 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
4224 ? _access_file().template read_dataset_to<std::size_t>(
158
8/16
✓ Branch 1 taken 570 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 570 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 570 times.
✓ Branch 8 taken 114 times.
✓ Branch 10 taken 570 times.
✓ Branch 11 taken 114 times.
✓ Branch 12 taken 570 times.
✓ Branch 13 taken 114 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3072 "VTKHDF/Steps/CellDataOffsets/" + std::string{name},
159 HDF5::Slice{
160
1/2
✓ Branch 1 taken 570 times.
✗ Branch 2 not taken.
960 .offset = {_step_index.value()},
161 .count = {1}
162 })
163
2/2
✓ Branch 0 taken 570 times.
✓ Branch 1 taken 114 times.
2304 : std::size_t{0};
164
4/14
✓ Branch 1 taken 570 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 570 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 570 times.
✓ Branch 9 taken 114 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
4992 }
165
166 1162 std::size_t _get_point_data_offset(std::string_view name) const {
167 1162 return _is_transient()
168
8/18
✓ Branch 0 taken 570 times.
✓ Branch 1 taken 120 times.
✓ Branch 3 taken 570 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 570 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 570 times.
✓ Branch 10 taken 120 times.
✓ Branch 12 taken 570 times.
✓ Branch 13 taken 120 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
4244 ? _access_file().template read_dataset_to<std::size_t>(
169
8/16
✓ Branch 1 taken 570 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 570 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 570 times.
✓ Branch 8 taken 120 times.
✓ Branch 10 taken 570 times.
✓ Branch 11 taken 120 times.
✓ Branch 12 taken 570 times.
✓ Branch 13 taken 120 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3082 "VTKHDF/Steps/PointDataOffsets/" + std::string{name},
170 HDF5::Slice{
171
1/2
✓ Branch 1 taken 570 times.
✗ Branch 2 not taken.
960 .offset = {_step_index.value()},
172 .count = {1}
173 })
174
2/2
✓ Branch 0 taken 570 times.
✓ Branch 1 taken 120 times.
2324 : std::size_t{0};
175
4/14
✓ Branch 1 taken 570 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 570 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 570 times.
✓ Branch 9 taken 120 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
5002 }
176
177 150 std::size_t _get_field_data_offset(std::string_view name) const {
178 150 return _is_transient()
179
5/18
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 90 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 90 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 90 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 90 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
600 ? _access_file().template read_dataset_to<std::size_t>(
180
5/16
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 90 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 90 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 90 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
450 "VTKHDF/Steps/FieldDataOffsets/" + std::string{name},
181 HDF5::Slice{
182
1/2
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
150 .offset = {_step_index.value()},
183 .count = {1}
184 })
185
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
300 : std::size_t{0};
186
3/14
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 90 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
750 }
187
188 45 bool _is_sequence() const override {
189 45 return _is_transient();
190 }
191
192 542 std::size_t _number_of_steps() const override {
193
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
542 if (!_num_steps)
194 throw ValueError("No step information available");
195 542 return _num_steps.value();
196 }
197
198 160 double _time_at_step(std::size_t step_idx) const override {
199
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 95 times.
160 if (step_idx >= _number_of_steps())
200 throw ValueError("Only " + as_string(_number_of_steps()) + " available");
201
2/4
✓ Branch 2 taken 95 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 95 times.
✗ Branch 6 not taken.
640 return _access_file().template read_dataset_to<double>("/VTKHDF/Steps/Values", HDF5::Slice{
202 .offset = {step_idx},
203 .count = {1}
204 320 });
205
2/8
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 95 times.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
640 }
206
207 260 void _set_step(std::size_t step_idx, typename GridReader::FieldNames&) override {
208
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 155 times.
260 if (step_idx >= _number_of_steps())
209 throw ValueError("Only " + as_string(_number_of_steps()) + " available");
210
2/2
✓ Branch 1 taken 136 times.
✓ Branch 2 taken 19 times.
260 if (step_idx != _step_index.value()) {
211 228 _compute_piece_offsets();
212 228 _step_index = step_idx;
213 }
214 260 }
215
216 367 std::size_t _number_of_cells() const override {
217 367 return _num_cells;
218 }
219
220 721 std::size_t _number_of_points() const override {
221 721 return _num_points;
222 }
223
224 28 std::size_t _number_of_pieces() const override {
225 28 return _number_of_current_pieces_in_file();
226 }
227
228 2028 std::size_t _number_of_current_pieces_in_file() const {
229
2/2
✓ Branch 1 taken 1062 times.
✓ Branch 2 taken 178 times.
2028 if (_is_transient())
230 1734 return _number_of_pieces_in_file_at_step(_step_index.value());
231 294 return _total_number_of_pieces();
232 }
233
234 294 std::size_t _total_number_of_pieces() const {
235
3/6
✓ Branch 1 taken 178 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 178 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 178 times.
✗ Branch 8 not taken.
588 auto ncells = _access_file().get_dimensions("/VTKHDF/NumberOfCells");
236
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
294 if (!ncells) throw IOError("Missing dataset at '/VTKHDF/NumberOfCells'");
237
1/4
✗ Branch 2 not taken.
✓ Branch 3 taken 178 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
294 if (ncells->size() != 1) throw IOError("Unexpected dimension of '/VTKHDF/NumberOfCells'");
238
1/2
✓ Branch 2 taken 178 times.
✗ Branch 3 not taken.
588 return ncells->at(0);
239 294 }
240
241 2554 std::size_t _number_of_pieces_in_file_at_step(std::size_t step) const {
242
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1546 times.
2554 if (!_is_transient())
243 throw InvalidState("Step data only available in transient files");
244
3/6
✓ Branch 2 taken 1546 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1546 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1546 times.
✗ Branch 9 not taken.
7662 if (const auto& file = _access_file(); file.exists("/VTKHDF/Steps/NumberOfParts"))
245
3/6
✓ Branch 2 taken 1546 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1546 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1546 times.
✗ Branch 9 not taken.
7662 return file.template read_dataset_to<std::vector<std::size_t>>("/VTKHDF/Steps/NumberOfParts").at(step);
246
247 // all steps have the same number of parts
248 if (_total_number_of_pieces()%_num_steps.value() != 0)
249 throw IOError(
250 "Cannot deduce the number of pieces. "
251 "The dataset '/VTKHDF/Steps/NumberOfParts' is not available, "
252 "but the total number of pieces is not divisble by the number of steps"
253 );
254 return _total_number_of_pieces()/_num_steps.value();
255 }
256
257 302 void _check_communicator_size() const {
258 if constexpr (!std::is_same_v<Communicator, NullCommunicator>)
259
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 116 times.
232 if (_number_of_current_pieces_in_file() != static_cast<std::size_t>(Parallel::size(_comm)))
260 throw SizeError(
261 "Can only read the file in parallel if the size of the communicator matches the size "
262 "of that used when writing the file. Please read in the file sequentially on one process "
263 "and distribute the grid yourself, or restart the parallel run with "
264 + std::to_string(_number_of_current_pieces_in_file()) + " processes."
265 );
266 302 }
267
268 439 void _visit_cells(const typename GridReader::CellVisitor& visitor) const override {
269 if constexpr (read_rank_piece_only)
270 332 _visit_cells_for_rank(Parallel::rank(_comm), 0, visitor);
271 else
272
1/2
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
107 std::ranges::for_each(
273
2/4
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 95 times.
✗ Branch 5 not taken.
107 std::views::iota(std::size_t{0}, _number_of_current_pieces_in_file()),
274 107 [&] (int rank) mutable {
275
2/4
✓ Branch 1 taken 107 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 107 times.
✗ Branch 5 not taken.
321 const auto [_, base_offset] = _number_of_entities_and_offset_at_rank(rank, "Points");
276
1/2
✓ Branch 1 taken 107 times.
✗ Branch 2 not taken.
107 _visit_cells_for_rank(rank, base_offset, visitor);
277 }
278 );
279 439 }
280
281 463 void _visit_cells_for_rank(int piece_rank,
282 std::size_t point_base_offset,
283 const typename GridReader::CellVisitor& visitor) const {
284
1/2
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
463 const auto& file = _access_file();
285
2/4
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
926 const auto [my_num_cells, my_cell_offset] = _number_of_entities_and_offset_at_rank(piece_rank, "Cells");
286
2/4
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
926 const auto num_connectivity_ids = file.template read_dataset_to<std::vector<std::size_t>>(
287 "VTKHDF/NumberOfConnectivityIds",
288 HDF5::Slice{
289
1/2
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
463 .offset = {_get_part_offset()},
290 926 .count = {_number_of_current_pieces_in_file()}
291 }
292 );
293 926 const auto my_num_connectivity_ids = num_connectivity_ids.at(piece_rank);
294 463 const auto my_id_offset = std::accumulate(
295 num_connectivity_ids.begin(),
296 463 num_connectivity_ids.begin() + piece_rank,
297 std::size_t{0}
298 );
299
300
2/4
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
926 auto offsets = file.template read_dataset_to<std::vector<std::size_t>>("VTKHDF/Offsets", {{
301 // offsets have length num_cells+1, so we need to add +1 per rank to the cell offsets
302 .offset = {
303
2/4
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 273 times.
✗ Branch 6 not taken.
463 _get_step_cells_offset() + _accumulate_over_pieces_until_step(_step_index.value_or(0), 1) // offset from step
304 463 + my_cell_offset + piece_rank // offset from this piece in the pieces of the current step
305 },
306 463 .count = {my_num_cells + 1}
307 }});
308
2/4
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
926 auto types = file.template read_dataset_to<std::vector<std::uint_least8_t>>(
309 "VTKHDF/Types",
310 926 {{.offset = {_get_step_cells_offset() + my_cell_offset}, .count = {my_num_cells}}}
311 );
312
2/4
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
926 auto connectivity = file.template read_dataset_to<std::vector<std::size_t>>(
313 "VTKHDF/Connectivity",
314 926 {{.offset = {_get_connectivity_id_offset() + my_id_offset}, .count = {my_num_connectivity_ids}}}
315 );
316
317 463 std::vector<std::size_t> corners;
318
2/2
✓ Branch 1 taken 3524 times.
✓ Branch 2 taken 273 times.
6299 for (std::size_t i = 0; i < types.size(); ++i) {
319
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3524 times.
5836 assert(i < offsets.size() - 1);
320
3/6
✓ Branch 1 taken 3524 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3524 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3524 times.
5836 assert(offsets.at(i+1) > offsets.at(i));
321
1/2
✓ Branch 1 taken 3524 times.
✗ Branch 2 not taken.
5836 const auto p0_offset = offsets.at(i);
322
1/2
✓ Branch 1 taken 3524 times.
✗ Branch 2 not taken.
5836 const auto num_corners = offsets.at(i+1) - p0_offset;
323
324
1/2
✓ Branch 1 taken 3524 times.
✗ Branch 2 not taken.
5836 corners.resize(num_corners);
325
2/2
✓ Branch 0 taken 14096 times.
✓ Branch 1 taken 3524 times.
29180 for (std::size_t c = 0; c < num_corners; ++c)
326
1/2
✓ Branch 1 taken 14096 times.
✗ Branch 2 not taken.
23344 corners[c] = connectivity.at(p0_offset + c) + point_base_offset;
327
3/6
✓ Branch 1 taken 3524 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3524 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3524 times.
✗ Branch 8 not taken.
5836 visitor(VTK::cell_type(types.at(i)), corners);
328 }
329
12/40
✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 273 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 273 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 273 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 273 times.
✗ Branch 19 not taken.
✓ Branch 23 taken 273 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 273 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 273 times.
✗ Branch 30 not taken.
✓ Branch 34 taken 273 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 273 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 273 times.
✗ Branch 41 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
6945 }
330
331 227 FieldPtr _points() const override {
332
1/2
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
227 const std::string path = "VTKHDF/Points";
333
2/4
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
681 return make_field_ptr(VTKHDF::DataSetField{
334 _file.value(),
335
1/2
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
227 MDLayout{{_num_points, vtk_space_dim}},
336
3/6
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 135 times.
✗ Branch 8 not taken.
227 _file.value().get_precision(path).value(),
337
1/2
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
454 _serialization_callback(path, HDF5::Slice{
338
1/2
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
227 .offset = {_point_offset + _get_step_points_offset(), 0},
339 227 .count = {_num_points, vtk_space_dim}
340 })
341
1/2
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
454 });
342
2/8
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
908 }
343
344 1152 FieldPtr _cell_field(std::string_view name) const override {
345
2/4
✓ Branch 1 taken 684 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 684 times.
✗ Branch 5 not taken.
1152 const std::string path = "VTKHDF/CellData/" + std::string{name};
346
2/4
✓ Branch 1 taken 684 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 684 times.
✗ Branch 5 not taken.
1152 const auto slice = _get_slice(path, _num_cells, _cell_offset + _get_cell_data_offset(name));
347
3/6
✓ Branch 1 taken 684 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 684 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 684 times.
✗ Branch 8 not taken.
3456 return make_field_ptr(VTKHDF::DataSetField{
348 _file.value(),
349 MDLayout{slice.count},
350
3/6
✓ Branch 1 taken 684 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 684 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 684 times.
✗ Branch 8 not taken.
1152 _file.value().get_precision(path).value(),
351
2/4
✓ Branch 1 taken 684 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 684 times.
✗ Branch 5 not taken.
2304 _serialization_callback(path, slice)
352
1/2
✓ Branch 1 taken 684 times.
✗ Branch 2 not taken.
2304 });
353 1152 }
354
355 1162 FieldPtr _point_field(std::string_view name) const override {
356
2/4
✓ Branch 1 taken 690 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 690 times.
✗ Branch 5 not taken.
1162 const std::string path = "VTKHDF/PointData/" + std::string{name};
357
2/4
✓ Branch 1 taken 690 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 690 times.
✗ Branch 5 not taken.
1162 const auto slice = _get_slice(path, _num_points, _point_offset + _get_point_data_offset(name));
358
3/6
✓ Branch 1 taken 690 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 690 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 690 times.
✗ Branch 8 not taken.
3486 return make_field_ptr(VTKHDF::DataSetField{
359 _file.value(),
360 MDLayout{slice.count},
361
3/6
✓ Branch 1 taken 690 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 690 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 690 times.
✗ Branch 8 not taken.
1162 _file.value().get_precision(path).value(),
362
2/4
✓ Branch 1 taken 690 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 690 times.
✗ Branch 5 not taken.
2324 _serialization_callback(path, slice)
363
1/2
✓ Branch 1 taken 690 times.
✗ Branch 2 not taken.
2324 });
364 1162 }
365
366 180 FieldPtr _meta_data_field(std::string_view name) const override {
367
2/4
✓ Branch 1 taken 108 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
180 const auto path = "VTKHDF/FieldData/" + std::string{name};
368
3/6
✓ Branch 1 taken 108 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 108 times.
✗ Branch 8 not taken.
180 const auto dims = _file.value().get_dimensions(path).value();
369
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 90 times.
180 if (dims.size() == 1)
370
4/8
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 18 times.
✗ Branch 11 not taken.
30 return make_field_ptr(VTKHDF::DataSetField{_file.value(), path});
371
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
150 if (dims.size() != 2)
372 throw SizeError("Unexpected field data array size");
373
1/2
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
150 auto offset = dims;
374
1/2
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
150 auto count = offset;
375
1/2
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
150 count.at(0) = 1;
376
1/2
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
150 std::ranges::fill(offset, 0);
377
2/4
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
150 offset.at(0) = _get_field_data_offset(name);
378
2/4
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
450 return make_field_ptr(VTKHDF::DataSetField{
379 _file.value(),
380
2/4
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
150 MDLayout{count | std::views::drop(1)},
381
3/6
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 90 times.
✗ Branch 8 not taken.
150 _file.value().get_precision(path).value(),
382
4/16
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 90 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 90 times.
✗ Branch 11 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
318 [p=path, o=offset, c=count] (const HDF5File& f) {
383 60 return f.visit_dataset(p, [&] <typename F> (F&& field) {
384
8/88
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 74 taken 4 times.
✗ Branch 75 not taken.
✓ Branch 78 taken 4 times.
✗ Branch 79 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✓ Branch 122 taken 2 times.
✗ Branch 123 not taken.
✓ Branch 126 taken 2 times.
✗ Branch 127 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✓ Branch 206 taken 8 times.
✗ Branch 207 not taken.
✓ Branch 210 taken 8 times.
✗ Branch 211 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✓ Branch 254 taken 4 times.
✗ Branch 255 not taken.
✓ Branch 258 taken 4 times.
✗ Branch 259 not taken.
18 return FlattenedField{make_field_ptr(std::move(field))}.serialized();
385
6/12
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 12 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 12 times.
✗ Branch 17 not taken.
54 }, HDF5::Slice{.offset = o, .count = c});
386 }
387
1/2
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
150 });
388 180 }
389
390 template<Concepts::Scalar T>
391 T _read_rank_scalar(const std::string& path, const std::size_t base_offset = 0) const {
392 T result;
393 _file.value().visit_dataset(
394 path,
395 [&] (auto&& field) { field.export_to(result); },
396 HDF5::Slice{
397 .offset = {base_offset + static_cast<std::size_t>(Parallel::rank(_comm))},
398 .count = {1}
399 }
400 );
401 return result;
402 }
403
404 2314 HDF5::Slice _get_slice(const std::string& path,
405 std::size_t count,
406 std::size_t offset) const {
407
3/6
✓ Branch 1 taken 1374 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1374 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1374 times.
✗ Branch 8 not taken.
2314 auto ds_size = _file.value().get_dimensions(path).value();
408
1/2
✓ Branch 1 taken 1374 times.
✗ Branch 2 not taken.
2314 auto ds_offset = ds_size;
409
1/2
✓ Branch 1 taken 1374 times.
✗ Branch 2 not taken.
2314 std::ranges::fill(ds_offset, std::size_t{0});
410
1/2
✓ Branch 1 taken 1374 times.
✗ Branch 2 not taken.
2314 ds_size.at(0) = count;
411
1/2
✓ Branch 1 taken 1374 times.
✗ Branch 2 not taken.
2314 ds_offset.at(0) = offset;
412 2314 return {.offset = ds_offset, .count = ds_size};
413
2/6
✓ Branch 1 taken 1374 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1374 times.
✗ Branch 5 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
2314 }
414
415 2541 auto _serialization_callback(std::string path, std::optional<HDF5::Slice> slice = {}) const {
416 3477 return [_p=std::move(path), _s=std::move(slice)] (const HDF5File& file) {
417
2/4
✓ Branch 1 taken 507 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 858 times.
✗ Branch 5 not taken.
1365 if (_s)
418
6/12
✓ Branch 1 taken 507 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 507 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 507 times.
✗ Branch 8 not taken.
✓ Branch 13 taken 858 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 858 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 858 times.
✗ Branch 20 not taken.
3159 return file.visit_dataset(_p, [&] <typename F> (F&& f) { return f.serialized(); }, _s.value());
419 return file.visit_dataset(_p, [&] <typename F> (F&& f) { return f.serialized(); });
420 2541 };
421 }
422
423 10691 bool _is_transient() const {
424 10691 return static_cast<bool>(_num_steps);
425 }
426
427 9561 const HDF5File& _access_file() const {
428
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5757 times.
9561 if (!_file.has_value())
429 throw InvalidState("No file has been read");
430 9561 return _file.value();
431 }
432
433 1198 std::vector<std::size_t> _number_of_all_piece_entities(const std::string& entity_type) const {
434
1/2
✓ Branch 2 taken 740 times.
✗ Branch 3 not taken.
3594 return _access_file().template read_dataset_to<std::vector<std::size_t>>("/VTKHDF/NumberOf" + entity_type, {{
435
1/2
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
1198 .offset = {_get_part_offset()},
436 2396 .count = {_number_of_current_pieces_in_file()}
437
1/2
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
2396 }});
438
3/10
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 740 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 740 times.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
4792 }
439
440 template<std::integral T>
441 594 std::array<std::size_t, 2> _number_of_entities_and_offset_at_rank(T rank, const std::string& entity_type) const {
442
1/2
✓ Branch 1 taken 380 times.
✗ Branch 2 not taken.
594 const auto entities = _number_of_all_piece_entities(entity_type);
443
1/2
✓ Branch 1 taken 380 times.
✗ Branch 2 not taken.
1188 return std::array{entities.at(rank), _accumulate_until(rank, entities)};
444 594 }
445
446 template<typename T>
447 1480 T _accumulate_until(std::integral auto rank, const std::vector<T>& values) const {
448 1480 return std::accumulate(values.begin(), values.begin() + rank, T{0});
449 }
450
451 273 std::size_t _accumulate_over_pieces_until_step(std::size_t step, std::size_t count_per_piece) const {
452
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 58 times.
273 if (step == 0)
453 83 return 0;
454
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 58 times.
190 if (!_is_transient())
455 throw InvalidState("Step data only available in transient files");
456
457 190 std::size_t result = 0;
458
2/4
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 58 times.
✗ Branch 5 not taken.
862 std::ranges::for_each(std::views::iota(std::size_t{0}, step), [&] (std::size_t step_idx) {
459 484 const auto num_step_pieces = _number_of_pieces_in_file_at_step(step_idx);
460 484 result += count_per_piece*num_step_pieces;
461 });
462 190 return result;
463 }
464
465 Communicator _comm;
466 std::optional<HDF5File> _file;
467 std::size_t _num_cells = 0;
468 std::size_t _num_points = 0;
469 std::size_t _cell_offset = 0;
470 std::size_t _point_offset = 0;
471 std::optional<std::size_t> _num_steps;
472 std::optional<std::size_t> _step_index;
473 };
474
475 } // namespace GridFormat
476
477 #endif // GRIDFORMAT_HAVE_HIGH_FIVE
478 #endif // GRIDFORMAT_VTK_HDF_UNSTRUCTURED_GRID_READER_HPP_
479