From 6b31e7944145fcfef05bdc8885f14c1e9ce130fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Wed, 5 Jun 2019 16:56:38 +0200 Subject: [PATCH 1/2] Adapt tests to allowing delayed write of position and positionOffset --- test/CoreTest.cpp | 2 -- test/SerialIOTest.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index dc647b6265..e0358e8f00 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -234,8 +234,6 @@ TEST_CASE( "particleSpecies_modification_test", "[core]" ) REQUIRE(1 == particles.size()); REQUIRE(1 == particles.count("species")); REQUIRE(0 == species.numAttributes()); - REQUIRE(2 == species.size()); //position, positionOffset - REQUIRE(1 == species.count("position")); auto dset = Dataset(Datatype::DOUBLE, {1}); species["position"][RecordComponent::SCALAR].resetDataset(dset); species["positionOffset"][RecordComponent::SCALAR].resetDataset(dset); diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 82e6a4890b..efbb81fead 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -171,6 +171,41 @@ TEST_CASE( "constant_scalar", "[serial]" ) } } +TEST_CASE( "flush_without_position_positionOffset", "[serial]" ) +{ + for( auto const & t : backends ) + { + const std::string & file_ending = std::get< 0 >( t ); + Series s = Series( + "../samples/flush_without_position_positionOffset." + file_ending, + AccessType::CREATE ); + ParticleSpecies e = s.iterations[ 0 ].particles[ "e" ]; + RecordComponent weighting = e[ "weighting" ][ RecordComponent::SCALAR ]; + weighting.resetDataset( Dataset( Datatype::FLOAT, Extent{ 2, 2 } ) ); + weighting.storeChunk( std::shared_ptr< float >( + new float[ 4 ]{}, + []( float * ptr ) { delete[] ptr; } ), + { 0, 0 }, + { 2, 2 } ); + + s.flush(); + + for( auto const & key : { "position", "positionOffset" } ) + { + for( auto const & dim : { "x", "y", "z" } ) + { + RecordComponent rc = e[ key ][ dim ]; + rc.resetDataset( Dataset( Datatype::FLOAT , Extent{ 2, 2 } ) ); + rc.storeChunk( std::shared_ptr< float >( + new float[ 4 ]{}, + []( float * ptr ) { delete[] ptr; } ), + { 0, 0 }, + { 2, 2 } ); + } + } + } +} + inline void particle_patches( std::string file_ending ) From 4bdd73fbed07023e9b4b8718c432b049e8492b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Wed, 5 Jun 2019 16:57:22 +0200 Subject: [PATCH 2/2] Allow flushes before defining position and positionOffset records This will ensure openPMD specific requirements for those records at flush time as soon as those records are present -- rather than at creation time of the particle species object. Currently missing is any kind of check that those records are present before closing the series. --- include/openPMD/ParticleSpecies.hpp | 3 --- src/ParticleSpecies.cpp | 11 +++++++++++ test/CoreTest.cpp | 2 -- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/openPMD/ParticleSpecies.hpp b/include/openPMD/ParticleSpecies.hpp index 288d0d28e0..6c11a715a8 100644 --- a/include/openPMD/ParticleSpecies.hpp +++ b/include/openPMD/ParticleSpecies.hpp @@ -55,9 +55,6 @@ namespace traits template< typename T > void operator()(T & ret) { - /* enforce these two RecordComponents as required by the standard */ - ret["position"].setUnitDimension({{UnitDimension::L, 1}}); - ret["positionOffset"].setUnitDimension({{UnitDimension::L, 1}}); ret.particlePatches.linkHierarchy(ret.m_writable); auto& np = ret.particlePatches["numParticles"]; diff --git a/src/ParticleSpecies.cpp b/src/ParticleSpecies.cpp index 91fe4ea429..be653bf246 100644 --- a/src/ParticleSpecies.cpp +++ b/src/ParticleSpecies.cpp @@ -122,6 +122,17 @@ ParticleSpecies::flush(std::string const& path) for( auto& patch : particlePatches ) patch.second.flush(patch.first); } + + iterator it = find("position"); + if ( it != end() ) + { + it->second.setUnitDimension({{UnitDimension::L, 1}}); + } + it = find("positionOffset"); + if ( it != end() ) + { + it->second.setUnitDimension({{UnitDimension::L, 1}}); + } } } } // openPMD diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index e0358e8f00..ed9a17959b 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -449,8 +449,6 @@ TEST_CASE( "structure_test", "[core]" ) REQUIRE(o.iterations[1].particles["P"].particlePatches.IOHandler); REQUIRE(o.iterations[1].particles["P"].particlePatches.parent == getWritable(&o.iterations[1].particles["P"])); - REQUIRE(1 == o.iterations[1].particles["P"].count("position")); - REQUIRE(1 == o.iterations[1].particles["P"].count("positionOffset")); auto dset = Dataset(Datatype::DOUBLE, {1}); o.iterations[1].particles["P"]["position"][RecordComponent::SCALAR].resetDataset(dset); o.iterations[1].particles["P"]["positionOffset"][RecordComponent::SCALAR].resetDataset(dset);