|
30 | 30 | #include "openPMD/auxiliary/DerefDynamicCast.hpp" |
31 | 31 | #include "openPMD/auxiliary/Filesystem.hpp" |
32 | 32 | #include "openPMD/auxiliary/StringManip.hpp" |
| 33 | +#include "openPMD/auxiliary/TypeTraits.hpp" |
33 | 34 | #include "openPMD/auxiliary/Variant.hpp" |
34 | 35 | #include "openPMD/backend/Attributable.hpp" |
| 36 | +#include "openPMD/backend/BaseRecordComponent.hpp" |
35 | 37 | #include "openPMD/backend/ScientificDefaults.hpp" |
36 | 38 | #include "openPMD/backend/ScientificDefaults_impl.hpp" |
37 | 39 | #include "openPMD/backend/Variant_internal.hpp" |
|
44 | 46 | #include <optional> |
45 | 47 | #include <stdexcept> |
46 | 48 | #include <tuple> |
| 49 | +#include <type_traits> |
47 | 50 | #include <variant> |
48 | 51 |
|
49 | 52 | namespace openPMD |
@@ -114,7 +117,7 @@ Iteration &Iteration::close(bool _flush) |
114 | 117 |
|
115 | 118 | if (access::write(IOHandler()->m_frontendAccess)) |
116 | 119 | { |
117 | | - writeDefaultsRecursively(IOHandler()->m_standard); |
| 120 | + setDefaultAttributes(); |
118 | 121 | } |
119 | 122 |
|
120 | 123 | if (_flush) |
@@ -148,6 +151,40 @@ Iteration &Iteration::close(bool _flush) |
148 | 151 | return *this; |
149 | 152 | } |
150 | 153 |
|
| 154 | +void Iteration::setDefaultAttributes() |
| 155 | +{ |
| 156 | + auto standard = IOHandler()->m_standard; |
| 157 | + visitHierarchy([standard](auto &component) { |
| 158 | + using ComponentType = std::remove_reference_t<decltype(component)>; |
| 159 | + if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, ComponentType>) |
| 160 | + { |
| 161 | + if (component.empty() && !component.datasetDefined()) |
| 162 | + { |
| 163 | + std::cerr |
| 164 | + << "Cannot flush Record without any contained components: '" |
| 165 | + << component.myPath().openPMDPath() << "'. Will ignore."; |
| 166 | + if (component.written()) |
| 167 | + { |
| 168 | + std::cerr |
| 169 | + << "\n(Note: The Record seems to have been written " |
| 170 | + "previously?)"; |
| 171 | + } |
| 172 | + std::cerr << std::endl; |
| 173 | + return; |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + if constexpr ( |
| 178 | + !std::is_same_v<ComponentType, Container<Mesh>> && |
| 179 | + !std::is_same_v<ComponentType, Container<Record>> && |
| 180 | + !std::is_same_v<ComponentType, Container<PatchRecord>> && |
| 181 | + !std::is_same_v<ComponentType, Container<ParticleSpecies>>) |
| 182 | + { |
| 183 | + component.writeDefaults(standard); |
| 184 | + } |
| 185 | + }); |
| 186 | +} |
| 187 | + |
151 | 188 | Iteration &Iteration::open() |
152 | 189 | { |
153 | 190 | Series s = retrieveSeries(); |
@@ -941,22 +978,17 @@ void Iteration::defaults_impl(bool write, OpenpmdStandard) |
941 | 978 | auto float_types = get_float_types(); |
942 | 979 | auto const wor = write ? WriteOrRead::Write : WriteOrRead::Read; |
943 | 980 |
|
944 | | - defaultAttribute("time") |
| 981 | + defaultAttribute(*this, "time") |
945 | 982 | .template withSetter<Iteration>(0., &Iteration::setTime) |
946 | 983 | .withReader(float_types, require_scalar)(wor); |
947 | | - defaultAttribute("dt") |
| 984 | + defaultAttribute(*this, "dt") |
948 | 985 | .template withSetter<Iteration>(1., &Iteration::setDt) |
949 | 986 | .withReader(float_types, require_scalar)(wor); |
950 | | - defaultAttribute("timeUnitSI") |
| 987 | + defaultAttribute(*this, "timeUnitSI") |
951 | 988 | .template withSetter<Iteration>(1.0, &Iteration::setTimeUnitSI) |
952 | 989 | .withReader(float_types, require_type<double>())(wor); |
953 | 990 | } |
954 | 991 |
|
955 | | -auto Iteration::as_attributable() -> Attributable & |
956 | | -{ |
957 | | - return *this; |
958 | | -} |
959 | | - |
960 | 992 | template float Iteration::time<float>() const; |
961 | 993 | template double Iteration::time<double>() const; |
962 | 994 | template long double Iteration::time<long double>() const; |
|
0 commit comments