0

I want to make npy matrix from unstructured vtu data, and the following is the code for it.

file_name = 'data/0_0000.vtu'
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update()  

polydata = reader.GetOutput()
points = polydata.GetPoints()
array1 = vtk_to_numpy(points.GetData())

cells = polydata.GetCells()
array2 = vtk_to_numpy(cells.GetData())
velocity = vtk_to_numpy(polydata.GetCellData().GetArray("velocity"))

But after I ran this code, it only convert the data partially, not fully. The vtu file contains more than 30000 cells but somehow only 4000 cells were converted.

Could anyone help me to solve this problem?

Thanks!

Nico Vuaille
  • 2,310
  • 1
  • 6
  • 14
swanhwang
  • 31
  • 3
  • Ho do how obtain the "4000" number ? Can you share a file ? Which version of VTK ? For info I cannot reproduce here with VTK 9.1 RC 1 – Nico Vuaille Oct 15 '21 at 08:40
  • Thanks for your reply. 4000 was the number from Python and 30000 is the number I can read from Paraview. But, I just found that my code was right. It was the problem of MPI, and I only read partial data. I am not sure about VTK but the version of the Paraview is 5.10. Thanks again for your comment and I leave this question for other people who want to use Python to read vtu file. – swanhwang Oct 15 '21 at 19:55

0 Answers0