Hi. I prefer the
PyEVTK package. Its not as rich as the python-vtk package but it gets the job done nicely:
Lets say you have PySPH data in a directory in either npz or hdf format, say example_xxxx.hdf5 for example and each solution file has data for two particle arrays 'array1' and 'array2'
First, write a convenience function to load the arrays:
from pyevtk.hl import pointsToVTK
from pysph.solver.utils import load
def get_particles(iteration, array_name):
data = load('example_%01d.hdf5'%iteration)
return data['arrays'][array_name]
Now you can cycle through the iteration numbers and dump out the vtk files quite easily:
for iteration in range(...):
pa1 = get_particles(iteration, 'array1')
pa2 = get_particles(iteration, 'array2)
pointsToVTK('array1_%03d'%iteration, pa1.x, pa1.y, pa1.z, data={'rho':pa1.rho, 'velx':pa1.u...})
pointsToVTK('array2_%03d'%iteration, pa2.x, pa2.y, pa2.z, data={'rho':pa2.rho, 'velx':pa2.u...})
what you get is a vtu sequence for each array that can be loaded in to VisIT or Paraview
If you want to collate the data into one data-set, you can create a multi-block data set (but for now I can only do this via the python-vtk module):
import vtk
for iteration in range(...):
mb = vtk.vtkMultiBlockDataSet()
mb.SetNumberOfBlocks(2) # because we have two arrays
for i, array_name in enumerate['array1', 'array2']:
r = vtk.vtkXMLUnstructuredGridReader()
r.SetFileName('array1_%03d'%iteration)
r.Update()
data = r.GetOutput()
mb.SetBlock(i, data)
writer = vtk.vtkXMLMultiBlockDataWriter()
writer.SetDataModeToBinary()
writer.SetFileName('./sim_%03d.vtm'%iteration)
writer.SetInputData(mb)
writer.Write()
This will create a sequence of vtm files sim_xxx.vtm which again can be loaded into your favorite vis package. A caveat with this approach is that the files will be duplicated so you can add a line to delete the original vtu files.
This procedure works for parallel data too. First collate partition files into one multiblock data set per array and then collate the two multi-block files into one.
Hope this helps.
Kunal