diff --git a/simphony/io/h5_cuds.py b/simphony/io/h5_cuds.py index 2cd6b09e..0e862b8b 100644 --- a/simphony/io/h5_cuds.py +++ b/simphony/io/h5_cuds.py @@ -314,7 +314,7 @@ def _add_mesh(self, mesh, cuba_keys): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUDSItem.EDGE]}) - h5_mesh.add_points([item]) + h5_mesh.add_edges([item]) for item in mesh.iter_faces(): item.data = DataContainer( diff --git a/simphony/io/tests/test_h5_cuds.py b/simphony/io/tests/test_h5_cuds.py index c2b7f925..71a0c777 100644 --- a/simphony/io/tests/test_h5_cuds.py +++ b/simphony/io/tests/test_h5_cuds.py @@ -12,7 +12,7 @@ from simphony.io.h5_mesh import H5Mesh from simphony.io.h5_particles import H5Particles from simphony.io.h5_lattice import H5Lattice -from simphony.cuds import Mesh, Particles +from simphony.cuds import Mesh, Particles, Point, Edge, Face, Cell from simphony.cuds.lattice import make_cubic_lattice from simphony.testing.abc_check_engine import ( @@ -187,13 +187,25 @@ def test_add_get_dataset_with_cuba_keys_argument(self): expected = self.create_dataset(name='test') # Add some CUBA data - for point in items: + for point in [p for p in items if isinstance(p, Point)]: point.data = DataContainer({CUBA.VELOCITY: [1, 0, 0]}) expected.add_points([point]) point.data = DataContainer( {CUBA.VELOCITY: [1, 0, 0], CUBA.MASS: 1}) reference.add_points([point]) + for edge in [e for e in items if isinstance(e, Edge)]: + expected.add_edges([edge]) + reference.add_edges([edge]) + + for face in [f for f in items if isinstance(f, Face)]: + expected.add_faces([face]) + reference.add_faces([face]) + + for cell in [c for c in items if isinstance(c, Cell)]: + expected.add_cells([cell]) + reference.add_cells([cell]) + # Store reference dataset along with its data engine.add_dataset(reference, {CUDSItem.POINT: [CUBA.VELOCITY]}) diff --git a/simphony/testing/abc_check_engine.py b/simphony/testing/abc_check_engine.py index ae968a2c..63c6260e 100644 --- a/simphony/testing/abc_check_engine.py +++ b/simphony/testing/abc_check_engine.py @@ -7,10 +7,21 @@ from simphony.core.cuba import CUBA from simphony.cuds.particles import Particle, Particles -from simphony.cuds.mesh import Point, Mesh +from simphony.cuds.mesh import Edge, Face, Cell, Point, Mesh from simphony.cuds.lattice import make_cubic_lattice +def grouper(iterable, group_size): + """Given an iterable, returns groups of size group_size. + Excess entries are not included. + + >>> grouper('abcdefg', 3) + [('a', 'b', 'c'), ('d', 'e', 'f')] + """ + iters = [iter(iterable)]*group_size + return zip(*iters) + + class CheckEngine(object): __metaclass__ = abc.ABCMeta @@ -263,9 +274,24 @@ def create_dataset_items(self): """ Create and return a list of items """ items = [] + point_uids = [] for i in xrange(10): - items.append( - Point((1.1*i, 2.2*i, 3.3*i), uid=uuid.uuid4())) + point = Point((1.1*i, 2.2*i, 3.3*i), uid=uuid.uuid4()) + items.append(point) + point_uids.append(point.uid) + + for edge_points in grouper(point_uids, 2): + edge = Edge(edge_points, uid=uuid.uuid4()) + items.append(edge) + + for face_points in grouper(point_uids, 4): + face = Face(face_points, uid=uuid.uuid4()) + items.append(face) + + for cell_points in grouper(point_uids, 8): + cell = Cell(cell_points, uid=uuid.uuid4()) + items.append(cell) + return items