[Paraview-developers] Carrying calculated array through to the last time step in programmable filter

mp maik.pohl87 at gmx.de
Wed Mar 16 08:03:06 EDT 2016


For now, i used a different (very inelegant and inefficient) way, but it's
the only one i can come up with for now.
Instead of writing the difference into an array and trying to get the array
to the end, i write the results of my calculation to a file and when the
simulation reaches the last time step (for now, the user has to specify this
too), the file is read and written into an array which is then committed to
the output.

The source code now looks like this:

from paraview.simple import *
filter = ProgrammableFilter()
RenameSource("Diference between time steps" , filter)
filter.Script = """
import os
import os.path
#Number of Array to be subtracted
arr = 2
# t1 is the time that contains the minuend
t1 = 100
# t2 is the time that contains the subtrahend
t2 = 800
# tEnd is the last timestep of the simulation
tEnd = 1000

tempFilePath = ""
tCurrent =
inputs[0].GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())
if tCurrent == t1:
    f = open(tempFilePath + "test.txt" , 'w')
    for i in range(self.GetInput().GetCellData().GetArray(arr).GetSize()):
        f.write(str(self.GetInput().GetCellData().GetArray(arr).GetValue(i))
+ "\\n")
elif tCurrent==t2:
    subtrahend = list()
    for i in range(self.GetInput().GetCellData().GetArray(arr).GetSize()):
       
subtrahend.append(float(self.GetInput().GetCellData().GetArray(arr).GetValue(i)))
    f = open(tempFilePath + "test.txt" , 'r')
    minuend = [line.rstrip("\\n") for line in f]
    for j in range(len(minuend)):
        minuend[j] = float(minuend[j])
    d = map(lambda x,y: x-y,minuend,subtrahend)
    f.close()
    f = open(tempFilePath + "difference.txt" ,'w')
    for k in range(len(d)):
        f.write(str(d[k]) + "\\n")
    os.remove(tempFilePath + "test.txt")
elif tCurrent==tEnd:
    f = open(tempFilePath + "difference.txt" , 'r')
    dif = [line.rstrip("\\n") for line in f]
    for j in range(len(dif)):
        dif[j] = float(dif[j])
    f.close()
    difference = vtk.vtkDoubleArray()
    difference.SetNumberOfComponents(0)
    difference.SetName("difference")
    for i in range(len(dif)):
        difference.InsertNextValue(dif[i])
    self.GetOutput().GetCellData().AddArray(difference)
    os.remove(tempFilePath + "difference.txt")
"""
filter_repr = Show()



Is there a way to get the last time step without having to rely on the user?

Thanks, mp



--
View this message in context: http://the-unofficial-paraview-developers-forum.34153.x6.nabble.com/Carrying-calculated-array-through-to-the-last-time-step-in-programmable-filter-tp4213p4216.html
Sent from the The Unofficial ParaView Developers Forum mailing list archive at Nabble.com.


More information about the Paraview-developers mailing list