Skip to content

Commit

Permalink
Merge pull request #5 from openPMD/particleBoundary
Browse files Browse the repository at this point in the history
Move Particle Boundaries
  • Loading branch information
ax3l authored Nov 8, 2018
2 parents 98648c1 + f1fc4e4 commit bd1f216
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
4 changes: 3 additions & 1 deletion openpmd_updater/Updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"""
import packaging.version
from openpmd_updater.backends.HDF5 import HDF5
from openpmd_updater.transforms.v2_0_0 import DataOrder, ExtensionString, Version
from openpmd_updater.transforms.v2_0_0 import DataOrder, \
ExtensionString, Version, ParticleBoundary


class Updater(object):
Expand All @@ -29,6 +30,7 @@ def __init__(self, filename, verbose=False):
self.updates = {
"2.0.0" : [
DataOrder.DataOrder, # must be before move of particleBoundary
ParticleBoundary.ParticleBoundary,
ExtensionString.ExtensionString,
Version.Version # must be last
]
Expand Down
63 changes: 63 additions & 0 deletions openpmd_updater/transforms/v2_0_0/ParticleBoundary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
This file is part of the openPMD-updater.
Copyright 2018 openPMD contributors
Authors: Axel Huebl, Remi Lehe
License: ISC
"""

from openpmd_updater.transforms.ITransform import ITransform
import numpy as np


class ParticleBoundary(ITransform):
"""
Moves the `particleBoundary` attribute from the mesh records
to the species records
openPMD standard: 1.*.* -> 2.0.0
Related openPMD-standard issues:
https://github.com/openPMD/openPMD-standard/issues/105
"""

"""Name and description of the transformation"""
name = "particleBoundary", \
"move the particleBoundary attribute from the mesh records to the species records"

"""Minimum openPMD standard version that is supported by this transformation"""
min_version = "1.0.0"

"""openPMD standard version is fulfulled by this transformation"""
to_version = "2.0.0"

def __init__(self, backend):
"""Open a file"""
self.fb = backend

def transform(self, in_place=True):
"""Perform transformation"""
if not in_place:
raise NotImplementedError("Only in-place transformation implemented!")

self.fb.cd(None)
basePath = "/data/" # fixed in openPMD v1
meshes_path = self.fb.get_attr("meshesPath").decode()
particles_path = self.fb.get_attr("particlesPath").decode()
iterations = self.fb.list_groups("/data/")

for it in iterations:
# Get the old particle_boundary attribute, from the mesh level
abs_meshes_path = "/data/" + str(it) + "/" + meshes_path
particle_boundary = self.fb.get_attr("particleBoundary", abs_meshes_path)

# Go through the list of species, and set this attribute
# at the species level
abs_particle_path = "/data/" + str(it) + "/" + particles_path
all_species = self.fb.list_groups(abs_particle_path)
self.fb.cd(abs_particle_path)
for species in all_species:
self.fb.add_attr("particleBoundary", particle_boundary, species)

# Delete the old particle_boundary attribute
self.fb.del_attr("particleBoundary", abs_meshes_path)

0 comments on commit bd1f216

Please sign in to comment.