Skip to content

Commit

Permalink
[WIP] put all recursive meshes in Iteration::meshes
Browse files Browse the repository at this point in the history
Doesn't really work due to legacy definition of Iteration::meshes, maybe
introduce sth like Iteration::all_meshes()
  • Loading branch information
franzpoeschel committed Nov 7, 2024
1 parent 20f2cd5 commit 00ec21e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 14 deletions.
15 changes: 13 additions & 2 deletions include/openPMD/CustomHierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,21 @@ class CustomHierarchy : public ConversibleContainer<CustomHierarchy>
CustomHierarchy();
CustomHierarchy(NoInit);

void read(internal::MeshesParticlesPath const &);
inline void setData(std::shared_ptr<Data_t> data)
{
m_customHierarchyData = data;
Container_t::setData(std::move(data));
}

void read(
internal::MeshesParticlesPath const &,
Container<Mesh> meshes,
Container<ParticleSpecies> particles);
void read(
internal::MeshesParticlesPath const &,
std::vector<std::string> &currentPath);
std::vector<std::string> &currentPath,
Container<Mesh> meshes,
Container<ParticleSpecies> particles);

void flush_internal(
internal::FlushParams const &,
Expand Down
61 changes: 55 additions & 6 deletions src/CustomHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,45 @@ void CustomHierarchy::readParticleSpecies(
}
}

void CustomHierarchy::read(internal::MeshesParticlesPath const &mpp)
void CustomHierarchy::read(
internal::MeshesParticlesPath const &mpp,
Container<Mesh> meshes,
Container<ParticleSpecies> particles)
{
std::vector<std::string> currentPath;
read(mpp, currentPath);
read(mpp, currentPath, meshes, particles);
}

namespace
{
template <typename T>
void add_to_meshes_particles_view(
std::vector<std::string> const &currentPath,
std::string const &defaultMeshesParticlesPath,
Container<T> &meshesOrParticles,
std::string const &name,
T &meshOrParticle)
{
if (currentPath.empty())
{
throw std::runtime_error(
"Meshes or particles cannot be part of the root group.");
}
auto concatenatedName = concatWithSep(currentPath, "/");
concatenatedName.append(1, '/').append(name);
meshesOrParticles[concatenatedName] = meshOrParticle;
if (concatenatedName == defaultMeshesParticlesPath + '/' + name)
{
meshesOrParticles[name] = meshOrParticle;
}
}
} // namespace

void CustomHierarchy::read(
internal::MeshesParticlesPath const &mpp,
std::vector<std::string> &currentPath)
std::vector<std::string> &currentPath,
Container<Mesh> meshes,
Container<ParticleSpecies> particles)
{
/*
* Convention for CustomHierarchy::flush and CustomHierarchy::read:
Expand Down Expand Up @@ -416,7 +446,7 @@ void CustomHierarchy::read(
currentPath.emplace_back(path);
try
{
subpath.read(mpp, currentPath);
subpath.read(mpp, currentPath, meshes, particles);
}
catch (error::ReadError const &err)
{
Expand All @@ -442,6 +472,12 @@ void CustomHierarchy::read(
try
{
readNonscalarMesh(meshesMap, path);
add_to_meshes_particles_view(
currentPath,
mpp.m_defaultMeshesPath,
meshes,
path,
meshesMap[path]);
}
catch (error::ReadError const &err)
{
Expand All @@ -451,12 +487,19 @@ void CustomHierarchy::read(
<< err.what() << std::endl;
meshesMap.forget(path);
}

break;
}
case internal::ContainedType::Particle: {
try
{
readParticleSpecies(particlesMap, path);
add_to_meshes_particles_view(
currentPath,
mpp.m_defaultParticlesPath,
particles,
path,
particlesMap[path]);
}
catch (error::ReadError const &err)
{
Expand Down Expand Up @@ -514,12 +557,18 @@ void CustomHierarchy::read(
try
{
readScalarMesh(meshesMap, path);
add_to_meshes_particles_view(
currentPath,
mpp.m_defaultMeshesPath,
meshes,
path,
meshesMap[path]);
}
catch (error::ReadError const &err)
{
std::cerr << "Cannot read scalar mesh at location '"
std::cerr << "Cannot read mesh at location '"
<< myPath().openPMDPath() << "/" << path
<< "' and will skip it due to read error:\n"
<< "' and will skip them due to read error:\n"
<< err.what() << std::endl;
meshesMap.forget(path);
}
Expand Down
10 changes: 4 additions & 6 deletions src/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ void Iteration::sync_meshes_and_particles_from_alias_to_subgroups(
{
if (auxiliary::contains(name, '/'))
{
throw std::runtime_error(
"Unimplemented: Multi-level paths in "
"Iteration::meshes/Iteration::particles");
// throw std::runtime_error(
// "Unimplemented: Multi-level paths in "
// "Iteration::meshes/Iteration::particles");
}
if (auto it = container.find(name); it != container.end())
{
Expand Down Expand Up @@ -570,9 +570,7 @@ void Iteration::read_impl(std::string const &groupPath)
// hasMeshes <-> meshesPath is defined

internal::MeshesParticlesPath mpp(s.meshesPaths(), s.particlesPaths());
CustomHierarchy::read(mpp);

sync_meshes_and_particles_from_subgroups_to_alias(mpp);
CustomHierarchy::read(mpp, meshes, particles);

#ifdef openPMD_USE_INVASIVE_TESTS
if (containsAttribute("__openPMD_internal_fail"))
Expand Down

0 comments on commit 00ec21e

Please sign in to comment.