Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #48 from simphony/upgrade-to-0.5.0
Browse files Browse the repository at this point in the history
Build against 0.5.0dev0 (master)
  • Loading branch information
stefanoborini committed Jan 16, 2017
2 parents 5e0fb05 + aeafc6d commit 2f26b20
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ python:
virtualenv:
system_site_packages: true
env:
- SIMPHONY_VERSION=0.4.0 PARAVIEW=paraview
- SIMPHONY_VERSION=0.4.0 PARAVIEW=paraviewopenfoam410
- SIMPHONY_VERSION=master PARAVIEW=paraview
- SIMPHONY_VERSION=master PARAVIEW=paraviewopenfoam410
matrix:
allow_failures:
- env: SIMPHONY_VERSION=master PARAVIEW=paraview
- env: SIMPHONY_VERSION=master PARAVIEW=paraviewopenfoam410
before_install:
- sudo sh -c "echo deb http://www.openfoam.org/download/ubuntu precise main > /etc/apt/sources.list.d/openfoam.list"
- sudo apt-get update -qq
Expand Down
6 changes: 6 additions & 0 deletions simphony_paraview/core/cuba_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def default_cuba_value(cuba):
"""
description = KEYWORDS[cuba.name]

if description.dtype is None:
message = 'property {!r} is currently ignored'
warnings.warn(message.format(cuba))
return

if description.shape == [1]:
if numpy.issubdtype(description.dtype, numpy.float):
return numpy.nan
Expand Down
17 changes: 9 additions & 8 deletions simphony_paraview/core/cuds2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy
from paraview import vtk
from simphony.core.cuba import CUBA
from simphony.cuds import ABCMesh, ABCParticles, ABCLattice
from simphony.cuds.primitive_cell import BravaisLattice

Expand Down Expand Up @@ -39,14 +40,14 @@ def _particles2poly_data(cuds):

point_data = poly_data.GetPointData()
data_collector = CUBADataAccumulator(container=point_data)
for index, particle in enumerate(cuds.iter_particles()):
for index, particle in enumerate(cuds.iter(item_type=CUBA.PARTICLE)):
particle2index[particle.uid] = index
points.InsertPoint(index, *particle.coordinates)
data_collector.append(particle.data)

cell_data = poly_data.GetCellData()
data_collector = CUBADataAccumulator(container=cell_data)
for bond in cuds.iter_bonds():
for bond in cuds.iter(item_type=CUBA.BOND):
lines.InsertNextCell(len(bond.particles))
for uuid in bond.particles:
lines.InsertCellPoint(particle2index[uuid])
Expand Down Expand Up @@ -80,7 +81,7 @@ def vector_length(vector):
indices = izip(x.ravel(), y.ravel(), z.ravel())
point_data = structured_points.GetPointData()
data_collector = CUBADataAccumulator(container=point_data)
for node in cuds.iter_nodes(indices):
for node in cuds.iter(indices):
data_collector.append(node.data)

return structured_points
Expand All @@ -94,7 +95,7 @@ def _lattice2poly_data(cuds):
# copy node data
point_data = poly_data.GetPointData()
data_collector = CUBADataAccumulator(container=point_data)
for node in cuds.iter_nodes():
for node in cuds.iter(item_type=CUBA.NODE):
points.InsertNextPoint(coordinates(node.index))
data_collector.append(node.data)

Expand All @@ -111,7 +112,7 @@ def _mesh2unstructured_grid(cuds):
points = vtk.vtkPoints()
point_data = unstructured_grid.GetPointData()
data_collector = CUBADataAccumulator(container=point_data)
for index, point in enumerate(cuds.iter_points()):
for index, point in enumerate(cuds.iter(item_type=CUBA.POINT)):
point2index[point.uid] = index
points.InsertNextPoint(*point.coordinates)
data_collector.append(point.data)
Expand All @@ -122,7 +123,7 @@ def _mesh2unstructured_grid(cuds):

# copy edges
mapping = points2edge()
for edge in cuds.iter_edges():
for edge in cuds.iter(item_type=CUBA.EDGE):
npoints = len(edge.points)
ids = vtk.vtkIdList()
for uid in edge.points:
Expand All @@ -132,7 +133,7 @@ def _mesh2unstructured_grid(cuds):

# copy faces
mapping = points2face()
for face in cuds.iter_faces():
for face in cuds.iter(item_type=CUBA.FACE):
npoints = len(face.points)
ids = vtk.vtkIdList()
for uid in face.points:
Expand All @@ -142,7 +143,7 @@ def _mesh2unstructured_grid(cuds):

# copy cells
mapping = points2cell()
for cell in cuds.iter_cells():
for cell in cuds.iter(item_type=CUBA.CELL):
npoints = len(cell.points)
ids = vtk.vtkIdList()
for uid in cell.points:
Expand Down
14 changes: 7 additions & 7 deletions simphony_paraview/core/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def work_on_nodes(nodes):
node.data[CUBA.TEMPERATURE] = prod(index)
yield node

lattice.update_nodes(work_on_nodes(lattice.iter_nodes()))
lattice.update(work_on_nodes(lattice.iter(item_type=CUBA.NODE)))
return lattice


Expand All @@ -39,26 +39,26 @@ def create_example_mesh():
mesh = Mesh('example')

# add points
uids = mesh.add_points(
uids = mesh.add(
Point(coordinates=point, data=DataContainer(TEMPERATURE=index))
for index, point in enumerate(points))

# add edges
mesh.add_edges(
mesh.add(
Edge(
points=[uids[index] for index in element],
data=DataContainer(TEMPERATURE=index))
for index, element in enumerate(edges))

# add faces
mesh.add_faces(
mesh.add(
Face(
points=[uids[index] for index in element],
data=DataContainer(TEMPERATURE=index))
for index, element in enumerate(faces))

# add cells
mesh.add_cells(
mesh.add(
Cell(
points=[uids[index] for index in element],
data=DataContainer(TEMPERATURE=index))
Expand All @@ -73,13 +73,13 @@ def create_example_particles():
temperature = array([10., 20., 30., 40.])

particles = Particles('test')
uids = particles.add_particles(
uids = particles.add(
Particle(
coordinates=point,
data=DataContainer(TEMPERATURE=temperature[index]))
for index, point in enumerate(points))

particles.add_bonds(
particles.add(
Bond(
particles=[uids[index] for index in indices],
data=DataContainer(TEMPERATURE=temperature[index]))
Expand Down
37 changes: 20 additions & 17 deletions simphony_paraview/core/tests/test_cuds2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def test_with_cuds_particles(self):
bond_temperature = [60., 80., 190.]

cuds = Particles('test')
particle_uids = cuds.add_particles(
particle_uids = cuds.add(
Particle(
coordinates=point,
data=DataContainer(
TEMPERATURE=point_temperature[index],
MASS=index))
for index, point in enumerate(points))
cuds.add_bonds(
cuds.add(
Bond(
particles=[particle_uids[uid] for uid in indices],
data=DataContainer(
Expand All @@ -61,7 +61,8 @@ def test_with_cuds_particles(self):
self.assertEqual(data_set.GetNumberOfPoints(), 4)

coordinates = [
particle.coordinates for particle in cuds.iter_particles()]
particle.coordinates for particle in cuds.iter(
item_type=CUBA.PARTICLE)]
vtk_points = [
data_set.GetPoint(index)
for index in range(len(particle_uids))]
Expand All @@ -84,8 +85,8 @@ def test_with_cuds_particles(self):

links = [[
particle.coordinates
for particle in cuds.iter_particles(bond.particles)]
for bond in cuds.iter_bonds()]
for particle in cuds.iter(bond.particles)]
for bond in cuds.iter(item_type=CUBA.BOND)]
vtk_lines = data_set.GetLines()
lines = [[
data_set.GetPoint(index) for index in line]
Expand Down Expand Up @@ -122,7 +123,7 @@ def test_source_from_a_xy_plane_rectangular_lattice(self):
point_data.GetArray(index).GetName():
vtk_to_numpy(point_data.GetArray(index))
for index in range(point_data.GetNumberOfArrays())}
for node in lattice.iter_nodes():
for node in lattice.iter(item_type=CUBA.NODE):
point_id = data_set.ComputePointId(node.index)
assert_array_equal(
lattice.get_coordinate(node.index),
Expand All @@ -147,7 +148,7 @@ def test_source_from_a_cubic_lattice(self):
point_data.GetArray(index).GetName():
vtk_to_numpy(point_data.GetArray(index))
for index in range(point_data.GetNumberOfArrays())}
for node in lattice.iter_nodes():
for node in lattice.iter(item_type=CUBA.NODE):
point_id = data_set.ComputePointId(node.index)
assert_array_equal(
lattice.get_coordinate(node.index),
Expand All @@ -173,7 +174,7 @@ def test_source_from_an_orthorhombic_lattice(self):
point_data.GetArray(index).GetName():
vtk_to_numpy(point_data.GetArray(index))
for index in range(point_data.GetNumberOfArrays())}
for node in lattice.iter_nodes():
for node in lattice.iter(item_type=CUBA.NODE):
point_id = data_set.ComputePointId(node.index)
assert_array_equal(
lattice.get_coordinate(node.index),
Expand All @@ -193,7 +194,7 @@ def test_source_from_a_xy_plane_hexagonal_lattice(self):
self.assertEqual(data_set.GetNumberOfPoints(), 5 * 4)

points = vtk_to_numpy(data_set.GetPoints().GetData())
for node in lattice.iter_nodes():
for node in lattice.iter(item_type=CUBA.NODE):
position = lattice.get_coordinate(node.index)
point_id = data_set.FindPoint(position)
assert_array_equal(
Expand All @@ -217,7 +218,7 @@ def test_with_cuds_mesh(self):
for index, point in enumerate(points)]

cuds = Mesh('test')
cuds.add_points(points)
cuds.add(points)

faces = [
Face(
Expand All @@ -234,9 +235,9 @@ def test_with_cuds_mesh(self):
points=[points[index].uid for index in cell],
data=DataContainer(TEMPERATURE=next(count)))
for cell in cells]
cuds.add_edges(edges)
cuds.add_faces(faces)
cuds.add_cells(cells)
cuds.add(edges)
cuds.add(faces)
cuds.add(cells)

# when
data_set = cuds2vtk(cuds=cuds)
Expand Down Expand Up @@ -265,15 +266,17 @@ def test_with_cuds_mesh(self):
# find the corresponding cell in the vtkCellArray and
# verify that they link to points that have the right coordinates.
for cell in itertools.chain(
cuds.iter_edges(), cuds.iter_faces(), cuds.iter_cells()):
cuds.iter(item_type=CUBA.EDGE),
cuds.iter(item_type=CUBA.FACE),
cuds.iter(item_type=CUBA.CELL)):
# The temperature value is also the index that the cells
# are expected to have in the vtkCellArray.
value = cell.data[CUBA.TEMPERATURE]
index = numpy.nonzero(vtk_to_numpy(temperature) == value)[0]
vtk_cell = data_set.GetCell(index)
ids = vtk_cell.GetPointIds()
for i, uid in enumerate(cell.points):
cell_point = cuds.get_point(uid)
cell_point = cuds.get(uid)
assert_array_equal(
data_set.GetPoint(ids.GetId(i)), cell_point.coordinates)

Expand All @@ -300,10 +303,10 @@ def test_with_empty_cuds_particles(self):
self.assertEqual(data_set.GetNumberOfCells(), 0)

def add_velocity(self, lattice):
nodes = [node for node in lattice.iter_nodes()]
nodes = [node for node in lattice.iter(item_type=CUBA.NODE)]
for node in nodes:
node.data[CUBA.VELOCITY] = node.index
lattice.update_nodes(nodes)
lattice.update(nodes)

def test_with_invalid_cuds(self):
# given
Expand Down

0 comments on commit 2f26b20

Please sign in to comment.