[vtkusers] add cell data to unstructured grid in time.

Kurt Sansom kayarre at gmail.com
Mon May 8 17:44:48 EDT 2017


I have created an unstructured grid data set that uses the SetTimeStep
method to get the data for each time step. What I am having trouble doing
to adding an array with calculated information and then writing the file
out.

see below.


I create a variable TAWSS

TAWSS = vtk.vtkFloatArray()
TAWSS.SetNumberOfComponents(1)
TAWSS.SetNumberOfValues(calc2.GetOutput().GetNumberOfCells())
TAWSS.SetName("TAWSS")

then I calculate the average over the whole dataset, where calc2 is a
vtkArrayCalculator() earlier in the pipeline.

for i in range(N):
    reader.SetTimeStep(i)
    print("Time step {0} for average calc".format(i))
    reader.Update()
    calc2.Update()
    wss_temp = calc2.GetOutput().GetCellData().GetArray("WSS")
    if ( i == 0 ):
        TAWSS.DeepCopy(wss_temp)
    else:
        array_avg(TAWSS, wss_temp, reader.GetOutput().GetNumberOfCells(),
float(i+1.0))

    calc2.GetOutput().GetCellData().AddArray(TAWSS)

this doesn't add TAWSS to the outfile.

writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName("calc_test.vtu")
writer.SetNumberOfTimeSteps(N)
writer.SetInputConnection(calc2.GetOutputPort())
writer.Start()

for i in range(N):
    reader.SetTimeStep(i)
    print("Writing time step {0}".format(i))
    calc2.GetOutput().GetCellData().AddArray(TAWSS)
    reader.Update()
    calc2.Update()

    writer.WriteNextTime(reader.GetTimeStep())
writer.Stop()

-- 
Kurt Sansom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170508/0c7c1733/attachment.html>


More information about the vtkusers mailing list