<div dir="ltr"><div>Hello,</div><div><br></div><div>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.</div>
<div><br></div><div>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).</div>
<div><br></div><div>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?</div>
<div><br></div><div>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</div>
<div><br></div><div><font face="courier new, monospace">==================</font></div><div><font face="courier new, monospace">START OF THE SCRIPT</font></div><div><font face="courier new, monospace">==================</font></div>
<div><font face="courier new, monospace">#!/apps/local-linux/paraview4.01/bin/pvpython</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">try: paraview.simple</font></div>
<div><font face="courier new, monospace">except: from paraview.simple import *</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">import sys, getopt, math, subprocess, os.path</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">def main(argv):</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>inputfile = 'NS.vtk'</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Nstep = 200</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Zmin = -2.</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Zmax = 20.</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Zoffset = +1.</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>try:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>opts, args = getopt.getopt(argv,"hi:o:N:Zmax:Zmin:Zoff:",["ifile=","Nstep=","zStart=","zEnd=","zOffset="])</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>except getopt.GetoptError:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>print 'slices.py -i <inputfile> -N <Nstep> -Zmin <Z 1st slice> -Zmax <Z final slice> -Zoff <Offset in Z>' </font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>sys.exit(2)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>for opt, arg in opts:</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>if opt == '-h':</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>print 'slices.py -i <inputfile> -N <Nstep> -Zmin <Z 1st slice> -Zmax <Z final slice> -Zoff <Offset in Z>'</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>sys.exit()</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>elif opt in ("-i", "--ifile"):</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>inputfile = arg</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>elif opt in ("-N", "--Nstep"):</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Nstep = int(arg)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>elif opt in ("-Zmax", "--zEnd"):</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Zmax = float(arg)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>elif opt in ("-Zmin", "--zStart"):</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Zmin = float(arg)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>elif opt in ("-Zoff", "--zOffset"):</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Zoffset = float(arg)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>inputfile = '..' + inputfile</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>command = ['find', '.', '-type', 'f', '-regex', inputfile]</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>FileList = subprocess.check_output(command).split()</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>for k in range (0,len(FileList)):</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>vtkfile = FileList[k].replace('./','')</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>outfile = FileList[k].replace('./','').replace('vtk','dat')</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>if not os.path.isfile(outfile):</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>NS_quad_vtk = LegacyVTKReader(FileNames=vtkfile)</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>print "output: %s" %(outfile)</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Calculator1 = Calculator()</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Calculator1.Function = 'U+V+W_Z*coordsX'</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Calculator1.ResultArrayName = 'momX'</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Slice1 = Slice( SliceType="Plane" )</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>IntegrateVariables1 = IntegrateVariables()</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>IntegrateVariables1.Input=Slice1</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>fout = open(outfile,'w')</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>for i in range (0,Nstep):</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>zOrigin = Zmin + float(i)*(Zmax-Zmin)/(Nstep-1.)</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Slice1.SliceOffsetValues = [0.0]</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Slice1.SliceType.Origin = [0.0, 0.0, zOrigin]</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Slice1.SliceType.Normal = [0.0, 0.0, 1.0]</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>Slice1.SliceType = "Plane"</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>intResult = servermanager.Fetch(IntegrateVariables1,0)</font></div><div>
<font face="courier new, monospace"><span class="" style="white-space:pre"> </span>pointIntResult = intResult.GetPointData()</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>intMx = pointIntResult.GetArray("momX").GetTuple1(0)</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>intW = pointIntResult.GetArray("U+V+W").GetTuple3(0)[2]</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>E = intMx/intW</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>fout.write(str(zOrigin+Zoffset) + "\t" + str(E) + "\n")</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>fout.close()</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">if __name__ == "__main__":</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>main(sys.argv[1:])</font></div><div><font face="courier new, monospace">=================</font></div><div><font face="courier new, monospace">END OF THE SCRIPT</font></div>
<div><font face="courier new, monospace">=================</font></div><div><br></div><div>------------------------------------<b><br>Félix Salazar<br></b><i><a href="mailto:felix.salazar@polymtl.ca" target="_blank"><span style="color:rgb(51,102,255)">felix.salazar@polymtl.ca</span></a></i><b><br>
</b><font size="1">Étudiant au doctorat - PhD Student</font><div><font face="arial, helvetica, sans-serif"><i>École Polytechnique de Montréal</i></font></div><div><div><div><div>------------------------------------<br></div>
</div></div></div></div>
</div>