Skip to content

Commit f1889d1

Browse files
committed
Adhere to the standard changes more closely
1 parent 18e2a75 commit f1889d1

File tree

9 files changed

+58
-21
lines changed

9 files changed

+58
-21
lines changed

include/openPMD/RecordComponent.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ class RecordComponent : public BaseRecordComponent
487487
static constexpr char const *const SCALAR = "\vScalar";
488488

489489
protected:
490-
void flush(std::string const &, internal::FlushParams const &);
490+
void
491+
flush(std::string const &, internal::FlushParams const &, bool is_scalar);
491492
void read(bool require_unit_si);
492493

493494
private:

include/openPMD/backend/MeshRecordComponent.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class MeshRecordComponent : public RecordComponent
4747
MeshRecordComponent();
4848
MeshRecordComponent(NoInit);
4949
void read();
50-
void flush(std::string const &, internal::FlushParams const &);
50+
void
51+
flush(std::string const &, internal::FlushParams const &, bool is_scalar);
5152

5253
public:
5354
~MeshRecordComponent() override = default;

src/Iteration.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,14 @@ void Iteration::readMeshes(std::string const &meshesPath)
623623
IOHandler()->enqueue(IOTask(&m, aList));
624624
IOHandler()->flush(internal::defaultFlushParams);
625625

626+
// Find constant scalar meshes. shape generally required for meshes,
627+
// shape also required for scalars.
628+
// https://github.com/openPMD/openPMD-standard/pull/289
626629
auto att_begin = aList.attributes->begin();
627630
auto att_end = aList.attributes->end();
628631
auto value = std::find(att_begin, att_end, "value");
629-
if (value != att_end)
632+
auto shape = std::find(att_begin, att_end, "shape");
633+
if (value != att_end && shape != att_end)
630634
{
631635
MeshRecordComponent &mrc = m;
632636
IOHandler()->enqueue(IOTask(&mrc, pOpen));

src/Mesh.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,14 @@ void Mesh::flush_impl(
371371
auto &m = get();
372372
if (m.m_datasetDefined)
373373
{
374-
T_RecordComponent::flush(SCALAR, flushParams);
374+
T_RecordComponent::flush(
375+
SCALAR, flushParams, /* is_scalar = */ true);
375376
}
376377
else
377378
{
378379
for (auto &comp : *this)
379-
comp.second.flush(comp.first, flushParams);
380+
comp.second.flush(
381+
comp.first, flushParams, /* is_scalar = */ false);
380382
}
381383
}
382384
else
@@ -386,7 +388,7 @@ void Mesh::flush_impl(
386388
if (scalar())
387389
{
388390
MeshRecordComponent &mrc = *this;
389-
mrc.flush(name, flushParams);
391+
mrc.flush(name, flushParams, /* is_scalar = */ true);
390392
}
391393
else
392394
{
@@ -396,20 +398,23 @@ void Mesh::flush_impl(
396398
for (auto &comp : *this)
397399
{
398400
comp.second.parent() = &this->writable();
399-
comp.second.flush(comp.first, flushParams);
401+
comp.second.flush(
402+
comp.first, flushParams, /* is_scalar = */ false);
400403
}
401404
}
402405
}
403406
else
404407
{
405408
if (scalar())
406409
{
407-
T_RecordComponent::flush(name, flushParams);
410+
T_RecordComponent::flush(
411+
name, flushParams, /* is_scalar = */ true);
408412
}
409413
else
410414
{
411415
for (auto &comp : *this)
412-
comp.second.flush(comp.first, flushParams);
416+
comp.second.flush(
417+
comp.first, flushParams, /* is_scalar = */ false);
413418
}
414419
}
415420
if (!containsAttribute("gridUnitSI"))

src/ParticleSpecies.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void ParticleSpecies::read()
7676
auto att_begin = aList.attributes->begin();
7777
auto att_end = aList.attributes->end();
7878
auto value = std::find(att_begin, att_end, "value");
79+
// @todo see this comment:
80+
// https://github.com/openPMD/openPMD-standard/pull/289#issuecomment-2407263974
7981
if (value != att_end)
8082
{
8183
RecordComponent &rc = r;

src/Record.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ void Record::flush_impl(
5656
{
5757
if (scalar())
5858
{
59-
T_RecordComponent::flush(SCALAR, flushParams);
59+
T_RecordComponent::flush(
60+
SCALAR, flushParams, /* is_scalar = */ true);
6061
}
6162
else
6263
{
6364
for (auto &comp : *this)
64-
comp.second.flush(comp.first, flushParams);
65+
comp.second.flush(
66+
comp.first, flushParams, /* is_scalar = */ false);
6567
}
6668
}
6769
else
@@ -71,7 +73,7 @@ void Record::flush_impl(
7173
if (scalar())
7274
{
7375
RecordComponent &rc = *this;
74-
rc.flush(name, flushParams);
76+
rc.flush(name, flushParams, /* is_scalar = */ true);
7577
}
7678
else
7779
{
@@ -81,7 +83,8 @@ void Record::flush_impl(
8183
for (auto &comp : *this)
8284
{
8385
comp.second.parent() = getWritable(this);
84-
comp.second.flush(comp.first, flushParams);
86+
comp.second.flush(
87+
comp.first, flushParams, /* is_scalar = */ false);
8588
}
8689
}
8790
}
@@ -90,12 +93,14 @@ void Record::flush_impl(
9093

9194
if (scalar())
9295
{
93-
T_RecordComponent::flush(name, flushParams);
96+
T_RecordComponent::flush(
97+
name, flushParams, /* is_scalar = */ true);
9498
}
9599
else
96100
{
97101
for (auto &comp : *this)
98-
comp.second.flush(comp.first, flushParams);
102+
comp.second.flush(
103+
comp.first, flushParams, /* is_scalar = */ false);
99104
}
100105
}
101106

src/RecordComponent.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ bool RecordComponent::empty() const
241241
}
242242

243243
void RecordComponent::flush(
244-
std::string const &name, internal::FlushParams const &flushParams)
244+
std::string const &name,
245+
internal::FlushParams const &flushParams,
246+
bool is_scalar)
245247
{
246248
auto &rc = get();
247249
if (flushParams.flushLevel == FlushLevel::SkeletonOnly)
@@ -285,6 +287,21 @@ void RecordComponent::flush(
285287
setUnitSI(1);
286288
}
287289
auto constant_component_write_shape = [&]() {
290+
if (is_scalar)
291+
{
292+
// Must write shape in any case:
293+
// 1. Non-scalar constant components can be distinguished from
294+
// normal components by checking if the backend reports a
295+
// group or a dataset. This does not work for scalar constant
296+
// components, so the parser needs to check if the attributes
297+
// value and shape are there. If they're not, the group is
298+
// not considered as a constant component.
299+
// 2. Scalar constant components are required to write the shape
300+
// by standard anyway since the standard requires that at
301+
// least one component in a record have a shape. For scalars,
302+
// there is only one component, so it must have a shape.
303+
return true;
304+
}
288305
auto extent = getExtent();
289306
return !extent.empty() &&
290307
std::none_of(extent.begin(), extent.end(), [](auto val) {

src/backend/MeshRecordComponent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ void MeshRecordComponent::read()
6868
}
6969

7070
void MeshRecordComponent::flush(
71-
std::string const &name, internal::FlushParams const &params)
71+
std::string const &name,
72+
internal::FlushParams const &params,
73+
bool is_scalar)
7274
{
7375
if (access::write(IOHandler()->m_frontendAccess) &&
7476
!containsAttribute("position"))
7577
{
7678
setPosition(std::vector<double>{0});
7779
}
78-
RecordComponent::flush(name, params);
80+
RecordComponent::flush(name, params, is_scalar);
7981
}
8082

8183
template <typename T>

src/backend/PatchRecord.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ PatchRecord::setUnitDimension(std::map<UnitDimension, double> const &udim)
4141
void PatchRecord::flush_impl(
4242
std::string const &path, internal::FlushParams const &flushParams)
4343
{
44-
if (!this->datasetDefined())
44+
if (!this->scalar())
4545
{
4646
if (IOHandler()->m_frontendAccess != Access::READ_ONLY)
4747
Container<PatchRecordComponent>::flush(
4848
path, flushParams); // warning (clang-tidy-10):
4949
// bugprone-parent-virtual-call
5050
for (auto &comp : *this)
51-
comp.second.flush(comp.first, flushParams);
51+
comp.second.flush(comp.first, flushParams, /* is_scalar = */ false);
5252
}
5353
else
54-
T_RecordComponent::flush(path, flushParams);
54+
T_RecordComponent::flush(path, flushParams, /* is_scalar = */ true);
5555
if (flushParams.flushLevel != FlushLevel::SkeletonOnly)
5656
{
5757
setDirty(false);

0 commit comments

Comments
 (0)