[Paraview] Memory issues with pvpython

Felix Salazar felix.salazar at polymtl.ca
Thu Oct 10 18:03:41 EDT 2013


Hello,

I'm not very good in python, and I'm new in Paraview. I want to calculate
an integral over a series of slices in a domain. I need an scalar per
slice, that result being a function of the position of the slice. The
easiest way I found to do this was a for loop in pvpython, changing the
position of a single in each iteration, and dumping the value of the
integral into an output file, one line per slice. Works good.

Then I slightly modified my script to works with several files at the same
time. It works without errors, but the memory usage grows each time a new
file is processed, until eventually the machine collapse, and an error is
printed (SEGFAULT).

I read that some functions in pvpython have a memory leak, and the way to
deal with this was using UnRegister(). I tried it, but it didn't solve my
issues. Maybe I did not putting in the right place. Could someone help me
with this issue?

My script is the following. I removed the UnRegister() because they were
not working. I also add a bunch of stuff at the beginning, to change the
parameters of integration via command line options. I'm using ParaView
4.01, and my files are in the legacy .vtk file format. Thanks in advance
for any help

==================
START OF THE SCRIPT
==================
#!/apps/local-linux/paraview4.01/bin/pvpython

try: paraview.simple
except: from paraview.simple import *

import sys, getopt, math, subprocess, os.path

def main(argv):
inputfile = 'NS.vtk'
 Nstep     = 200
Zmin      = -2.
 Zmax      = 20.
Zoffset   = +1.
 try:
opts, args =
getopt.getopt(argv,"hi:o:N:Zmax:Zmin:Zoff:",["ifile=","Nstep=","zStart=","zEnd=","zOffset="])
 except getopt.GetoptError:
print 'slices.py -i <inputfile> -N <Nstep> -Zmin <Z 1st slice> -Zmax <Z
final slice> -Zoff <Offset in Z>'
 sys.exit(2)
for opt, arg in opts:
 if opt == '-h':
print 'slices.py -i <inputfile> -N <Nstep> -Zmin <Z 1st slice> -Zmax <Z
final slice> -Zoff <Offset in Z>'
 sys.exit()
elif opt in ("-i", "--ifile"):
 inputfile = arg
elif opt in ("-N", "--Nstep"):
 Nstep = int(arg)
elif opt in ("-Zmax", "--zEnd"):
 Zmax = float(arg)
elif opt in ("-Zmin", "--zStart"):
 Zmin = float(arg)
elif opt in ("-Zoff", "--zOffset"):
 Zoffset = float(arg)

inputfile = '..' + inputfile
 command = ['find', '.', '-type', 'f', '-regex', inputfile]
FileList = subprocess.check_output(command).split()
 for k in range (0,len(FileList)):
vtkfile = FileList[k].replace('./','')
 outfile = FileList[k].replace('./','').replace('vtk','dat')

 if not os.path.isfile(outfile):
NS_quad_vtk = LegacyVTKReader(FileNames=vtkfile)

print "output: %s" %(outfile)

 Calculator1 = Calculator()
Calculator1.Function = 'U+V+W_Z*coordsX'
 Calculator1.ResultArrayName = 'momX'

Slice1 = Slice( SliceType="Plane" )

IntegrateVariables1 = IntegrateVariables()
IntegrateVariables1.Input=Slice1

fout = open(outfile,'w')

 for i in range (0,Nstep):
zOrigin = Zmin + float(i)*(Zmax-Zmin)/(Nstep-1.)
 Slice1.SliceOffsetValues = [0.0]
Slice1.SliceType.Origin = [0.0, 0.0, zOrigin]
 Slice1.SliceType.Normal = [0.0, 0.0, 1.0]
Slice1.SliceType = "Plane"

intResult = servermanager.Fetch(IntegrateVariables1,0)
 pointIntResult = intResult.GetPointData()
intMx  = pointIntResult.GetArray("momX").GetTuple1(0)
 intW   = pointIntResult.GetArray("U+V+W").GetTuple3(0)[2]
E      = intMx/intW
 fout.write(str(zOrigin+Zoffset) + "\t" + str(E) + "\n")

 fout.close()

if __name__ == "__main__":
 main(sys.argv[1:])
=================
END OF THE SCRIPT
=================

------------------------------------*
Félix Salazar
**felix.salazar at polymtl.ca**
*Étudiant au doctorat - PhD Student
*École Polytechnique de Montréal*
------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20131010/9f5386c0/attachment-0001.htm>


More information about the ParaView mailing list