I have a triangle mesh, and want to write some cell data which changed over time into a test.vtu
files by vtk python interface.
import numpy as np
import vtk
import vtk.util.numpy_support as vnp
mesh =vtk.vtkUnstructuredGrid()
# creat points, cellType, cells, (here we have NC cells)
mesh.SetPoints(points)
mesh.SetCells(cellType, cells)
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName("test.vtu")
writer.SetInputData(mesh)
writer.SetNumberOfTimeSteps(100)
writer.Start()
for i in range(100):
# how to add the celldata array of current time level into mesh?
# cdata = mesh.GetCellData()
# val = ... # a numpy array
# d = vnp.numpy_to_vtk(val)
# cdata.AddArray(val)
writer.WriteNextTime(i)
writer.Stop()
The code in the loop which was commented can not work well. Any suggestion? Thanks very much.