Skip to content

Commit 99a05ee

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 80da577 commit 99a05ee

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:
@@ -418,7 +448,7 @@ void CustomHierarchy::read(
418448
currentPath.emplace_back(path);
419449
try
420450
{
421-
subpath.read(mpp, currentPath);
451+
subpath.read(mpp, currentPath, meshes, particles);
422452
}
423453
catch (error::ReadError const &err)
424454
{
@@ -444,6 +474,12 @@ void CustomHierarchy::read(
444474
try
445475
{
446476
readNonscalarMesh(meshesMap, path);
477+
add_to_meshes_particles_view(
478+
currentPath,
479+
mpp.m_defaultMeshesPath,
480+
meshes,
481+
path,
482+
meshesMap[path]);
447483
}
448484
catch (error::ReadError const &err)
449485
{
@@ -453,12 +489,19 @@ void CustomHierarchy::read(
453489
<< err.what() << std::endl;
454490
meshesMap.forget(path);
455491
}
492+
456493
break;
457494
}
458495
case internal::ContainedType::Particle: {
459496
try
460497
{
461498
readParticleSpecies(particlesMap, path);
499+
add_to_meshes_particles_view(
500+
currentPath,
501+
mpp.m_defaultParticlesPath,
502+
particles,
503+
path,
504+
particlesMap[path]);
462505
}
463506
catch (error::ReadError const &err)
464507
{
@@ -516,12 +559,18 @@ void CustomHierarchy::read(
516559
try
517560
{
518561
readScalarMesh(meshesMap, path);
562+
add_to_meshes_particles_view(
563+
currentPath,
564+
mpp.m_defaultMeshesPath,
565+
meshes,
566+
path,
567+
meshesMap[path]);
519568
}
520569
catch (error::ReadError const &err)
521570
{
522-
std::cerr << "Cannot read scalar mesh at location '"
571+
std::cerr << "Cannot read mesh at location '"
523572
<< myPath().openPMDPath() << "/" << path
524-
<< "' and will skip it due to read error:\n"
573+
<< "' and will skip them due to read error:\n"
525574
<< err.what() << std::endl;
526575
meshesMap.forget(path);
527576
}

src/Iteration.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ void Iteration::sync_meshes_and_particles_from_alias_to_subgroups(
422422
{
423423
if (auxiliary::contains(name, '/'))
424424
{
425-
throw std::runtime_error(
426-
"Unimplemented: Multi-level paths in "
427-
"Iteration::meshes/Iteration::particles");
425+
// throw std::runtime_error(
426+
// "Unimplemented: Multi-level paths in "
427+
// "Iteration::meshes/Iteration::particles");
428428
}
429429
if (auto it = container.find(name); it != container.end())
430430
{
@@ -637,9 +637,7 @@ void Iteration::read_impl(std::string const &groupPath)
637637
// hasMeshes <-> meshesPath is defined
638638

639639
internal::MeshesParticlesPath mpp(s.meshesPaths(), s.particlesPaths());
640-
CustomHierarchy::read(mpp);
641-
642-
sync_meshes_and_particles_from_subgroups_to_alias(mpp);
640+
CustomHierarchy::read(mpp, meshes, particles);
643641

644642
#ifdef openPMD_USE_INVASIVE_TESTS
645643
if (containsAttribute("__openPMD_internal_fail"))

0 commit comments

Comments
 (0)