Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5305435
Base structure for scientific defaults
franzpoeschel Jan 12, 2026
ecbe88d
Start adding defaults
franzpoeschel Jan 12, 2026
3e1cceb
debugging output
franzpoeschel Jan 12, 2026
4f6d7c8
Fixes
franzpoeschel Jan 12, 2026
84539cf
BaseRecord --> unitDimension
franzpoeschel Jan 12, 2026
7428f6d
nunja hehe
franzpoeschel Jan 12, 2026
c14851c
Fixes
franzpoeschel Jan 12, 2026
5fbf987
Further fixes
franzpoeschel Jan 13, 2026
170e522
further fixes
franzpoeschel Jan 13, 2026
1ab3b0b
tests temporarily passing :D
franzpoeschel Jan 13, 2026
e494429
Cleanup
franzpoeschel Jan 13, 2026
6855b48
UnitDimension for position/positionOffset
franzpoeschel Jan 13, 2026
e3edc1b
WIP: RecordComponent stuff
franzpoeschel Jan 13, 2026
07577e5
Fix coretests
franzpoeschel Jan 14, 2026
a4d0597
Clean up Iteration finalizing logic
franzpoeschel Jan 14, 2026
2a43516
Add defaults for Iteration class
franzpoeschel Jan 14, 2026
747665e
Fix variadic template template parameters
franzpoeschel Jan 15, 2026
e222744
Remove flush-time check for populized components
franzpoeschel Jan 16, 2026
5327d87
Make the default specification more flexible
franzpoeschel Jan 16, 2026
95e6699
WIP
franzpoeschel Jan 20, 2026
fa66809
continue
franzpoeschel Jan 20, 2026
e5e513e
Split this into internal and public header
franzpoeschel Jan 21, 2026
e9c871d
Distinguish writing from reading
franzpoeschel Jan 21, 2026
95e3c19
Tests now working again
franzpoeschel Jan 21, 2026
0e7e572
Mostly move Mesh reading to ScientificDefaults
franzpoeschel Jan 21, 2026
02671bb
Fix type conversions between char and string
franzpoeschel Jan 21, 2026
3672d2f
Somewhat working Mesh reading
franzpoeschel Jan 21, 2026
b6c9cc3
Fix little parent call bug
franzpoeschel Jan 22, 2026
eeeb1c4
Mention expected datatypes in attribute reading error messages
franzpoeschel Jan 22, 2026
bfd5797
Move Iteration reading to ScientificDefaults class
franzpoeschel Jan 22, 2026
f345d4d
Introduce genericsetter, use for unitDimension
franzpoeschel Jan 22, 2026
5f13092
Record / BaseRecord Reading
franzpoeschel Jan 22, 2026
b7abb3e
Readers for everything now except version-dependent stuff
franzpoeschel Jan 22, 2026
90c205e
Add gridUnitDimension in ScientificDefaults
franzpoeschel Jan 23, 2026
7d98e8e
Do not use templates for defaults setter
franzpoeschel Jan 26, 2026
535721c
Wew NewAttributeReader
franzpoeschel Jan 27, 2026
abdd175
Fixes
franzpoeschel Jan 27, 2026
5c1b6d3
Fixes
franzpoeschel Jan 27, 2026
e4aa13c
Defaults for patchRecord
franzpoeschel Jan 27, 2026
983736d
Adapt PatchRecordComponent
franzpoeschel Jan 27, 2026
6b9303c
Fixes
franzpoeschel Jan 27, 2026
8ed03f2
Cleanup
franzpoeschel Jan 28, 2026
1b4d5bc
Cleanup
franzpoeschel Jan 28, 2026
0897c18
Avoid overcomplex attribute type conversions
franzpoeschel Jan 28, 2026
8d64cee
reduce binary size a bit
franzpoeschel Jan 28, 2026
e2eda11
Try further reducing amount of lambdas...
franzpoeschel Jan 28, 2026
7560230
Annotate MB sizes
franzpoeschel Jan 28, 2026
afc7414
Reduce implementation sizes for RequireScalar / RequireVector
franzpoeschel Jan 29, 2026
6b41972
vibe-coded suggestions for size optimization
franzpoeschel Jan 29, 2026
dbdb781
Avoid using lambdas for require_type
franzpoeschel Jan 29, 2026
f876db9
Change code order
franzpoeschel Jan 29, 2026
9210471
Replace if constexpr with SFINAE
franzpoeschel Jan 30, 2026
9dbef19
Fix nvhpc/msvc builds
franzpoeschel Jan 30, 2026
1dc9113
doxygen fix
franzpoeschel Feb 2, 2026
1c87e86
Cleanup
franzpoeschel Feb 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ set(CORE_SOURCE
src/backend/PatchRecord.cpp
src/backend/PatchRecordComponent.cpp
src/backend/Writable.cpp
src/backend/ScientificDefaults.cpp
src/auxiliary/OneDimensionalBlockSlicer.cpp
src/helper/list_series.cpp
src/snapshots/ContainerImpls.cpp
Expand Down
6 changes: 5 additions & 1 deletion include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <cstdint>
#include <deque>
Expand Down Expand Up @@ -142,7 +143,9 @@ namespace internal
* @see
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#required-attributes-for-the-basepath
*/
class Iteration : public Attributable
class Iteration
: public Attributable
, internal::ScientificDefaults<Iteration>
{
template <typename T, typename T_key, typename T_container>
friend class Container;
Expand All @@ -153,6 +156,7 @@ class Iteration : public Attributable
friend class Writable;
friend class StatefulIterator;
friend class StatefulSnapshotsContainer;
friend class internal::ScientificDefaults<Iteration>;

public:
Iteration(Iteration const &) = default;
Expand Down
14 changes: 13 additions & 1 deletion include/openPMD/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "openPMD/UnitDimension.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/BaseRecord.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/MeshRecordComponent.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <ostream>
#include <string>
Expand All @@ -37,10 +39,14 @@ namespace openPMD
* @see
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#mesh-based-records
*/
class Mesh : public BaseRecord<MeshRecordComponent>
class Mesh
: public BaseRecord<MeshRecordComponent>
, internal::ScientificDefaults<Mesh>
{
friend class Container<Mesh>;
friend class Iteration;
template <typename>
friend class internal::ScientificDefaults;

public:
Mesh(Mesh const &) = default;
Expand Down Expand Up @@ -328,8 +334,14 @@ class Mesh : public BaseRecord<MeshRecordComponent>
void
flush_impl(std::string const &, internal::FlushParams const &) override;
void read();
auto retrieveDimensionality() const -> uint64_t;
}; // Mesh

static_assert(internal::IsContainer_v<Mesh>);
static_assert(std::is_same_v<
Container<MeshRecordComponent>,
internal::AsContainer_t<Mesh>>);

template <typename T>
inline std::vector<T> Mesh::gridSpacing() const
{
Expand Down
7 changes: 6 additions & 1 deletion include/openPMD/ParticleSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@
#include "openPMD/Record.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <string>

namespace openPMD
{

class ParticleSpecies : public Container<Record>
class ParticleSpecies
: public Container<Record>
, internal::ScientificDefaults<ParticleSpecies>
{
friend class Container<ParticleSpecies>;
friend class Container<Record>;
friend class Iteration;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
template <typename>
friend class internal::ScientificDefaults;

public:
ParticlePatches particlePatches;
Expand Down
9 changes: 8 additions & 1 deletion include/openPMD/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@
#include "openPMD/RecordComponent.hpp"
#include "openPMD/UnitDimension.hpp"
#include "openPMD/backend/BaseRecord.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <string>
#include <type_traits>

namespace openPMD
{
class Record : public BaseRecord<RecordComponent>
class Record
: public BaseRecord<RecordComponent>
, internal::ScientificDefaults<Record>
{
friend class Container<Record>;
friend class Iteration;
friend class ParticleSpecies;
template <typename>
friend class internal::ScientificDefaults;

public:
Record(Record const &) = default;
Expand All @@ -57,6 +62,8 @@ class Record : public BaseRecord<RecordComponent>
[[nodiscard]] internal::HomogenizeExtents read();
}; // Record

static_assert(internal::HasScientificDefaults_v<Record>);

template <typename T>
inline T Record::timeOffset() const
{
Expand Down
11 changes: 8 additions & 3 deletions include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "openPMD/auxiliary/UniquePtr.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/BaseRecordComponent.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

// comment to prevent this include from being moved by clang-format
#include "openPMD/DatatypeMacros.hpp"
Expand Down Expand Up @@ -110,7 +111,9 @@ namespace internal
template <typename>
class BaseRecord;

class RecordComponent : public BaseRecordComponent
class RecordComponent
: public BaseRecordComponent
, internal::ScientificDefaults<RecordComponent>
{
template <typename T, typename T_key, typename T_container>
friend class Container;
Expand All @@ -128,6 +131,8 @@ class RecordComponent : public BaseRecordComponent
friend class MeshRecordComponent;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
template <typename>
friend class internal::ScientificDefaults;

public:
enum class Allocation
Expand Down Expand Up @@ -486,7 +491,7 @@ class RecordComponent : public BaseRecordComponent

protected:
void flush(std::string const &, internal::FlushParams const &);
void read(bool require_unit_si);
void read();

private:
/**
Expand Down Expand Up @@ -534,7 +539,7 @@ OPENPMD_protected
BaseRecordComponent::setData(m_recordComponentData);
}

void readBase(bool require_unit_si);
void readBase();

template <typename T>
void verifyChunk(Offset const &, Extent const &) const;
Expand Down
50 changes: 50 additions & 0 deletions include/openPMD/auxiliary/TypeTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ namespace detail
{
constexpr static bool value = true;
};

template <typename T>
struct ScalarType
{
using type = T;
};
template <typename T>
struct ScalarType<std::vector<T>>
{
using type = T;
};
template <typename T, size_t N>
struct ScalarType<std::array<T, N>>
{
using type = T;
};
} // namespace detail

template <typename T>
Expand All @@ -141,6 +157,12 @@ using IsPointer_t = typename detail::IsPointer<T>::type;
template <typename C>
inline constexpr bool IsChar_v = detail::IsChar<C>::value;

template <typename T>
using ScalarType_t = typename detail::ScalarType<T>::type;

template <typename T>
using VectorType_t = std::vector<ScalarType_t<T>>;

/** Emulate in the C++ concept ContiguousContainer
*
* Users can implement this trait for a type to signal it can be used as
Expand Down Expand Up @@ -203,6 +225,34 @@ namespace detail
// little trick to avoid trailing commas in the macro expansions below
template <typename Arg, typename... Args>
using variant_tail_t = std::variant<Args...>;

template <template <typename...> class Base, typename... Args>
auto infer_template_args(Base<Args...> &) -> Base<Args...>;

template <
template <typename...> class Base,
typename T,
typename SFINAE = void>
struct IsTemplateBaseOf
{
static constexpr bool value = false;
};

template <template <typename...> class Base, typename T>
struct IsTemplateBaseOf<
Base,
T,
std::void_t<decltype(detail::infer_template_args<Base>(
std::declval<T &>()))>>
{
static constexpr bool value = true;
using type =
decltype(detail::infer_template_args<Base>(std::declval<T &>()));
};
} // namespace detail

template <template <typename...> class Base, typename T>
constexpr bool IsTemplateBaseOf_v = detail::IsTemplateBaseOf<Base, T>::value;
template <template <typename...> class Base, typename T>
using AsTemplateBase_t = typename detail::IsTemplateBaseOf<Base, T>::type;
} // namespace openPMD::auxiliary
3 changes: 3 additions & 0 deletions include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace internal
class IterationData;
class SeriesData;
struct HomogenizeExtents;
struct ConfigAttribute;

class SharedAttributableData
{
Expand Down Expand Up @@ -244,6 +245,7 @@ class Attributable
friend class internal::AttributableData;
friend class Snapshots;
friend struct internal::HomogenizeExtents;
friend struct internal::ConfigAttribute;

protected:
// tag for internal constructor
Expand Down Expand Up @@ -276,6 +278,7 @@ class Attributable
template <typename T>
bool setAttribute(std::string const &key, T value);
bool setAttribute(std::string const &key, char const value[]);
bool setAttribute(std::string const &key, Attribute value);
/** @}
*/

Expand Down
25 changes: 23 additions & 2 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,30 @@ class Attribute
template <typename U>
std::optional<U> getOptional() const;

private:
template <typename U>
std::variant<U, std::runtime_error> get_impl() const;
std::variant<U, std::runtime_error> getOrError() const;

/**
* Force this attribute into a vector type.
* If it is scalar, convert to a vector with a single element.
* If it is an array, convert it to a vector.
*
* @return On success, a new Attribute with underlying vector type.
* On failure, an error with a description of what went wrong
* (e.g. when the base type is bool).
*/
[[nodiscard]] std::variant<Attribute, std::runtime_error>
requireVector() const;
/**
* Force this attribute into a scalar type.
* If it is a vector attribute with a single entry, convert to a scalar.
*
* @return On success, a new Attribute with underlying scalar type.
* On failure, an error with a description of what went wrong
* (e.g. when a vector with size other than 1 was provided).
*/
[[nodiscard]] std::variant<Attribute, std::runtime_error>
requireScalar() const;
};

namespace detail
Expand Down
22 changes: 19 additions & 3 deletions include/openPMD/backend/BaseRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/backend/BaseRecordComponent.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <array>
#include <stdexcept>
Expand Down Expand Up @@ -179,6 +180,7 @@ template <typename T_elem>
class BaseRecord
: public Container<T_elem>
, public T_elem // T_RecordComponent
, internal::ScientificDefaults<BaseRecord<T_elem>>
{
public:
using T_RecordComponent = T_elem;
Expand All @@ -197,6 +199,8 @@ class BaseRecord
friend class internal::ScalarIterator;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
template <typename>
friend class internal::ScientificDefaults;

using Data_t =
internal::BaseRecordData<T_elem, typename T_RecordComponent::Data_t>;
Expand Down Expand Up @@ -362,9 +366,6 @@ class BaseRecord
*/
bool scalar() const;

protected:
void readBase();

private:
void flush(std::string const &, internal::FlushParams const &) final;
virtual void
Expand All @@ -381,6 +382,21 @@ namespace detail

template <typename BaseRecord>
void verifyNonscalar(BaseRecord *self);

template <typename T>
struct IsBaseRecord
{
constexpr static bool value = false;
};

template <typename T>
struct IsBaseRecord<BaseRecord<T>>
{
constexpr static bool value = true;
};

template <typename T>
constexpr bool IsBaseRecord_v = IsBaseRecord<T>::value;
} // namespace detail

template <typename T_elem>
Expand Down
9 changes: 9 additions & 0 deletions include/openPMD/backend/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "openPMD/Error.hpp"
#include "openPMD/IO/Access.hpp"
#include "openPMD/auxiliary/TypeTraits.hpp"
#include "openPMD/backend/Attributable.hpp"

#include <initializer_list>
Expand Down Expand Up @@ -343,5 +344,13 @@ namespace internal

~EraseStaleEntries();
};

template <typename T>
constexpr bool IsContainer_v = auxiliary::IsTemplateBaseOf_v<Container, T>;
template <typename T>
using AsContainer_t = auxiliary::AsTemplateBase_t<Container, T>;

static_assert(!IsContainer_v<int>);
static_assert(IsContainer_v<Container<Attributable>>);
} // namespace internal
} // namespace openPMD
Loading
Loading