<div dir="ltr"><div>Hello,</div><div><br></div><div>I&#39;m not very good in python, and I&#39;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&#39;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&#39;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 = &#39;NS.vtk&#39;</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,&quot;hi:o:N:Zmax:Zmin:Zoff:&quot;,[&quot;ifile=&quot;,&quot;Nstep=&quot;,&quot;zStart=&quot;,&quot;zEnd=&quot;,&quot;zOffset=&quot;])</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 &#39;slices.py -i &lt;inputfile&gt; -N &lt;Nstep&gt; -Zmin &lt;Z 1st slice&gt; -Zmax &lt;Z final slice&gt; -Zoff &lt;Offset in Z&gt;&#39; </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 == &#39;-h&#39;:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>print &#39;slices.py -i &lt;inputfile&gt; -N &lt;Nstep&gt; -Zmin &lt;Z 1st slice&gt; -Zmax &lt;Z final slice&gt; -Zoff &lt;Offset in Z&gt;&#39;</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 (&quot;-i&quot;, &quot;--ifile&quot;):</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 (&quot;-N&quot;, &quot;--Nstep&quot;):</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 (&quot;-Zmax&quot;, &quot;--zEnd&quot;):</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 (&quot;-Zmin&quot;, &quot;--zStart&quot;):</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 (&quot;-Zoff&quot;, &quot;--zOffset&quot;):</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 = &#39;..&#39; + inputfile</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>command = [&#39;find&#39;, &#39;.&#39;, &#39;-type&#39;, &#39;f&#39;, &#39;-regex&#39;, 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(&#39;./&#39;,&#39;&#39;)</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>outfile = FileList[k].replace(&#39;./&#39;,&#39;&#39;).replace(&#39;vtk&#39;,&#39;dat&#39;)</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 &quot;output: %s&quot; %(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 = &#39;U+V+W_Z*coordsX&#39;</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>Calculator1.ResultArrayName = &#39;momX&#39;</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=&quot;Plane&quot; )</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,&#39;w&#39;)</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 = &quot;Plane&quot;</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(&quot;momX&quot;).GetTuple1(0)</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>intW   = pointIntResult.GetArray(&quot;U+V+W&quot;).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) + &quot;\t&quot; + str(E) + &quot;\n&quot;)</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__ == &quot;__main__&quot;:</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>