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 Common functionality for VTK writers | ||
7 | */ | ||
8 | #ifndef GRIDFORMAT_VTK_COMMON_HPP_ | ||
9 | #define GRIDFORMAT_VTK_COMMON_HPP_ | ||
10 | |||
11 | #include <ranges> | ||
12 | #include <cassert> | ||
13 | #include <utility> | ||
14 | #include <type_traits> | ||
15 | #include <algorithm> | ||
16 | #include <array> | ||
17 | #include <cmath> | ||
18 | |||
19 | #include <gridformat/common/field.hpp> | ||
20 | #include <gridformat/common/concepts.hpp> | ||
21 | #include <gridformat/common/exceptions.hpp> | ||
22 | #include <gridformat/common/precision.hpp> | ||
23 | #include <gridformat/common/serialization.hpp> | ||
24 | #include <gridformat/common/md_layout.hpp> | ||
25 | #include <gridformat/common/ranges.hpp> | ||
26 | #include <gridformat/common/matrix.hpp> | ||
27 | #include <gridformat/common/type_traits.hpp> | ||
28 | #include <gridformat/common/string_conversion.hpp> | ||
29 | #include <gridformat/common/flat_index_mapper.hpp> | ||
30 | #include <gridformat/common/field_transformations.hpp> | ||
31 | #include <gridformat/common/field.hpp> | ||
32 | |||
33 | #include <gridformat/grid/entity_fields.hpp> | ||
34 | #include <gridformat/grid/cell_type.hpp> | ||
35 | #include <gridformat/grid/concepts.hpp> | ||
36 | #include <gridformat/grid/_detail.hpp> | ||
37 | #include <gridformat/grid/grid.hpp> | ||
38 | |||
39 | #ifndef DOXYGEN | ||
40 | namespace GridFormat::Encoding { struct Ascii; struct Base64; struct RawBinary; } | ||
41 | #endif // DOXYGEN | ||
42 | |||
43 | namespace GridFormat::VTK { | ||
44 | |||
45 | //! \addtogroup VTK | ||
46 | //! \{ | ||
47 | |||
48 | namespace DataFormat { | ||
49 | |||
50 | struct Inlined {}; //!< Inline data format (inside xml elements) | ||
51 | struct Appended {}; //!< Appended data format (all data is appended at the end of the xml file) | ||
52 | |||
53 | inline constexpr Inlined inlined; //!< Instance of the inline data format | ||
54 | inline constexpr Appended appended; //!< Instance of the appended data format | ||
55 | |||
56 | } // namespace DataFormat | ||
57 | |||
58 | #ifndef DOXYGEN | ||
59 | namespace Traits { | ||
60 | |||
61 | template<typename T> struct ProducesValidXML; | ||
62 | template<> struct ProducesValidXML<Encoding::Ascii> : public std::true_type {}; | ||
63 | template<> struct ProducesValidXML<Encoding::Base64> : public std::true_type {}; | ||
64 | template<> struct ProducesValidXML<Encoding::RawBinary> : public std::false_type {}; | ||
65 | |||
66 | } // namespace Traits | ||
67 | |||
68 | template<typename Encoder> | ||
69 | 12146 | inline constexpr bool produces_valid_xml(const Encoder&) { | |
70 | static_assert( | ||
71 | is_complete<Traits::ProducesValidXML<Encoder>>, | ||
72 | "Traits::ProducesValidXML was not specialized for the given encoder" | ||
73 | ); | ||
74 | 12146 | return Traits::ProducesValidXML<Encoder>::value; | |
75 | } | ||
76 | |||
77 | 34596 | inline constexpr std::uint8_t cell_type_number(CellType t) { | |
78 |
14/15✓ Branch 0 taken 135 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 653 times.
✓ Branch 3 taken 18050 times.
✓ Branch 4 taken 3037 times.
✓ Branch 5 taken 141 times.
✓ Branch 6 taken 1732 times.
✓ Branch 7 taken 923 times.
✓ Branch 8 taken 3000 times.
✓ Branch 9 taken 46 times.
✓ Branch 10 taken 727 times.
✓ Branch 11 taken 463 times.
✓ Branch 12 taken 4483 times.
✓ Branch 13 taken 741 times.
✗ Branch 14 not taken.
|
34596 | switch (t) { |
79 | 135 | case (CellType::vertex): return 1; | |
80 | 465 | case (CellType::segment): return 3; | |
81 | 653 | case (CellType::triangle): return 5; | |
82 | 18050 | case (CellType::pixel): return 8; | |
83 | 3037 | case (CellType::quadrilateral): return 9; | |
84 | 141 | case (CellType::polygon): return 7; | |
85 | 1732 | case (CellType::tetrahedron): return 10; | |
86 | 923 | case (CellType::hexahedron): return 12; | |
87 | 3000 | case (CellType::voxel): return 11; | |
88 | 46 | case (CellType::lagrange_segment): return 68; | |
89 | 727 | case (CellType::lagrange_triangle): return 69; | |
90 | 463 | case (CellType::lagrange_quadrilateral): return 70; | |
91 | 4483 | case (CellType::lagrange_tetrahedron): return 71; | |
92 | 741 | case (CellType::lagrange_hexahedron): return 72; | |
93 | } | ||
94 | |||
95 | ✗ | throw NotImplemented("VTK cell type number for the given cell type"); | |
96 | } | ||
97 | |||
98 | 10004 | inline constexpr CellType cell_type(std::uint8_t vtk_id) { | |
99 |
4/15✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 1200 times.
✓ Branch 4 taken 8734 times.
✓ Branch 5 taken 35 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
10004 | switch (vtk_id) { |
100 | ✗ | case 1: return CellType::vertex; | |
101 | ✗ | case 3: return CellType::segment; | |
102 | 35 | case 5: return CellType::triangle; | |
103 | 1200 | case 8: return CellType::pixel; | |
104 | 8734 | case 9: return CellType::quadrilateral; | |
105 | 35 | case 7: return CellType::polygon; | |
106 | ✗ | case 10: return CellType::tetrahedron; | |
107 | ✗ | case 12: return CellType::hexahedron; | |
108 | ✗ | case 11: return CellType::voxel; | |
109 | ✗ | case 68: return CellType::lagrange_segment; | |
110 | ✗ | case 69: return CellType::lagrange_triangle; | |
111 | ✗ | case 70: return CellType::lagrange_quadrilateral; | |
112 | ✗ | case 71: return CellType::lagrange_tetrahedron; | |
113 | ✗ | case 72: return CellType::lagrange_hexahedron; | |
114 | } | ||
115 | |||
116 | ✗ | throw NotImplemented("Cell type for the given VTK cell type number: " + std::to_string(vtk_id)); | |
117 | } | ||
118 | |||
119 | 93286 | FieldPtr make_vtk_field(FieldPtr field) { | |
120 |
1/2✓ Branch 2 taken 93286 times.
✗ Branch 3 not taken.
|
93286 | const auto layout = field->layout(); |
121 |
3/4✓ Branch 1 taken 93286 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32960 times.
✓ Branch 4 taken 60326 times.
|
93286 | if (layout.dimension() < 2) |
122 | 32960 | return field; | |
123 | // (maybe) make vector/tensor fields 3d | ||
124 |
1/2✓ Branch 1 taken 60326 times.
✗ Branch 2 not taken.
|
60326 | if (std::ranges::all_of( |
125 |
4/6✓ Branch 1 taken 60326 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60326 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16601 times.
✓ Branch 7 taken 43725 times.
|
120652 | std::views::iota(std::size_t{1}, layout.dimension()), |
126 | 68005 | [&] (const std::size_t codim) { return layout.extent(codim) < 3; } | |
127 | )) | ||
128 |
1/2✓ Branch 3 taken 16601 times.
✗ Branch 4 not taken.
|
16601 | return transform(field, FieldTransformation::extend_all_to(3)); |
129 | 43725 | return field; | |
130 | 93286 | } | |
131 | |||
132 | template<std::derived_from<Field> F> | ||
133 | requires(!std::is_lvalue_reference_v<F>) | ||
134 | 14078 | FieldPtr make_vtk_field(F&& field) { | |
135 |
2/4✓ Branch 2 taken 7039 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7039 times.
✗ Branch 6 not taken.
|
14078 | return make_vtk_field(make_field_ptr(std::forward<F>(field))); |
136 | } | ||
137 | |||
138 | template<typename ctype, GridDetail::ExposesPointRange Grid> | ||
139 | 6732 | auto make_coordinates_field(const Grid& grid, bool structured_grid_ordering) { | |
140 | 6732 | return make_vtk_field(PointField{ | |
141 | grid, | ||
142 | 145857 | [&] (const auto& point) { return coordinates(grid, point); }, | |
143 | structured_grid_ordering, | ||
144 | Precision<ctype>{} | ||
145 |
1/2✓ Branch 1 taken 3415 times.
✗ Branch 2 not taken.
|
13464 | }); |
146 | } | ||
147 | |||
148 | template<typename HeaderType = std::size_t, | ||
149 | Concepts::UnstructuredGrid Grid, | ||
150 | std::ranges::forward_range Cells, | ||
151 | typename PointMap> | ||
152 | requires(std::is_lvalue_reference_v<PointMap>) | ||
153 | 2736 | auto make_connectivity_field(const Grid& grid, | |
154 | Cells&& cells, | ||
155 | PointMap&& map) { | ||
156 | class ConnectivityField : public Field { | ||
157 | public: | ||
158 | 1417 | explicit ConnectivityField(const Grid& g, | |
159 | Cells&& cells, | ||
160 | PointMap&& map) | ||
161 | 1417 | : _grid(g) | |
162 | 2788 | , _cells{std::forward<Cells>(cells)} | |
163 | 1463 | , _point_map{std::forward<PointMap>(map)} { | |
164 | 1417 | _num_values = 0; | |
165 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
75209 | std::ranges::for_each(_cells, [&] (const auto& cell) { |
166 | 38264 | _num_values += number_of_points(_grid, cell); | |
167 | }); | ||
168 | 1417 | } | |
169 | |||
170 | private: | ||
171 |
1/2✓ Branch 1 taken 392 times.
✗ Branch 2 not taken.
|
4508 | MDLayout _layout() const override { return MDLayout{{_num_values}}; } |
172 | 4130 | DynamicPrecision _precision() const override { return Precision<HeaderType>{}; } | |
173 | 1395 | Serialization _serialized() const override { | |
174 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
1395 | Serialization serialization(sizeof(HeaderType)*_num_values); |
175 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
1395 | HeaderType* data = serialization.as_span_of<HeaderType>().data(); |
176 | |||
177 | 1395 | std::size_t i = 0; | |
178 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
74975 | std::ranges::for_each(_cells, [&] (const auto& cell) { |
179 |
72/242✓ Branch 1 taken 6741 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6741 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 414 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 414 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 9173 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 9173 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3084 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 3084 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 944 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 944 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 13992 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 13992 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 292 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 292 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 312 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 312 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 64 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 64 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 702 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 702 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 950 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 950 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1170 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1170 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 42 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 42 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 3 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 3 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 45 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 45 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 3 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 3 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 10 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 10 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 13 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 13 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 14 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 14 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 10 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 10 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 7 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 7 times.
✗ Branch 125 not taken.
✓ Branch 127 taken 9 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 9 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 4 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 4 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 14 times.
✗ Branch 140 not taken.
✓ Branch 142 taken 14 times.
✗ Branch 143 not taken.
✓ Branch 145 taken 4 times.
✗ Branch 146 not taken.
✓ Branch 148 taken 4 times.
✗ Branch 149 not taken.
✓ Branch 151 taken 14 times.
✗ Branch 152 not taken.
✓ Branch 154 taken 14 times.
✗ Branch 155 not taken.
✓ Branch 157 taken 4 times.
✗ Branch 158 not taken.
✓ Branch 160 taken 4 times.
✗ Branch 161 not taken.
✓ Branch 163 taken 22 times.
✗ Branch 164 not taken.
✓ Branch 166 taken 22 times.
✗ Branch 167 not taken.
✓ Branch 169 taken 15 times.
✗ Branch 170 not taken.
✓ Branch 172 taken 15 times.
✗ Branch 173 not taken.
✓ Branch 175 taken 12 times.
✗ Branch 176 not taken.
✓ Branch 178 taken 12 times.
✗ Branch 179 not taken.
✓ Branch 181 taken 15 times.
✗ Branch 182 not taken.
✓ Branch 184 taken 15 times.
✗ Branch 185 not taken.
✓ Branch 187 taken 12 times.
✗ Branch 188 not taken.
✓ Branch 190 taken 12 times.
✗ Branch 191 not taken.
✓ Branch 193 taken 12 times.
✗ Branch 194 not taken.
✓ Branch 196 taken 12 times.
✗ Branch 197 not taken.
✓ Branch 199 taken 12 times.
✗ Branch 200 not taken.
✓ Branch 202 taken 12 times.
✗ Branch 203 not taken.
✓ Branch 205 taken 12 times.
✗ Branch 206 not taken.
✓ Branch 208 taken 12 times.
✗ Branch 209 not taken.
✓ Branch 211 taken 12 times.
✗ Branch 212 not taken.
✓ Branch 214 taken 12 times.
✗ Branch 215 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 256 not taken.
✗ Branch 257 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 271 not taken.
✗ Branch 272 not taken.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 358 not taken.
✗ Branch 359 not taken.
|
380160 | std::ranges::for_each(points(_grid, cell), [&] (const auto& point) { |
180 |
84/272✓ Branch 1 taken 9844 times.
✓ Branch 2 taken 29616 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9844 times.
✓ Branch 5 taken 400 times.
✓ Branch 6 taken 396 times.
✓ Branch 7 taken 694 times.
✓ Branch 8 taken 400 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 33767 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 8406 times.
✓ Branch 14 taken 84 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 8406 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 42 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 12000 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 4882 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 3606 times.
✓ Branch 26 taken 280 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 3606 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 560 times.
✓ Branch 31 taken 25736 times.
✓ Branch 32 taken 25200 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 25904 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 652 times.
✓ Branch 38 taken 448 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 652 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 168 times.
✓ Branch 43 taken 172 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 452 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 12 times.
✓ Branch 50 taken 342 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 12 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 1191 times.
✓ Branch 55 taken 3852 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 6797 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 3852 times.
✓ Branch 62 taken 11631 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 3852 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 20 times.
✓ Branch 67 taken 12 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 35 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 20 times.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 78 taken 15 times.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✓ Branch 82 taken 12 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✓ Branch 86 taken 15 times.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✓ Branch 94 taken 20 times.
✗ Branch 95 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✓ Branch 102 taken 20 times.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✓ Branch 109 taken 12 times.
✓ Branch 110 taken 20 times.
✗ Branch 111 not taken.
✓ Branch 112 taken 12 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 12 times.
✓ Branch 115 taken 12 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 12 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 12 times.
✓ Branch 122 taken 12 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 12 times.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✓ Branch 127 taken 12 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 12 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 12 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 12 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 12 times.
✗ Branch 140 not taken.
✓ Branch 142 taken 12 times.
✗ Branch 143 not taken.
✓ Branch 145 taken 12 times.
✗ Branch 146 not taken.
✓ Branch 148 taken 12 times.
✗ Branch 149 not taken.
✓ Branch 151 taken 12 times.
✗ Branch 152 not taken.
✓ Branch 154 taken 12 times.
✗ Branch 155 not taken.
✓ Branch 157 taken 12 times.
✗ Branch 158 not taken.
✓ Branch 160 taken 12 times.
✗ Branch 161 not taken.
✓ Branch 163 taken 48 times.
✗ Branch 164 not taken.
✓ Branch 166 taken 48 times.
✗ Branch 167 not taken.
✓ Branch 169 taken 48 times.
✗ Branch 170 not taken.
✓ Branch 172 taken 48 times.
✗ Branch 173 not taken.
✓ Branch 175 taken 48 times.
✗ Branch 176 not taken.
✓ Branch 178 taken 48 times.
✗ Branch 179 not taken.
✓ Branch 181 taken 48 times.
✗ Branch 182 not taken.
✓ Branch 184 taken 48 times.
✗ Branch 185 not taken.
✓ Branch 187 taken 48 times.
✗ Branch 188 not taken.
✓ Branch 190 taken 48 times.
✗ Branch 191 not taken.
✓ Branch 193 taken 48 times.
✗ Branch 194 not taken.
✓ Branch 196 taken 48 times.
✗ Branch 197 not taken.
✓ Branch 199 taken 48 times.
✗ Branch 200 not taken.
✓ Branch 202 taken 48 times.
✗ Branch 203 not taken.
✓ Branch 205 taken 48 times.
✗ Branch 206 not taken.
✓ Branch 208 taken 48 times.
✗ Branch 209 not taken.
✓ Branch 211 taken 48 times.
✗ Branch 212 not taken.
✓ Branch 214 taken 48 times.
✗ Branch 215 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 256 not taken.
✗ Branch 257 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 271 not taken.
✗ Branch 272 not taken.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 358 not taken.
✗ Branch 359 not taken.
|
181273 | data[i] = _point_map.at(id(_grid, point)); |
181 | 181273 | i++; | |
182 | }); | ||
183 | }); | ||
184 | 1395 | return serialization; | |
185 | ✗ | } | |
186 | |||
187 | const Grid& _grid; | ||
188 | LVReferenceOrValue<Cells> _cells; | ||
189 | LVReferenceOrValue<PointMap> _point_map; | ||
190 | HeaderType _num_values; | ||
191 |
1/2✓ Branch 3 taken 1417 times.
✗ Branch 4 not taken.
|
2736 | } _field{grid, std::forward<Cells>(cells), std::forward<PointMap>(map)}; |
192 | |||
193 |
1/2✓ Branch 2 taken 1417 times.
✗ Branch 3 not taken.
|
5472 | return make_vtk_field(std::move(_field)); |
194 | 2736 | } | |
195 | |||
196 | template<typename HeaderType = std::size_t, | ||
197 | Concepts::UnstructuredGrid Grid, | ||
198 | typename PointMap> | ||
199 | 1482 | auto make_connectivity_field(const Grid& grid, PointMap&& map) { | |
200 |
3/5✓ Branch 2 taken 321 times.
✓ Branch 3 taken 469 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 321 times.
✗ Branch 6 not taken.
|
2964 | return make_connectivity_field<HeaderType>(grid, cells(grid), std::forward<PointMap>(map)); |
201 | } | ||
202 | |||
203 | template<typename HeaderType = std::size_t, | ||
204 | Concepts::UnstructuredGrid Grid, | ||
205 | std::ranges::range Cells> | ||
206 | 2736 | auto make_offsets_field(const Grid& grid, Cells&& cells) { | |
207 | class OffsetField : public Field { | ||
208 | public: | ||
209 | 1417 | explicit OffsetField(const Grid& g, Cells&& cells) | |
210 | 1417 | : _grid(g) | |
211 | 2788 | , _cells{std::forward<Cells>(cells)} | |
212 | 1463 | , _num_cells{static_cast<HeaderType>(Ranges::size(_cells))} | |
213 | 1417 | {} | |
214 | |||
215 | private: | ||
216 |
1/2✓ Branch 1 taken 392 times.
✗ Branch 2 not taken.
|
4508 | MDLayout _layout() const override { return MDLayout{{_num_cells}}; } |
217 | 4130 | DynamicPrecision _precision() const override { return Precision<HeaderType>{}; } | |
218 | 1395 | Serialization _serialized() const override { | |
219 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
1395 | Serialization serialization(sizeof(HeaderType)*_num_cells); |
220 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
1395 | HeaderType* data = serialization.as_span_of<HeaderType>().data(); |
221 | |||
222 | 1395 | std::size_t i = 0; | |
223 | 1395 | HeaderType offset = 0; | |
224 |
1/2✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
|
74975 | std::ranges::for_each(_cells, [&] (const auto& cell) { |
225 | 38158 | offset += number_of_points(_grid, cell); | |
226 | 38158 | data[i] = offset; | |
227 | 38158 | i++; | |
228 | }); | ||
229 | 1395 | return serialization; | |
230 | ✗ | } | |
231 | |||
232 | const Grid& _grid; | ||
233 | LVReferenceOrValue<Cells> _cells; | ||
234 | HeaderType _num_cells; | ||
235 |
1/2✓ Branch 2 taken 794 times.
✗ Branch 3 not taken.
|
2736 | } _field{grid, std::forward<Cells>(cells)}; |
236 | |||
237 |
1/2✓ Branch 2 taken 1417 times.
✗ Branch 3 not taken.
|
5472 | return make_vtk_field(std::move(_field)); |
238 | 2736 | } | |
239 | |||
240 | template<typename HeaderType = std::size_t, Concepts::UnstructuredGrid Grid> | ||
241 | 1482 | auto make_offsets_field(const Grid& grid) { | |
242 |
3/5✓ Branch 1 taken 321 times.
✓ Branch 2 taken 469 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 321 times.
✗ Branch 5 not taken.
|
1482 | return make_offsets_field<HeaderType>(grid, cells(grid)); |
243 | } | ||
244 | |||
245 | template<Concepts::UnstructuredGrid Grid> | ||
246 | 1298 | auto make_cell_types_field(const Grid& grid) { | |
247 | 1298 | return make_vtk_field(CellField{ | |
248 | grid, | ||
249 | 25321 | [&] (const auto& cell) { | |
250 | 34596 | return VTK::cell_type_number(type(grid, cell)); | |
251 | }, | ||
252 | false | ||
253 |
1/2✓ Branch 1 taken 790 times.
✗ Branch 2 not taken.
|
2596 | }); |
254 | } | ||
255 | |||
256 | 107212 | inline auto active_array_attribute_for_rank(unsigned int rank) { | |
257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 107212 times.
|
107212 | if (rank > 2) |
258 | ✗ | throw ValueError("Rank must be <= 2"); | |
259 | static constexpr std::array attributes{"Scalars", "Vectors", "Tensors"}; | ||
260 | 107212 | return attributes[rank]; | |
261 | } | ||
262 | |||
263 | namespace CommonDetail { | ||
264 | |||
265 | template<Concepts::StaticallySizedRange R> | ||
266 | 30486 | std::string number_string_3d(const R& r) { | |
267 | static_assert(static_size<R> >= 1 || static_size<R> <= 3); | ||
268 | if constexpr (static_size<R> == 3) | ||
269 |
1/2✓ Branch 2 taken 12055 times.
✗ Branch 3 not taken.
|
24110 | return as_string(r); |
270 | if constexpr (static_size<R> == 2) | ||
271 |
2/4✓ Branch 2 taken 3188 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3188 times.
✗ Branch 6 not taken.
|
6376 | return as_string(r) + " 0"; |
272 | if constexpr (static_size<R> == 1) | ||
273 | return as_string(r) + " 0 0"; | ||
274 | } | ||
275 | |||
276 | template<Concepts::StaticallySizedMDRange<2> R> | ||
277 | 6294 | std::string direction_string(const R& basis) { | |
278 |
1/2✓ Branch 1 taken 3208 times.
✗ Branch 2 not taken.
|
6294 | Matrix m{basis}; |
279 | 6294 | m.transpose(); | |
280 | |||
281 |
1/2✓ Branch 1 taken 3208 times.
✗ Branch 2 not taken.
|
6294 | std::string result = ""; |
282 |
1/2✓ Branch 1 taken 3208 times.
✗ Branch 2 not taken.
|
23458 | std::ranges::for_each(m, [&] (const auto& row) { |
283 |
4/4✓ Branch 1 taken 799 times.
✓ Branch 2 taken 798 times.
✓ Branch 4 taken 4820 times.
✓ Branch 5 taken 2410 times.
|
8827 | if (result != "") |
284 | 5619 | result += " "; | |
285 |
4/8✓ Branch 1 taken 1597 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1597 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 7230 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 7230 times.
✗ Branch 13 not taken.
|
8827 | result += number_string_3d(row); |
286 | }); | ||
287 |
2/2✓ Branch 0 taken 797 times.
✓ Branch 1 taken 3208 times.
|
7767 | for (int i = static_size<R>; i < 3; ++i) |
288 |
1/2✓ Branch 1 taken 797 times.
✗ Branch 2 not taken.
|
1473 | result += " 0 0 0"; |
289 | 6294 | return result; | |
290 | ✗ | } | |
291 | |||
292 | template<Concepts::StaticallySizedRange R1, | ||
293 | Concepts::StaticallySizedRange R2> | ||
294 | requires(std::integral<std::ranges::range_value_t<R1>> and | ||
295 | std::integral<std::ranges::range_value_t<R2>>) | ||
296 | 44313 | std::array<std::size_t, 6> get_extents(const R1& from, const R2& to) { | |
297 | static_assert(static_size<R1> == static_size<R2>); | ||
298 | static_assert(static_size<R1> <= 3); | ||
299 | |||
300 | 44313 | int i = 0; | |
301 | 44313 | auto result = Ranges::filled_array<6>(std::size_t{0}); | |
302 | 44313 | auto it1 = std::ranges::begin(from); | |
303 | 44313 | auto it2 = std::ranges::begin(to); | |
304 |
2/2✓ Branch 1 taken 62172 times.
✓ Branch 2 taken 22493 times.
|
167288 | for (; it1 != std::ranges::end(from); ++it1, ++it2, ++i) { |
305 | 122975 | result[i*2 + 0] = *it1; | |
306 | 122975 | result[i*2 + 1] = *it2; | |
307 | } | ||
308 | 44313 | return result; | |
309 | } | ||
310 | |||
311 | template<Concepts::StaticallySizedRange R> | ||
312 | 235 | std::array<std::size_t, 6> get_extents(const R& to) { | |
313 | using T = std::ranges::range_value_t<R>; | ||
314 |
2/4✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 155 times.
✗ Branch 5 not taken.
|
235 | return get_extents(Ranges::filled_array<static_size<R>>(T{0}), to); |
315 | } | ||
316 | |||
317 | template<Concepts::StaticallySizedRange R1, | ||
318 | Concepts::StaticallySizedRange R2> | ||
319 | 44078 | std::string extents_string(const R1& from, const R2& to) { | |
320 |
2/4✓ Branch 2 taken 22338 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 22338 times.
✗ Branch 6 not taken.
|
44078 | return as_string(get_extents(from, to)); |
321 | } | ||
322 | |||
323 | template<Concepts::StaticallySizedRange R> | ||
324 | 20222 | std::string extents_string(const R& r) { | |
325 | using T = std::ranges::range_value_t<R>; | ||
326 |
2/4✓ Branch 1 taken 10274 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10274 times.
✗ Branch 5 not taken.
|
20222 | return extents_string(Ranges::filled_array<static_size<R>>(T{0}), r); |
327 | } | ||
328 | |||
329 | template<Concepts::StructuredEntitySet Grid> | ||
330 | requires(!Concepts::StaticallySizedRange<Grid>) | ||
331 | 3980 | std::string extents_string(const Grid& grid) { | |
332 |
2/4✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
|
3980 | return extents_string(extents(grid)); |
333 | } | ||
334 | |||
335 | template<Concepts::StaticallySizedRange Spacing> | ||
336 | 4354 | auto structured_grid_axis_orientation(const Spacing& spacing) { | |
337 | std::array<bool, static_size<Spacing>> result; | ||
338 |
1/2✓ Branch 1 taken 2226 times.
✗ Branch 2 not taken.
|
4354 | std::ranges::copy( |
339 |
2/4✓ Branch 1 taken 2226 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2226 times.
✗ Branch 5 not taken.
|
10500 | spacing | std::views::transform([&] <typename CT> (const CT dx) { return dx <= CT{0}; }), |
340 | result.begin() | ||
341 | ); | ||
342 | 4354 | return result; | |
343 | } | ||
344 | |||
345 | 7634 | std::size_t number_of_entities(const std::array<std::size_t, 6>& extents) { | |
346 | 7634 | return std::max(extents[1] - extents[0], std::size_t{1}) | |
347 | 7634 | *std::max(extents[3] - extents[2], std::size_t{1}) | |
348 | 7634 | *std::max(extents[5] - extents[4], std::size_t{1}); | |
349 | } | ||
350 | |||
351 | 3123 | unsigned int structured_grid_dimension(const std::array<std::size_t, 3>& cells_per_direction) { | |
352 | 12492 | return std::ranges::count_if(cells_per_direction, [] (const std::size_t e) { return e > 0; }); | |
353 | } | ||
354 | |||
355 | template<typename T> | ||
356 | 24050 | std::array<T, 3> compute_location(const std::array<T, 3>& origin, | |
357 | const std::array<T, 3>& coordinate, | ||
358 | const std::array<T, 9>& direction) { | ||
359 | 24050 | const auto& [x, y, z] = coordinate; | |
360 | return { | ||
361 | 24050 | origin[0] + x*direction[0] + y*direction[1] + z*direction[2], | |
362 | 24050 | origin[1] + x*direction[3] + y*direction[4] + z*direction[5], | |
363 | 24050 | origin[2] + x*direction[6] + y*direction[7] + z*direction[8] | |
364 | 72150 | }; | |
365 | } | ||
366 | |||
367 | template<typename T> | ||
368 | 282 | std::array<T, 3> compute_piece_origin(const std::array<T, 3>& global_origin, | |
369 | const std::array<T, 3>& spacing, | ||
370 | const std::array<std::size_t, 3>& extents_begin, | ||
371 | const std::array<T, 9>& direction) { | ||
372 | 282 | return compute_location( | |
373 | global_origin, | ||
374 | { | ||
375 | 282 | spacing[0]*static_cast<T>(extents_begin[0]), | |
376 | 282 | spacing[1]*static_cast<T>(extents_begin[1]), | |
377 | 282 | spacing[2]*static_cast<T>(extents_begin[2]) | |
378 | }, | ||
379 | direction | ||
380 | 282 | ); | |
381 | } | ||
382 | |||
383 | template<typename T> | ||
384 | 282 | Serialization serialize_structured_points(const std::array<std::size_t, 6>& extents, | |
385 | const std::array<T, 3>& origin, | ||
386 | const std::array<T, 3>& spacing, | ||
387 | const std::array<T, 9>& direction) { | ||
388 | ✗ | const MDLayout layout{{ | |
389 | 282 | extents[1] - extents[0], | |
390 | 282 | extents[3] - extents[2], | |
391 |
1/2✓ Branch 3 taken 282 times.
✗ Branch 4 not taken.
|
282 | extents[5] - extents[4] |
392 | }}; | ||
393 |
1/2✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
|
282 | const FlatIndexMapper mapper{layout}; |
394 |
1/2✓ Branch 4 taken 282 times.
✗ Branch 5 not taken.
|
282 | const auto piece_origin = compute_piece_origin( |
395 | origin, spacing, {extents[0], extents[2], extents[4]}, direction | ||
396 | ); | ||
397 | |||
398 | static constexpr unsigned int vtk_space_dim = 3; | ||
399 |
2/4✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 282 times.
✗ Branch 5 not taken.
|
282 | Serialization result(layout.number_of_entries()*sizeof(T)*vtk_space_dim); |
400 |
1/2✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
|
282 | auto span_out = result.as_span_of(Precision<T>{}); |
401 |
8/14✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 282 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 282 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 282 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 23768 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 24050 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 23768 times.
✓ Branch 20 taken 282 times.
|
24050 | for (const auto& md_index : MDIndexRange{layout}) { |
402 |
1/2✓ Branch 1 taken 23768 times.
✗ Branch 2 not taken.
|
23768 | const auto offset = mapper.map(md_index)*vtk_space_dim; |
403 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23768 times.
|
23768 | assert(offset + 2 < span_out.size()); |
404 |
1/2✓ Branch 1 taken 23768 times.
✗ Branch 2 not taken.
|
23768 | std::ranges::copy( |
405 |
1/2✓ Branch 1 taken 23768 times.
✗ Branch 2 not taken.
|
23768 | compute_location(piece_origin, { |
406 | 23768 | static_cast<T>(md_index.get(0))*spacing[0], | |
407 | 23768 | static_cast<T>(md_index.get(1))*spacing[1], | |
408 | 23768 | static_cast<T>(md_index.get(2))*spacing[2] | |
409 | }, direction), | ||
410 | 23768 | span_out.data() + offset | |
411 | ); | ||
412 | } | ||
413 | 282 | return result; | |
414 | 282 | } | |
415 | |||
416 | template<typename Visitor> | ||
417 | 1039 | void visit_structured_cells(const Visitor& visitor, | |
418 | const std::array<std::size_t, 6>& extents, | ||
419 | const bool is_axis_aligned = true) { | ||
420 | 3117 | std::array<CellType, 4> grid_dim_to_cell_type{ | |
421 | CellType::vertex, | ||
422 | CellType::segment, | ||
423 |
2/2✓ Branch 0 taken 777 times.
✓ Branch 1 taken 262 times.
|
1039 | (is_axis_aligned ? CellType::pixel : CellType::quadrilateral), |
424 |
2/2✓ Branch 0 taken 777 times.
✓ Branch 1 taken 262 times.
|
1039 | (is_axis_aligned ? CellType::voxel : CellType::hexahedron) |
425 | }; | ||
426 | |||
427 | 3117 | std::array<std::size_t, 3> counts{ | |
428 | 1039 | extents[1] - extents[0], | |
429 | 1039 | extents[3] - extents[2], | |
430 | 1039 | extents[5] - extents[4] | |
431 | }; | ||
432 | |||
433 |
1/2✓ Branch 1 taken 1039 times.
✗ Branch 2 not taken.
|
1039 | const std::size_t grid_dim = structured_grid_dimension(counts); |
434 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1039 times.
|
1039 | if (grid_dim == 0) |
435 | ✗ | throw ValueError("Grid must be at least 1d"); | |
436 | |||
437 |
2/4✓ Branch 1 taken 1039 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1039 times.
✗ Branch 5 not taken.
|
1039 | const MDLayout point_layout{Ranges::incremented(counts, 1)}; |
438 |
1/2✓ Branch 1 taken 1039 times.
✗ Branch 2 not taken.
|
1039 | const FlatIndexMapper point_mapper{point_layout}; |
439 |
2/4✓ Branch 0 taken 1039 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1039 times.
✗ Branch 4 not taken.
|
1039 | const auto x_offset = grid_dim > 1 ? point_layout.extent(0) : std::size_t{0}; |
440 |
4/6✓ Branch 0 taken 41 times.
✓ Branch 1 taken 998 times.
✓ Branch 3 taken 41 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 41 times.
✗ Branch 7 not taken.
|
1039 | const auto y_offset = grid_dim > 2 ? point_layout.extent(0)*point_layout.extent(1) : std::size_t{0}; |
441 | |||
442 | // avoid zero counts s.t. the index range does not degenerate | ||
443 |
1/2✓ Branch 1 taken 1039 times.
✗ Branch 2 not taken.
|
4156 | std::ranges::for_each(counts, [] (std::size_t& count) { count = std::max(count, std::size_t{1}); }); |
444 |
1/2✓ Branch 2 taken 1039 times.
✗ Branch 3 not taken.
|
1039 | std::vector<std::size_t> corners(std::pow(2, grid_dim), 0); |
445 | |||
446 |
2/4✓ Branch 1 taken 1039 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1039 times.
✗ Branch 5 not taken.
|
1039 | const MDIndexRange index_range{MDLayout{counts}}; |
447 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1039 times.
|
1039 | if (grid_dim == 1) { |
448 | ✗ | std::ranges::for_each(index_range, [&] (const auto& md_index) { | |
449 | ✗ | const auto p0 = point_mapper.map(md_index); | |
450 | ✗ | corners = {p0, p0 + 1}; | |
451 | ✗ | visitor(grid_dim_to_cell_type[grid_dim], corners); | |
452 | }); | ||
453 |
2/2✓ Branch 0 taken 998 times.
✓ Branch 1 taken 41 times.
|
1039 | } else if (grid_dim == 2) { |
454 |
1/2✓ Branch 1 taken 998 times.
✗ Branch 2 not taken.
|
30985 | std::ranges::for_each(index_range, [&] (const auto& md_index) { |
455 | 29987 | const auto p0 = point_mapper.map(md_index); | |
456 |
1/2✓ Branch 1 taken 29987 times.
✗ Branch 2 not taken.
|
29987 | corners = {p0, p0 + 1, p0 + x_offset, p0 + 1 + x_offset}; |
457 | 29987 | visitor(grid_dim_to_cell_type[grid_dim], corners); | |
458 | }); | ||
459 | } else { | ||
460 |
1/2✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
|
4961 | std::ranges::for_each(index_range, [&] (const auto& md_index) { |
461 | 4920 | const auto p0 = point_mapper.map(md_index); | |
462 | 9840 | corners = { | |
463 | 4920 | p0, p0 + 1, p0 + x_offset, p0 + 1 + x_offset, | |
464 |
1/2✓ Branch 1 taken 4920 times.
✗ Branch 2 not taken.
|
4920 | p0 + y_offset, p0 + y_offset + 1, p0 + y_offset + x_offset, p0 + 1 + y_offset + x_offset |
465 | }; | ||
466 | 4920 | visitor(grid_dim_to_cell_type[grid_dim], corners); | |
467 | }); | ||
468 | } | ||
469 | 1039 | } | |
470 | |||
471 | } // namespace CommonDetail | ||
472 | #endif // DOXYGEN | ||
473 | |||
474 | //! \} group VTK | ||
475 | } // namespace GridFormat::VTK | ||
476 | |||
477 | |||
478 | #endif // GRIDFORMAT_VTK_COMMON_HPP_ | ||
479 |