[Paraview-developers] Time streaming problem of TemporalCache in paraview python

Di Cheng chengdi at imech.ac.cn
Mon Apr 27 09:40:48 EDT 2015


Hi, every one

I am using paraview to calculate correlation of each time steps in a filter, and I am using programmable filter to implement it. I have tried three different pipelines like those:
1) 
Reader
+-TemporalCache1->ProgrammableFilter
+-TemporalCache2->ProgrammableFilter

But it failed and give me a segfault after some output, And before segfault the data that  TemporalCache1 transferred to ProgrammableFilter is nan. Increasing CacheSize of TemporalCache is useless.

2)
Reader1->TemporalCache1->ProgrammableFilter
Reader2->TemporalCache2->ProgrammableFilter

No segfault, but still nan

3)
Reader1 ->ProgrammableFilter
Reader2 ->ProgrammableFilter

It works! 

My question is: Why?

p.s.
I am using paraview 4.3.1 in Ubuntu 12.04.

Here is my code:
#### import the simple module from the paraview
from paraview.simple import *
import numpy as np
# ----------------------------------------------------------------
# setup the data processing pipelines
# ----------------------------------------------------------------
filename = '/home/wei/Wu/VortexStreet/100cylinder/100cylinder.foam'

# create a new 'OpenFOAMReader'
reader1 = OpenFOAMReader(FileName=filename)
reader1.Createcelltopointfiltereddata = 0
reader1.MeshRegions = ['internalMesh']
reader1.CellArrays = ['p']
reader1.Cachemesh = 0
reader1.Decomposepolyhedra = 0

# create a new 'OpenFOAMReader'
reader2 = OpenFOAMReader(FileName=filename)
reader2.Createcelltopointfiltereddata = 0
reader2.MeshRegions = ['internalMesh']
reader2.CellArrays = ['p']
reader2.Cachemesh = 0
reader2.Decomposepolyhedra = 0
    
# create a new 'Temporal Cache'
tc1 = TemporalCache(Input=reader1)
tc1.CacheSize=2
# create a new 'Temporal Cache'
tc2 = TemporalCache(Input=reader2)
tc2.CacheSize=2

# initialize in RequestInformationScript
# Ask for new timestep in RequestUpdateExtentScript
# generate dataset in Script
#pf2 = ProgrammableFilter(Input = [tc1,tc2])
pf2 = ProgrammableFilter(Input = [reader1,reader2])
pf2.CopyArrays = 0
pf2.OutputDataSetType = 'vtkTable'
pf2.Script =\
"""
print 'running: Script'
# according to the c++ implementation of vtkPythonProgrammableFilter
# the following script has been run 
# from paraview import vtk
#     hasnumpy = True
# try:
#     from numpy import *
# except ImportError:
#     hasnumpy = False
# if hasnumpy:
# from vtk.numpy_interface import dataset_adapter

#note: all locals() will be collected by Garbage Collection after execution. 
#save all important variables in self.***
#pass arguments to other scripts by self.***
#use hasattr(***) function to check if there is existing self.*** 


# ref: The Paraview Guide v4.3 Chapter 13.2.2
# the types:
# executive: vtkPVCompositeDataPipeline
# inInfo: vtkInformation, ref:http://berkgeveci.github.io/2014/11/09/streaming-time/
from vtk.numpy_interface import algorithms as algs
#inner product is defined as cell volume weighted integration of p1*p2 over entire volume
self.R[self.i,self.j]  = algs.sum(inputs[0].CellData['p']*inputs[1].CellData['p']*self.weight)
print self.R[self.i,self.j]
#for upper half matrix, keep this matrix symmetry
if self.j!=self.i:
    self.R[self.j,self.i] = self.R[self.i,self.j]

try:
    self.n += 1
    self.i,self.j = self.time_value_index[self.n]
    request.Set(vtk.vtkStreamingDemandDrivenPipeline.CONTINUE_EXECUTING(),1)
    print 'CONTINUE_EXECUTING is set'
except IndexError:
    #output
    output.RowData.append(self.time_steps,'time_steps')
    for k,t0 in enumerate(self.time_steps):
        output.RowData.append(self.R[k],'{}'.format(k))
    #stop
    request.Remove(vtk.vtkStreamingDemandDrivenPipeline.CONTINUE_EXECUTING())
    print 'CONTINUE_EXECUTING removed'
"""
pf2.RequestUpdateExtentScript=\
"""
print 'running: RequestUpdateExtentScript'
# Code for RequestUpdateExtentScript.
executive = self.GetExecutive()
inInfo0 = executive.GetInputInformation(0,0) #port 0, connection 0
inInfo1 = executive.GetInputInformation(0,1) #port 0, connection 1 
inInfo0.Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_TIME_STEP(),self.time_steps[self.i])
inInfo1.Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_TIME_STEP(),self.time_steps[self.j])
print 'i={},j={},t0={},t1={}'.format(self.i,self.j,self.time_steps[self.i],self.time_steps[self.j])
"""
pf2.RequestInformationScript=\
'''
print 'running: RequestInformationScript'
# ref: The Paraview Guide v4.3 Chapter 13.2.2
# the types:
# executive: vtkPVCompositeDataPipeline
# outInfo: vtkInformation, ref:http://berkgeveci.github.io/2014/11/09/streaming-time/
executive = self.GetExecutive()
outInfo = executive.GetOutputInformation(0)
outInfo.Remove(executive.TIME_RANGE ())
outInfo.Remove(executive.TIME_STEPS ())
print 'outInfo:'
print(outInfo)
inInfo0 = executive.GetInputInformation(0,0) #port 0, connection 0 

print 'inInfo0:'
print(inInfo0)

# set the sampling time steps
start,end,step = 101,202,20 # None means to the end of the array
self.time_steps = array(inInfo0.Get(vtk.vtkStreamingDemandDrivenPipeline.TIME_STEPS())[start:end:step]) #create object, in case of Garbage Collection
print self.time_steps

self.N = len(self.time_steps)
from itertools import combinations_with_replacement
self.time_value_index = tuple(combinations_with_replacement(range(self.N),2))
self.n = 0
self.i,self.j = self.time_value_index[self.n]
#iterate to calculate correlation matrix
self.R = zeros([self.N,self.N]) 

from vtk.numpy_interface import algorithms as algs
self.weight = algs.volume(inputs[0])
self.weight = self.weight/algs.sum(self.weight) #normalization
'''
pf2.UpdatePipeline()


# calculate eigen values
pf3 = ProgrammableFilter(Input =pf2)
pf3.CopyArrays = 0
pf3.OutputDataSetType = 'vtkTable'
pf3.Script=\
'''
#get R
t = inputs[0].RowData['time_steps']
N = len(t)
R = zeros([N,N])
for i in range(N):
    R[i]=inputs[0].RowData['{}'.format(i)]

#calculate eigen values and vectors
from numpy.linalg import eigh
e,eV = eigh(R)
total_energy = trace(R)
#sort eV and a by a
idx = argsort(e)
e = e[idx[::-1]]
en = e/total_energy #normalized energy
eV = eV[idx[::-1]]

output.RowData.append(t,'time_steps')
output.RowData.append(e,'eigen_value')
output.RowData.append(en,'relative_energy_fraction')
for i,t0 in enumerate(t):
    output.RowData.append(eV[i],'{}'.format(i))
'''
pf3.UpdatePipeline()


Di CHENG (Ph.D. candidate)
Supersonic Combustion Group
State Key Laboratory of High Temperature Gas Dynamics
Institute of Mechanics, Chinese Academy of Sciences
ADDRESS: No.15 Beisihuanxi Road, Beijing (100190)
P. R. China
E-mail: chengdi at imech.ac.cn
Phone: +86-10-82544053
Fax: +86-10-82544034





More information about the Paraview-developers mailing list