Skip to content

Commit e530733

Browse files
committed
[wip] Set meshesPath and particlesPath as list of regexes
1 parent 4aea6d0 commit e530733

8 files changed

Lines changed: 390 additions & 147 deletions

File tree

include/openPMD/CustomHierarchy.hpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,44 @@
2828
#include "openPMD/backend/Writable.hpp"
2929

3030
#include <iostream>
31-
#include <set>
31+
#include <regex>
3232
#include <string>
3333
#include <type_traits>
34+
#include <vector>
3435

3536
namespace openPMD
3637
{
38+
class Series;
39+
3740
class CustomHierarchy;
3841
namespace internal
3942
{
43+
enum class ContainedType
44+
{
45+
Group,
46+
Mesh,
47+
Particle
48+
};
4049
struct MeshesParticlesPath
4150
{
42-
std::optional<std::string> meshesPath;
43-
std::optional<std::string> particlesPath;
44-
[[nodiscard]] bool ignore(std::string const &name) const;
45-
[[nodiscard]] inline bool hasMeshes() const noexcept
46-
{
47-
return meshesPath.has_value();
48-
}
49-
[[nodiscard]] inline bool hasParticles() const noexcept
50-
{
51-
return particlesPath.has_value();
52-
}
51+
std::map<std::string, std::regex> meshesPath;
52+
std::map<std::string, std::regex> particlesPath;
53+
54+
explicit MeshesParticlesPath() = default;
55+
MeshesParticlesPath(
56+
std::vector<std::string> const &meshes,
57+
std::vector<std::string> const &particles);
58+
MeshesParticlesPath(Series const &);
59+
60+
[[nodiscard]] ContainedType determineType(
61+
std::vector<std::string> const &path,
62+
std::string const &name) const;
63+
[[nodiscard]] bool isParticle(
64+
std::vector<std::string> const &path,
65+
std::string const &name) const;
66+
[[nodiscard]] bool isMesh(
67+
std::vector<std::string> const &path,
68+
std::string const &name) const;
5369
};
5470

5571
struct CustomHierarchyData : ContainerData<CustomHierarchy>
@@ -86,6 +102,11 @@ class CustomHierarchy : public Container<CustomHierarchy>
86102
void readMeshes(std::string const &meshesPath);
87103
void readParticles(std::string const &particlesPath);
88104

105+
void flush_internal(
106+
internal::FlushParams const &,
107+
internal::MeshesParticlesPath &,
108+
std::vector<std::string> currentPath);
109+
89110
protected:
90111
CustomHierarchy();
91112
CustomHierarchy(NoInit);
@@ -97,6 +118,9 @@ class CustomHierarchy : public Container<CustomHierarchy>
97118
}
98119

99120
void read(internal::MeshesParticlesPath const &);
121+
void read(
122+
internal::MeshesParticlesPath const &,
123+
std::vector<std::string> &currentPath);
100124

101125
void flush(std::string const &path, internal::FlushParams const &) override;
102126

include/openPMD/Series.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ class Series : public Attributable
295295
* <CODE>basePath</CODE>.
296296
*/
297297
std::string meshesPath() const;
298+
std::vector<std::string> meshesPaths() const;
298299
/** Set the path to <A
299300
* HREF="https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#mesh-based-records">mesh
300301
* records</A>, relative(!) to <CODE>basePath</CODE>.
@@ -305,13 +306,15 @@ class Series : public Attributable
305306
* @return Reference to modified series.
306307
*/
307308
Series &setMeshesPath(std::string const &meshesPath);
309+
Series &setMeshesPath(std::vector<std::string> const &meshesPath);
308310

309311
/**
310312
* @throw no_such_attribute_error If optional attribute is not present.
311313
* @return String representing the path to particle species, relative(!) to
312314
* <CODE>basePath</CODE>.
313315
*/
314316
std::string particlesPath() const;
317+
std::vector<std::string> particlesPaths() const;
315318
/** Set the path to groups for each <A
316319
* HREF="https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#particle-records">particle
317320
* species</A>, relative(!) to <CODE>basePath</CODE>.
@@ -322,6 +325,7 @@ class Series : public Attributable
322325
* @return Reference to modified series.
323326
*/
324327
Series &setParticlesPath(std::string const &particlesPath);
328+
Series &setParticlesPath(std::vector<std::string> const &particlesPath);
325329

326330
/**
327331
* @throw no_such_attribute_error If optional attribute is not present.
@@ -630,8 +634,6 @@ OPENPMD_private
630634
iterations_iterator end,
631635
internal::FlushParams flushParams,
632636
bool flushIOHandler = true);
633-
void flushMeshesPath();
634-
void flushParticlesPath();
635637
void readFileBased();
636638
void readOneIterationFileBased(std::string const &filePath);
637639
/**

include/openPMD/backend/Attribute.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,25 @@ namespace detail
229229
"getCast: no scalar to vector conversion possible.")};
230230
}
231231
}
232+
// conversion cast: turn a 1-element vector into a single value
233+
else if constexpr (auxiliary::IsVector_v<T>)
234+
{
235+
if constexpr (std::is_convertible_v<typename T::value_type, U>)
236+
{
237+
if (pv->size() != 1)
238+
{
239+
return {std::runtime_error(
240+
"getCast: vector to scalar conversion requires "
241+
"single-element vectors")};
242+
}
243+
return {U(*pv->begin())};
244+
}
245+
else
246+
{
247+
return {std::runtime_error(
248+
"getCast: no vector to scalar conversion possible.")};
249+
}
250+
}
232251
else
233252
{
234253
return {std::runtime_error("getCast: no cast possible.")};

0 commit comments

Comments
 (0)