PySPH and Paraview,

366 views
Skip to first unread message

Ionut Predoiu

unread,
Dec 13, 2016, 9:17:42 AM12/13/16
to pysph-users
Good afternoon,

It is some possibility to be use Paraview as post-processor for results obtained with PySPH ?

Somebody from community try this possibility ? What should be change in results files to can be view the results with Paraview software ?

I waiting with higher interest your comments with opinion related to subject !

Keep in touch.

Prabhu Ramachandran

unread,
Dec 14, 2016, 1:15:28 PM12/14/16
to pysph...@googlegroups.com
On 12/13/16 7:47 PM, Ionut Predoiu wrote:
> Good afternoon,
>
> It is some possibility to be use*Paraview* as post-processor for results
> obtained with *PySPH* ?
>
> Somebody from community try this possibility ? What should be change in results
> files to can be view the results with *Paraview* software ?

Yes, you should be able to do this quite easily. You will need either Mayavi
installed or must have pyvisfile (https://github.com/inducer/pyvisfile)
installed. Pyvisfile is relatively easy to install either via:

pip install pyvisfile

or

pip install git+https://github.com/inducer/pyvisfile.git

Once you have either Mayavi or pyvisfile you should just be able to run the
following:

$ pysph dump_vtk -h

See the options you have and use it appropriately. Once you have VTK files
dumped you can use Paraview easily.

cheers,
Prabhu

Ionut Predoiu

unread,
Dec 14, 2016, 2:20:51 PM12/14/16
to pysph-users
Fist of all, I want to thank you for answer. 
I will proceed based on your recommendation.

Thank you for support.
Keep in touch.

kunalp

unread,
Dec 14, 2016, 6:25:45 PM12/14/16
to pysph-users
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



Prabhu Ramachandran

unread,
Dec 15, 2016, 12:33:47 PM12/15/16
to pysph...@googlegroups.com
On 12/15/16 4:55 AM, kunalp wrote:
>
>
> On Tuesday, 13 December 2016 16:17:42 UTC+2, Ionut Predoiu wrote:
>
> Good afternoon,
>
> It is some possibility to be use*Paraview* as post-processor for results
> obtained with *PySPH* ?
>
> Somebody from community try this possibility ? What should be change in
> results files to can be view the results with *Paraview* software ?
>
> I waiting with higher interest your comments with opinion related to subject !
>
> Keep in touch.
>
>
> Hi. I prefer the PyEVTK <http://PyEVTK 1.0.0>package. Its not as rich as the
> python-vtk package but it gets the job done nicely:

Cool, I'll add support for this when I get time unless someone beats me to it.
It should be very easy to add this.

> 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:

You could also do this:

from pysph.solver.utils import iter_output, get_files

files = get_files(dirname='elliptical_drop_output')
for solver_data, arrays in iter_output(files):
# do whatever.

arrays is a dictionary of particle arrays keyed on the name of the array.

cheers,
Prabhu

Ionut Predoiu

unread,
Dec 30, 2016, 12:10:16 AM12/30/16
to pysph-users
Good morning,

Thank you for this complementary information.
I will try also this.

Kindly regards.

Happy New Year 2017 !!!



On Tuesday, December 13, 2016 at 4:17:42 PM UTC+2, Ionut Predoiu wrote:
Reply all
Reply to author
Forward
0 new messages