Skip to content

Commit 07417b7

Browse files
committed
[WIP] put all recursive meshes in Iteration::meshes
Doesn't really work due to legacy definition of Iteration::meshes, maybe introduce sth like Iteration::all_meshes()
1 parent 2f620f9 commit 07417b7

3 files changed

Lines changed: 72 additions & 14 deletions

File tree

include/openPMD/CustomHierarchy.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,21 @@ class CustomHierarchy : public ConversibleContainer<CustomHierarchy>
228228
CustomHierarchy();
229229
CustomHierarchy(NoInit);
230230

231-
void read(internal::MeshesParticlesPath const &);
231+
inline void setData(std::shared_ptr<Data_t> data)
232+
{
233+
m_customHierarchyData = data;
234+
Container_t::setData(std::move(data));
235+
}
236+
237+
void read(
238+
internal::MeshesParticlesPath const &,
239+
Container<Mesh> meshes,
240+
Container<ParticleSpecies> particles);
232241
void read(
233242
internal::MeshesParticlesPath const &,
234-
std::vector<std::string> &currentPath);
243+
std::vector<std::string> &currentPath,
244+
Container<Mesh> meshes,
245+
Container<ParticleSpecies> particles);
235246

236247
void flush_internal(
237248
internal::FlushParams const &,

src/CustomHierarchy.cpp

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,45 @@ void CustomHierarchy::readParticleSpecies(
376376
}
377377
}
378378

379-
void CustomHierarchy::read(internal::MeshesParticlesPath const &mpp)
379+
void CustomHierarchy::read(
380+
internal::MeshesParticlesPath const &mpp,
381+
Container<Mesh> meshes,
382+
Container<ParticleSpecies> particles)
380383
{
381384
std::vector<std::string> currentPath;
382-
read(mpp, currentPath);
385+
read(mpp, currentPath, meshes, particles);
383386
}
384387

388+
namespace
389+
{
390+
template <typename T>
391+
void add_to_meshes_particles_view(
392+
std::vector<std::string> const &currentPath,
393+
std::string const &defaultMeshesParticlesPath,
394+
Container<T> &meshesOrParticles,
395+
std::string const &name,
396+
T &meshOrParticle)
397+
{
398+
if (currentPath.empty())
399+
{
400+
throw std::runtime_error(
401+
"Meshes or particles cannot be part of the root group.");
402+
}
403+
auto concatenatedName = concatWithSep(currentPath, "/");
404+
concatenatedName.append(1, '/').append(name);
405+
meshesOrParticles[concatenatedName] = meshOrParticle;
406+
if (concatenatedName == defaultMeshesParticlesPath + '/' + name)
407+
{
408+
meshesOrParticles[name] = meshOrParticle;
409+
}
410+
}
411+
} // namespace
412+
385413
void CustomHierarchy::read(
386414
internal::MeshesParticlesPath const &mpp,
387-
std::vector<std::string> &currentPath)
415+
std::vector<std::string> &currentPath,
416+
Container<Mesh> meshes,
417+
Container<ParticleSpecies> particles)
388418
{
389419
/*
390420
* Convention for CustomHierarchy::flush and CustomHierarchy::read:
@@ -416,7 +446,7 @@ void CustomHierarchy::read(
416446
currentPath.emplace_back(path);
417447
try
418448
{
419-
subpath.read(mpp, currentPath);
449+
subpath.read(mpp, currentPath, meshes, particles);
420450
}
421451
catch (error::ReadError const &err)
422452
{
@@ -442,6 +472,12 @@ void CustomHierarchy::read(
442472
try
443473
{
444474
readNonscalarMesh(meshesMap, path);
475+
add_to_meshes_particles_view(
476+
currentPath,
477+
mpp.m_defaultMeshesPath,
478+
meshes,
479+
path,
480+
meshesMap[path]);
445481
}
446482
catch (error::ReadError const &err)
447483
{
@@ -451,12 +487,19 @@ void CustomHierarchy::read(
451487
<< err.what() << std::endl;
452488
meshesMap.forget(path);
453489
}
490+
454491
break;
455492
}
456493
case internal::ContainedType::Particle: {
457494
try
458495
{
459496
readParticleSpecies(particlesMap, path);
497+
add_to_meshes_particles_view(
498+
currentPath,
499+
mpp.m_defaultParticlesPath,
500+
particles,
501+
path,
502+
particlesMap[path]);
460503
}
461504
catch (error::ReadError const &err)
462505
{
@@ -514,12 +557,18 @@ void CustomHierarchy::read(
514557
try
515558
{
516559
readScalarMesh(meshesMap, path);
560+
add_to_meshes_particles_view(
561+
currentPath,
562+
mpp.m_defaultMeshesPath,
563+
meshes,
564+
path,
565+
meshesMap[path]);
517566
}
518567
catch (error::ReadError const &err)
519568
{
520-
std::cerr << "Cannot read scalar mesh at location '"
569+
std::cerr << "Cannot read mesh at location '"
521570
<< myPath().openPMDPath() << "/" << path
522-
<< "' and will skip it due to read error:\n"
571+
<< "' and will skip them due to read error:\n"
523572
<< err.what() << std::endl;
524573
meshesMap.forget(path);
525574
}

src/Iteration.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ void Iteration::sync_meshes_and_particles_from_alias_to_subgroups(
411411
{
412412
if (auxiliary::contains(name, '/'))
413413
{
414-
throw std::runtime_error(
415-
"Unimplemented: Multi-level paths in "
416-
"Iteration::meshes/Iteration::particles");
414+
// throw std::runtime_error(
415+
// "Unimplemented: Multi-level paths in "
416+
// "Iteration::meshes/Iteration::particles");
417417
}
418418
if (auto it = container.find(name); it != container.end())
419419
{
@@ -609,9 +609,7 @@ void Iteration::read_impl(std::string const &groupPath)
609609
// hasMeshes <-> meshesPath is defined
610610

611611
internal::MeshesParticlesPath mpp(s.meshesPaths(), s.particlesPaths());
612-
CustomHierarchy::read(mpp);
613-
614-
sync_meshes_and_particles_from_subgroups_to_alias(mpp);
612+
CustomHierarchy::read(mpp, meshes, particles);
615613

616614
#ifdef openPMD_USE_INVASIVE_TESTS
617615
if (containsAttribute("__openPMD_internal_fail"))

0 commit comments

Comments
 (0)