»

Jun 11

Python and VTK to get Vorticity

After a few days of understanding the VTK pipeline, I’ve finally figured out how to generate a vorticity cube from velocity cutout from the JHU Turbuelence database. ┬áSo here is the code!

h5file = h5py.File(“temp.h5”, ‘r’)

vtkdata = numpy_support.numpy_to_vtk(h5file[“u00000”][:,:,:,:].ravel(), deep=True, array_type=vtk.VTK_FLOAT)
vtkdata.SetNumberOfComponents(3) #We have an x,y,z vector so reform it accordingly
vtkdata.SetName(“Velocity”)

image = vtk.vtkImageData() #Create initial Image data
image.SetDimensions(64,256,256)
image.GetPointData().SetVectors(vtkdata)

vorticity = vtk.vtkCellDerivatives()
vorticity.SetVectorModeToComputeVorticity()
#We don’t need tensors now
vorticity.SetTensorModeToPassTensors()
vorticity.SetInputData(image)
vorticity.Update()

 

More to be posted in the future!

 

Leave a Reply