SimPhoNy¶
Paraview tools are available in the simphony library through the
visualisation plug-in named paraview_tools
.
e.g:
from simphony.visualisation import paraview_tools
Visualizing CUDS¶
The show()
function is available to
visualise any top level CUDS container. The function will open a
window containing a 3D view of the dataset. Interaction is supported
using the mouse and keyboard:
keyboard: |
|
---|---|
mouse: |
|
Mesh example
from numpy import array
from simphony.cuds import Mesh, Point, Cell, Edge, Face
from simphony.core.data_container import DataContainer
from simphony.core.cuba import CUBA
points = array([
[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1],
[2, 0, 0], [3, 0, 0], [3, 1, 0], [2, 1, 0],
[2, 0, 1], [3, 0, 1], [3, 1, 1], [2, 1, 1]],
'f')
cells = [
[0, 1, 2, 3], # tetra
[4, 5, 6, 7, 8, 9, 10, 11]] # hex
faces = [[2, 7, 11]]
edges = [[1, 4], [3, 8]]
mesh = Mesh('example')
# add points
uids = mesh.add_points(
Point(coordinates=point, data=DataContainer(TEMPERATURE=index))
for index, point in enumerate(points))
# add edges
edge_uids = mesh.add_edges(
Edge(points=[uids[index] for index in element])
for index, element in enumerate(edges))
# add faces
face_uids = mesh.add_faces(
Face(points=[uids[index] for index in element])
for index, element in enumerate(faces))
# add cells
cell_uids = mesh.add_cells(
Cell(points=[uids[index] for index in element])
for index, element in enumerate(cells))
if __name__ == '__main__':
from simphony.visualisation import paraview_tools
# Visualise the Mesh object
paraview_tools.show(mesh, select=(CUBA.TEMPERATURE, 'points'))
Lattice example
import numpy
from simphony.cuds.lattice import make_cubic_lattice
from simphony.core.cuba import CUBA
lattice = make_cubic_lattice('test', 0.1, (50, 10, 120))
def set_temperature(nodes):
for node in nodes:
index = numpy.array(node.index) + 1.0
node.data[CUBA.TEMPERATURE] = numpy.prod(index)
yield node
lattice.update_nodes(set_temperature(lattice.iter_nodes()))
if __name__ == '__main__':
from simphony.visualisation import paraview_tools
# Visualise the Lattice object
paraview_tools.show(lattice, select=(CUBA.TEMPERATURE, 'nodes'))
Particles example
from numpy import array
from simphony.cuds import Particles, Particle, Bond
from simphony.core.data_container import DataContainer
from simphony.core.cuba import CUBA
points = array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], 'f')
bonds = array([[0, 1], [0, 3], [1, 3, 2]])
temperature = array([10., 20., 30., 40.])
particles = Particles('test')
uids = particles.add_particles(
Particle(
coordinates=point,
data=DataContainer(TEMPERATURE=temperature[index]))
for index, point in enumerate(points))
particles.add_bonds(
Bond(particles=[uids[index] for index in indices])
for indices in bonds)
if __name__ == '__main__':
from simphony.visualisation import paraview_tools
# Visualise the Particles object
paraview_tools.show(particles, select=(CUBA.TEMPERATURE, 'particles'))