Skip to content

Commit

Permalink
[wip] Set meshesPath and particlesPath as list of regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jun 16, 2023
1 parent 1aed59a commit 4fa197e
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 147 deletions.
48 changes: 36 additions & 12 deletions include/openPMD/CustomHierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,44 @@
#include "openPMD/backend/Writable.hpp"

#include <iostream>
#include <set>
#include <regex>
#include <string>
#include <type_traits>
#include <vector>

namespace openPMD
{
class Series;

class CustomHierarchy;
namespace internal
{
enum class ContainedType
{
Group,
Mesh,
Particle
};
struct MeshesParticlesPath
{
std::optional<std::string> meshesPath;
std::optional<std::string> particlesPath;
[[nodiscard]] bool ignore(std::string const &name) const;
[[nodiscard]] inline bool hasMeshes() const noexcept
{
return meshesPath.has_value();
}
[[nodiscard]] inline bool hasParticles() const noexcept
{
return particlesPath.has_value();
}
std::map<std::string, std::regex> meshesPath;
std::map<std::string, std::regex> particlesPath;

explicit MeshesParticlesPath() = default;
MeshesParticlesPath(
std::vector<std::string> const &meshes,
std::vector<std::string> const &particles);
MeshesParticlesPath(Series const &);

[[nodiscard]] ContainedType determineType(
std::vector<std::string> const &path,
std::string const &name) const;
[[nodiscard]] bool isParticle(
std::vector<std::string> const &path,
std::string const &name) const;
[[nodiscard]] bool isMesh(
std::vector<std::string> const &path,
std::string const &name) const;
};

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

void flush_internal(
internal::FlushParams const &,
internal::MeshesParticlesPath &,
std::vector<std::string> currentPath);

protected:
CustomHierarchy();
CustomHierarchy(NoInit);
Expand All @@ -97,6 +118,9 @@ class CustomHierarchy : public Container<CustomHierarchy>
}

void read(internal::MeshesParticlesPath const &);
void read(
internal::MeshesParticlesPath const &,
std::vector<std::string> &currentPath);

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

Expand Down
6 changes: 4 additions & 2 deletions include/openPMD/Series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class Series : public Attributable
* <CODE>basePath</CODE>.
*/
std::string meshesPath() const;
std::vector<std::string> meshesPaths() const;
/** Set the path to <A
* HREF="https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#mesh-based-records">mesh
* records</A>, relative(!) to <CODE>basePath</CODE>.
Expand All @@ -305,13 +306,15 @@ class Series : public Attributable
* @return Reference to modified series.
*/
Series &setMeshesPath(std::string const &meshesPath);
Series &setMeshesPath(std::vector<std::string> const &meshesPath);

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

/**
* @throw no_such_attribute_error If optional attribute is not present.
Expand Down Expand Up @@ -630,8 +634,6 @@ OPENPMD_private
iterations_iterator end,
internal::FlushParams flushParams,
bool flushIOHandler = true);
void flushMeshesPath();
void flushParticlesPath();
void readFileBased();
void readOneIterationFileBased(std::string const &filePath);
/**
Expand Down
19 changes: 19 additions & 0 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ namespace detail
"getCast: no scalar to vector conversion possible.")};
}
}
// conversion cast: turn a 1-element vector into a single value
else if constexpr (auxiliary::IsVector_v<T>)
{
if constexpr (std::is_convertible_v<typename T::value_type, U>)
{
if (pv->size() != 1)
{
return {std::runtime_error(
"getCast: vector to scalar conversion requires "
"single-element vectors")};
}
return {U(*pv->begin())};
}
else
{
return {std::runtime_error(
"getCast: no vector to scalar conversion possible.")};
}
}
else
{
return {std::runtime_error("getCast: no cast possible.")};
Expand Down
Loading

0 comments on commit 4fa197e

Please sign in to comment.