|
9 | 9 |
|
10 | 10 | namespace components_without_extent
|
11 | 11 | {
|
12 |
| -auto components_without_extent() -> void |
| 12 | +constexpr char const *filepath = "../samples/components_without_extent.bp5"; |
| 13 | + |
| 14 | +void particle_offset_without_extent() |
13 | 15 | {
|
14 |
| - auto filepath = "../samples/components_without_extent.bp5"; |
15 | 16 | // write
|
16 | 17 | {
|
17 | 18 | openPMD::Series write(filepath, openPMD::Access::CREATE);
|
@@ -45,4 +46,214 @@ auto components_without_extent() -> void
|
45 | 46 | }
|
46 | 47 | }
|
47 | 48 | }
|
| 49 | + |
| 50 | +void particles_without_any_extent() |
| 51 | +{ |
| 52 | + // write |
| 53 | + { |
| 54 | + openPMD::Series write(filepath, openPMD::Access::CREATE); |
| 55 | + auto it0 = write.writeIterations()[0]; |
| 56 | + auto e = it0.particles["e"]; |
| 57 | + for (auto comp_id : {"x", "y", "z"}) |
| 58 | + { |
| 59 | + auto position_comp = e["position"][comp_id]; |
| 60 | + position_comp.resetDataset({openPMD::Datatype::INT, {}}); |
| 61 | + position_comp.makeConstant(0); |
| 62 | + |
| 63 | + auto offset_comp = e["positionOffset"][comp_id]; |
| 64 | + offset_comp.resetDataset({openPMD::Datatype::INT, {}}); |
| 65 | + offset_comp.makeConstant(0); |
| 66 | + } |
| 67 | + write.close(); |
| 68 | + } |
| 69 | + |
| 70 | + // read |
| 71 | + { |
| 72 | + openPMD::Series read(filepath, openPMD::Access::READ_RANDOM_ACCESS); |
| 73 | + REQUIRE(!read.snapshots()[0].particles.contains("e")); |
| 74 | + } |
| 75 | + |
| 76 | + { |
| 77 | + openPMD::Series read( |
| 78 | + filepath, |
| 79 | + openPMD::Access::READ_RANDOM_ACCESS, |
| 80 | + R"({"verify_homogeneous_extents": false})"); |
| 81 | + REQUIRE(read.snapshots()[0].particles.contains("e")); |
| 82 | + auto e = read.snapshots()[0].particles["e"]; |
| 83 | + for (auto const &record : e) |
| 84 | + { |
| 85 | + for (auto const &component : record.second) |
| 86 | + { |
| 87 | + REQUIRE(component.second.getExtent() == openPMD::Extent{}); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +void particles_without_inconsistent_extent() |
| 94 | +{ |
| 95 | + // write |
| 96 | + { |
| 97 | + openPMD::Series write(filepath, openPMD::Access::CREATE); |
| 98 | + auto it0 = write.writeIterations()[0]; |
| 99 | + auto e = it0.particles["e"]; |
| 100 | + for (auto comp_id : {"x", "y", "z"}) |
| 101 | + { |
| 102 | + auto position_comp = e["position"][comp_id]; |
| 103 | + position_comp.resetDataset({openPMD::Datatype::INT, {5}}); |
| 104 | + position_comp.makeConstant(0); |
| 105 | + |
| 106 | + auto offset_comp = e["positionOffset"][comp_id]; |
| 107 | + offset_comp.resetDataset({openPMD::Datatype::INT, {10}}); |
| 108 | + offset_comp.makeConstant(0); |
| 109 | + } |
| 110 | + write.close(); |
| 111 | + } |
| 112 | + |
| 113 | + // read |
| 114 | + { |
| 115 | + openPMD::Series read(filepath, openPMD::Access::READ_RANDOM_ACCESS); |
| 116 | + REQUIRE(!read.snapshots()[0].particles.contains("e")); |
| 117 | + } |
| 118 | + |
| 119 | + { |
| 120 | + openPMD::Series read( |
| 121 | + filepath, |
| 122 | + openPMD::Access::READ_RANDOM_ACCESS, |
| 123 | + R"({"verify_homogeneous_extents": false})"); |
| 124 | + REQUIRE(read.snapshots()[0].particles.contains("e")); |
| 125 | + auto e = read.snapshots()[0].particles["e"]; |
| 126 | + for (auto const &component : e["position"]) |
| 127 | + { |
| 128 | + REQUIRE(component.second.getExtent() == openPMD::Extent{5}); |
| 129 | + } |
| 130 | + for (auto const &component : e["positionOffset"]) |
| 131 | + { |
| 132 | + REQUIRE(component.second.getExtent() == openPMD::Extent{10}); |
| 133 | + } |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +void meshes_with_incomplete_extent() |
| 138 | +{ |
| 139 | + // write |
| 140 | + { |
| 141 | + openPMD::Series write(filepath, openPMD::Access::CREATE); |
| 142 | + auto it0 = write.writeIterations()[0]; |
| 143 | + auto E = it0.meshes["E"]; |
| 144 | + for (auto comp_id : {"x"}) |
| 145 | + { |
| 146 | + auto comp = E[comp_id]; |
| 147 | + comp.resetDataset({openPMD::Datatype::FLOAT, {5}}); |
| 148 | + std::unique_ptr<float[]> data{new float[5]}; |
| 149 | + std::iota(data.get(), data.get() + 5, 0); |
| 150 | + comp.storeChunk(std::move(data), {0}, {5}); |
| 151 | + } |
| 152 | + for (auto comp_id : {"y", "z"}) |
| 153 | + { |
| 154 | + auto comp = E[comp_id]; |
| 155 | + comp.resetDataset({openPMD::Datatype::INT, {}}); |
| 156 | + comp.makeConstant(0); |
| 157 | + } |
| 158 | + write.close(); |
| 159 | + } |
| 160 | + |
| 161 | + // read |
| 162 | + { |
| 163 | + openPMD::Series read(filepath, openPMD::Access::READ_RANDOM_ACCESS); |
| 164 | + auto E = read.snapshots()[0].meshes["E"]; |
| 165 | + for (auto const &component : E) |
| 166 | + { |
| 167 | + REQUIRE(component.second.getExtent() == openPMD::Extent{5}); |
| 168 | + } |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +void meshes_with_inconsistent_extent() |
| 173 | +{ |
| 174 | + // write |
| 175 | + { |
| 176 | + openPMD::Series write(filepath, openPMD::Access::CREATE); |
| 177 | + auto it0 = write.writeIterations()[0]; |
| 178 | + auto E = it0.meshes["E"]; |
| 179 | + size_t i = 1; |
| 180 | + for (auto comp_id : {"x", "y", "z"}) |
| 181 | + { |
| 182 | + size_t extent = i++ * 5; |
| 183 | + auto comp = E[comp_id]; |
| 184 | + comp.resetDataset({openPMD::Datatype::FLOAT, {extent}}); |
| 185 | + std::unique_ptr<float[]> data{new float[extent]}; |
| 186 | + std::iota(data.get(), data.get() + extent, 0); |
| 187 | + comp.storeChunk(std::move(data), {0}, {extent}); |
| 188 | + } |
| 189 | + write.close(); |
| 190 | + } |
| 191 | + |
| 192 | + // read |
| 193 | + { |
| 194 | + openPMD::Series read(filepath, openPMD::Access::READ_RANDOM_ACCESS); |
| 195 | + REQUIRE(!read.snapshots()[0].meshes.contains("E")); |
| 196 | + } |
| 197 | + |
| 198 | + // read |
| 199 | + { |
| 200 | + openPMD::Series read( |
| 201 | + filepath, |
| 202 | + openPMD::Access::READ_RANDOM_ACCESS, |
| 203 | + R"({"verify_homogeneous_extents": false})"); |
| 204 | + auto E = read.snapshots()[0].meshes["E"]; |
| 205 | + size_t i = 1; |
| 206 | + for (auto const &component : E) |
| 207 | + { |
| 208 | + REQUIRE(component.second.getExtent() == openPMD::Extent{5 * i++}); |
| 209 | + } |
| 210 | + } |
| 211 | +} |
| 212 | + |
| 213 | +void meshes_without_any_extent() |
| 214 | +{ |
| 215 | + // write |
| 216 | + { |
| 217 | + openPMD::Series write(filepath, openPMD::Access::CREATE); |
| 218 | + auto it0 = write.writeIterations()[0]; |
| 219 | + auto E = it0.meshes["E"]; |
| 220 | + size_t i = 1; |
| 221 | + for (auto comp_id : {"x", "y", "z"}) |
| 222 | + { |
| 223 | + auto comp = E[comp_id]; |
| 224 | + comp.resetDataset({openPMD::Datatype::FLOAT, {}}); |
| 225 | + comp.makeConstant<float>(0); |
| 226 | + } |
| 227 | + write.close(); |
| 228 | + } |
| 229 | + |
| 230 | + // read |
| 231 | + { |
| 232 | + openPMD::Series read(filepath, openPMD::Access::READ_RANDOM_ACCESS); |
| 233 | + REQUIRE(!read.snapshots()[0].meshes.contains("E")); |
| 234 | + } |
| 235 | + |
| 236 | + // read |
| 237 | + { |
| 238 | + openPMD::Series read( |
| 239 | + filepath, |
| 240 | + openPMD::Access::READ_RANDOM_ACCESS, |
| 241 | + R"({"verify_homogeneous_extents": false})"); |
| 242 | + auto E = read.snapshots()[0].meshes["E"]; |
| 243 | + for (auto const &component : E) |
| 244 | + { |
| 245 | + REQUIRE(component.second.getExtent() == openPMD::Extent{}); |
| 246 | + } |
| 247 | + } |
| 248 | +} |
| 249 | + |
| 250 | +auto components_without_extent() -> void |
| 251 | +{ |
| 252 | + particle_offset_without_extent(); |
| 253 | + particles_without_any_extent(); |
| 254 | + particles_without_inconsistent_extent(); |
| 255 | + meshes_with_incomplete_extent(); |
| 256 | + meshes_with_inconsistent_extent(); |
| 257 | + meshes_without_any_extent(); |
| 258 | +} |
48 | 259 | } // namespace components_without_extent
|
0 commit comments