[vtkusers] Saving multiple time steps in a vtkXMLStructuredGrid file ...
Meehan, Bernard
MEEHANBT at nv.doe.gov
Wed Jul 8 11:02:25 EDT 2015
I was hoping to be able to write a scalar field that changed over time to
a vtkXMLStructuredGridFile, following the example on this thread:
http://public.kitware.com/pipermail/vtkusers/2012-November/077262.html
But when I examined my ³*vts² file, the scalar function wasn¹t written to
a different time step. I¹d be happy to turn this into an example on the
wiki if I could get it to work Š
import vtk
NX = 10
NY = 10
NZ = 10
#-------------------------------Create your
Grid-------------------------------#
pts = vtk.vtkPoints()
for i in range(NX):
for j in range(NY):
for k in range(NZ):
pts.InsertNextPoint(i, j, k)
sg = vtk.vtkStructuredGrid()
sg.SetDimensions(NX, NY, NZ)
sg.SetPoints(pts)
f1 = vtk.vtkDoubleArray()
f1.SetName("Function 1")
for i in range(NX):
for j in range(NY):
for k in range(NZ):
f1.InsertNextValue(i+j+k)
sg.GetPointData().AddArray(f1)
#----------------------------------Save
File-----------------------------------#
w = vtk.vtkXMLStructuredGridWriter()
w.SetFileName("test.vts")
w.SetInputData(sg)
w.SetDataModeToAscii()
w.SetCompressorTypeToNone()
w.SetNumberOfTimeSteps(3)
w.Start()
w.WriteNextTime(0.0)
w.WriteNextTime(0.1)
# I wanted to see if I could change "Function 1" at the third time step,
but
# when I look at the file that is written, the time step for this never
seems
# to change?
f1 = vtk.vtkDoubleArray()
f1.SetName("Function 1")
for i in range(NX):
for j in range(NY):
for k in range(NZ):
f1.InsertNextValue(-(i+j+k))
sg.GetPointData().AddArray(f1)
sg.Modified()
w.WriteNextTime(0.2)
w.Stop()
More information about the vtkusers
mailing list