Skip to content

Commit ef0ec3e

Browse files
authored
Mesh & ParticleSpecies::seriesFlush (#924)
Implement a method in `Mesh` & `ParticleSpecies` to flush their corresponding `Series`. This simplifies downstream reader implementations operating on a specific mesh or particle species.
1 parent 7d3e925 commit ef0ec3e

9 files changed

Lines changed: 57 additions & 6 deletions

File tree

include/openPMD/Mesh.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class Mesh : public BaseRecord< MeshRecordComponent >
177177
template< typename T >
178178
Mesh& setTimeOffset(T timeOffset);
179179

180+
/** flush the corresponding Series */
181+
void seriesFlush();
182+
180183
private:
181184
Mesh();
182185

include/openPMD/ParticleSpecies.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class ParticleSpecies : public Container< Record >
4040
public:
4141
ParticlePatches particlePatches;
4242

43+
/** flush the corresponding Series */
44+
void seriesFlush();
45+
4346
private:
4447
ParticleSpecies() = default;
4548

include/openPMD/Series.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class WriteIterations;
6464
class Series : public Attributable
6565
{
6666
friend class Iteration;
67+
friend class Mesh;
68+
friend class ParticleSpecies;
6769
friend class SeriesIterator;
6870

6971
public:

src/Mesh.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
#include "openPMD/auxiliary/StringManip.hpp"
2222
#include "openPMD/Mesh.hpp"
23+
#include "openPMD/Series.hpp"
24+
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
25+
#include "openPMD/backend/Writable.hpp"
2326

2427
#include <iostream>
2528

@@ -193,6 +196,23 @@ template
193196
Mesh&
194197
Mesh::setTimeOffset( float );
195198

199+
void
200+
Mesh::seriesFlush()
201+
{
202+
Writable * findSeries = &*m_writable;
203+
while( findSeries->parent )
204+
{
205+
findSeries = findSeries->parent;
206+
}
207+
Series & series =
208+
auxiliary::deref_dynamic_cast< Series >( findSeries->attributable );
209+
series.flush_impl(
210+
series.iterations.begin(),
211+
series.iterations.end()
212+
//, IOHandler->m_flushLevel
213+
);
214+
}
215+
196216
void
197217
Mesh::flush_impl(std::string const& name)
198218
{

src/ParticleSpecies.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121
#include "openPMD/ParticleSpecies.hpp"
22+
#include "openPMD/Series.hpp"
23+
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
24+
#include "openPMD/backend/Writable.hpp"
2225

2326
#include <algorithm>
2427
#include <iostream>
@@ -116,6 +119,23 @@ namespace
116119
}
117120
}
118121

122+
void
123+
ParticleSpecies::seriesFlush()
124+
{
125+
Writable * findSeries = &*m_writable;
126+
while( findSeries->parent )
127+
{
128+
findSeries = findSeries->parent;
129+
}
130+
Series & series =
131+
auxiliary::deref_dynamic_cast< Series >( findSeries->attributable );
132+
series.flush_impl(
133+
series.iterations.begin(),
134+
series.iterations.end()
135+
//, IOHandler->m_flushLevel
136+
);
137+
}
138+
119139
void
120140
ParticleSpecies::flush(std::string const& path)
121141
{

src/binding/python/Mesh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void init_Mesh(py::module &m) {
4141
return "<openPMD.Mesh record with '" + std::to_string(mesh.size()) + "' record components>";
4242
}
4343
)
44+
.def("series_flush", &Mesh::seriesFlush)
4445

4546
.def_property("unit_dimension",
4647
&Mesh::unitDimension,

src/binding/python/ParticleSpecies.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void init_ParticleSpecies(py::module &m) {
3636
return "<openPMD.ParticleSpecies>";
3737
}
3838
)
39+
.def("series_flush", &ParticleSpecies::seriesFlush)
3940

4041
.def_readwrite("particle_patches", &ParticleSpecies::particlePatches)
4142
;

test/SerialIOTest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ void deletion_test(const std::string & backend)
15611561
e["positionOffset"][RecordComponent::SCALAR].resetDataset(dset);
15621562
e["positionOffset"][RecordComponent::SCALAR].makeConstant(22.0);
15631563
e.erase("deletion");
1564-
o.flush();
1564+
e.seriesFlush();
15651565

15661566
e["deletion_scalar"][RecordComponent::SCALAR].resetDataset(dset);
15671567
o.flush();
@@ -2082,11 +2082,12 @@ TEST_CASE( "git_hdf5_sample_content_test", "[serial][hdf5]" )
20822082
{{-1.3271805876513554e-09, -5.9243276950837753e-10, -2.2445734160214670e-10},
20832083
{-7.4578609954301101e-10, -1.1995737736469891e-10, 2.5611823772919706e-10},
20842084
{-9.4806251738077663e-10, -1.5472800818372434e-10, -3.6461900165818406e-10}}};
2085-
MeshRecordComponent& rho = o.iterations[100].meshes["rho"][MeshRecordComponent::SCALAR];
2085+
Mesh rhoMesh = o.iterations[100].meshes["rho"];
2086+
MeshRecordComponent rho = rhoMesh[MeshRecordComponent::SCALAR];
20862087
Offset offset{20, 20, 190};
20872088
Extent extent{3, 3, 3};
20882089
auto data = rho.loadChunk<double>(offset, extent);
2089-
o.flush();
2090+
rhoMesh.seriesFlush();
20902091
double* raw_ptr = data.get();
20912092

20922093
for( int i = 0; i < 3; ++i )
@@ -2624,7 +2625,7 @@ TEST_CASE( "hzdr_hdf5_sample_content_test", "[serial][hdf5]" )
26242625

26252626
std::vector< uint64_t > data( e_patches.size() );
26262627
e_extent_z.load(shareRaw(data.data()));
2627-
o.flush();
2628+
species_e.seriesFlush();
26282629
REQUIRE(data.at(0) == static_cast< uint64_t >(80));
26292630
REQUIRE(data.at(1) == static_cast< uint64_t >(80));
26302631
REQUIRE(data.at(2) == static_cast< uint64_t >(80));

test/python/unittest/API/APITest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def testData(self):
849849

850850
y_data = pos_y.load_chunk([200000, ], [10, ])
851851
w_data = w.load_chunk([200000, ], [10, ])
852-
series.flush()
852+
electrons.series_flush()
853853
self.assertSequenceEqual(y_data.shape, [10, ])
854854
self.assertSequenceEqual(w_data.shape, [10, ])
855855

@@ -887,7 +887,7 @@ def testData(self):
887887

888888
if found_numpy:
889889
chunk_data = E_x.load_chunk(offset, extent)
890-
series.flush()
890+
E.series_flush()
891891
self.assertSequenceEqual(chunk_data.shape, extent)
892892

893893
self.assertEqual(chunk_data.dtype, np.float64)

0 commit comments

Comments
 (0)