From 7909babfeb7d6dad3754c72bdd0e3bf1e76736c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Thu, 6 Oct 2022 15:14:36 +0200 Subject: [PATCH] Fix the bugs found by this check Fix the examples, the unfinished_iteratoin_test and the Coretests --- examples/7_extended_write_serial.cpp | 5 +++-- examples/7_extended_write_serial.py | 4 +++- examples/9_particle_write_serial.py | 4 +++- test/CoreTest.cpp | 28 ++++++++++++++++------------ test/SerialIOTest.cpp | 8 ++++++++ 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/examples/7_extended_write_serial.cpp b/examples/7_extended_write_serial.cpp index bfb64e1fff..580894a34f 100644 --- a/examples/7_extended_write_serial.cpp +++ b/examples/7_extended_write_serial.cpp @@ -83,8 +83,9 @@ int main() {{io::UnitDimension::M, 1}}); electrons["displacement"]["x"].setUnitSI(1e-6); electrons.erase("displacement"); - electrons["weighting"][io::RecordComponent::SCALAR].makeConstant( - 1.e-5); + electrons["weighting"][io::RecordComponent::SCALAR] + .resetDataset({io::Datatype::FLOAT, {1}}) + .makeConstant(1.e-5); } io::Mesh mesh = cur_it.meshes["lowRez_2D_field"]; diff --git a/examples/7_extended_write_serial.py b/examples/7_extended_write_serial.py index 84ca5002db..e16b4b993a 100755 --- a/examples/7_extended_write_serial.py +++ b/examples/7_extended_write_serial.py @@ -90,7 +90,9 @@ electrons["displacement"].unit_dimension = {Unit_Dimension.M: 1} electrons["displacement"]["x"].unit_SI = 1.e-6 del electrons["displacement"] - electrons["weighting"][SCALAR].make_constant(1.e-5) + electrons["weighting"][SCALAR] \ + .reset_dataset(Dataset(np.dtype("float32"), extent=[1])) \ + .make_constant(1.e-5) mesh = cur_it.meshes["lowRez_2D_field"] mesh.axis_labels = ["x", "y"] diff --git a/examples/9_particle_write_serial.py b/examples/9_particle_write_serial.py index aebd266528..0109a48a57 100644 --- a/examples/9_particle_write_serial.py +++ b/examples/9_particle_write_serial.py @@ -44,7 +44,9 @@ # don't like it anymore? remove it with: # del electrons["displacement"] - electrons["weighting"][SCALAR].make_constant(1.e-5) + electrons["weighting"][SCALAR] \ + .reset_dataset(Dataset(np.dtype("float32"), extent=[1])) \ + .make_constant(1.e-5) particlePos_x = np.random.rand(234).astype(np.float32) particlePos_y = np.random.rand(234).astype(np.float32) diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index 496cb0a36f..f21ee0867e 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -25,6 +25,8 @@ using namespace openPMD; +Dataset globalDataset(Datatype::CHAR, {1}); + TEST_CASE("versions_test", "[core]") { auto const apiVersion = getVersion(); @@ -439,11 +441,11 @@ TEST_CASE("record_constructor_test", "[core]") ps["position"][RecordComponent::SCALAR].resetDataset(dset); ps["positionOffset"][RecordComponent::SCALAR].resetDataset(dset); - REQUIRE(r["x"].unitSI() == 1); + REQUIRE(r["x"].resetDataset(dset).unitSI() == 1); REQUIRE(r["x"].numAttributes() == 1); /* unitSI */ - REQUIRE(r["y"].unitSI() == 1); + REQUIRE(r["y"].resetDataset(dset).unitSI() == 1); REQUIRE(r["y"].numAttributes() == 1); /* unitSI */ - REQUIRE(r["z"].unitSI() == 1); + REQUIRE(r["z"].resetDataset(dset).unitSI() == 1); REQUIRE(r["z"].numAttributes() == 1); /* unitSI */ std::array zeros{{0., 0., 0., 0., 0., 0., 0.}}; REQUIRE(r.unitDimension() == zeros); @@ -488,13 +490,15 @@ TEST_CASE("recordComponent_modification_test", "[core]") r["x"].setUnitSI(2.55999e-7); r["y"].setUnitSI(4.42999e-8); - REQUIRE(r["x"].unitSI() == static_cast(2.55999e-7)); + REQUIRE( + r["x"].resetDataset(dset).unitSI() == static_cast(2.55999e-7)); REQUIRE(r["x"].numAttributes() == 1); /* unitSI */ - REQUIRE(r["y"].unitSI() == static_cast(4.42999e-8)); + REQUIRE( + r["y"].resetDataset(dset).unitSI() == static_cast(4.42999e-8)); REQUIRE(r["y"].numAttributes() == 1); /* unitSI */ r["z"].setUnitSI(1); - REQUIRE(r["z"].unitSI() == static_cast(1)); + REQUIRE(r["z"].resetDataset(dset).unitSI() == static_cast(1)); REQUIRE(r["z"].numAttributes() == 1); /* unitSI */ } @@ -505,13 +509,13 @@ TEST_CASE("mesh_constructor_test", "[core]") Mesh &m = o.iterations[42].meshes["E"]; std::vector pos{0}; - REQUIRE(m["x"].unitSI() == 1); + REQUIRE(m["x"].resetDataset(globalDataset).unitSI() == 1); REQUIRE(m["x"].numAttributes() == 2); /* unitSI, position */ REQUIRE(m["x"].position() == pos); - REQUIRE(m["y"].unitSI() == 1); + REQUIRE(m["y"].resetDataset(globalDataset).unitSI() == 1); REQUIRE(m["y"].numAttributes() == 2); /* unitSI, position */ REQUIRE(m["y"].position() == pos); - REQUIRE(m["z"].unitSI() == 1); + REQUIRE(m["z"].resetDataset(globalDataset).unitSI() == 1); REQUIRE(m["z"].numAttributes() == 2); /* unitSI, position */ REQUIRE(m["z"].position() == pos); REQUIRE(m.geometry() == Mesh::Geometry::cartesian); @@ -534,9 +538,9 @@ TEST_CASE("mesh_modification_test", "[core]") Series o = Series("./MyOutput_%T.json", Access::CREATE); Mesh &m = o.iterations[42].meshes["E"]; - m["x"]; - m["y"]; - m["z"]; + m["x"].resetDataset(globalDataset); + m["y"].resetDataset(globalDataset); + m["z"].resetDataset(globalDataset); m.setGeometry(Mesh::Geometry::spherical); REQUIRE(m.geometry() == Mesh::Geometry::spherical); diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 9dda38cd4a..0a0ff41c14 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -6469,11 +6469,19 @@ void unfinished_iteration_test( */ it5.setAttribute("__openPMD_internal_fail", "asking for trouble"); auto it10 = write.writeIterations()[10]; + Dataset ds(Datatype::INT, {10}); auto E_x = it10.meshes["E"]["x"]; auto e_density = it10.meshes["e_density"][RecordComponent::SCALAR]; auto electron_x = it10.particles["e"]["position"]["x"]; auto electron_mass = it10.particles["e"]["mass"][RecordComponent::SCALAR]; + + RecordComponent *resetThese[] = { + &E_x, &e_density, &electron_x, &electron_mass}; + for (RecordComponent *rc : resetThese) + { + rc->resetDataset(ds); + } } auto tryReading = [&config, file, encoding]( Access access,