[Paraview] Delete Data Array from unstructured mesh in pypython

Jacques Papper jacques.papper at gmail.com
Thu Mar 5 17:01:59 EST 2009


Indeed, I think this would be very useful. For example I often use several
calculators in a pipeline and then create a custom filter from my pipeline.
Although the only data I need is the one in the output from my custom
filter, all the intermediate variables are kept in memory (right?) which can
make everything blow up. I know I can write the equivalent C++ code and only
keep the array I want, but this means I do not use the existing filters..

Jacques

2009/3/5 Berk Geveci <berk.geveci at kitware.com>

> Use a programmable filter with the following code (or something close to
> it):
>
> input = self.GetInputDataObject(0,0)
> output = self.GetOutputDataObject(0)
> output.CopyStructure(input)
> output.GetPointData().AddArray(input.GetArray("pressure"))
>
> This would avoid passing everything but pressure to the output.
> However, it would not delete the other arrays from memory as the
> previous objects in the pipeline are still referring to them. It
> would, however, prevent further processing of those arrays. There is
> really no way of deleting an object once you load it.  There are ways
> of doing this in VTK. If there is a need for it, we can put
> investigating the idea on our roadmap.
>
> -berk
>
>
> On Wed, Mar 4, 2009 at 3:34 PM, Dan Goldstein <dan at cora.nwra.com> wrote:
> >
> >  Can anyone give me a hint on how to delete an array from an unstructured
> > mesh
> > in a python script. I need to do this to save memory when going through
> > multiple
> > steps processing data.
> > Below is an example python script and where I would like to delete unused
> > arrays to save memory.
> > Thanks for any help or ideas.. Dan
> >
> >
> >    reader =  \
> >
> >
> servermanager.sources.XMLUnstructuredGridReader(FileName=in_dir+"/"+in_file)
> >
> > # Use calculator to get the first component of velocity into the
> >    # scalar array velocity_u
> >    calc_u = servermanager.filters.Calculator(Input=reader)
> >    calc_u.ResultArrayName ='velocity_u'
> >    calc_u.AddScalarVariable = ['velocity', 'velocity', '0']
> >    calc_u.Function = 'velocity'
> >
> > # Use calculator to get the first component of velocity into the
> >    # scalar array velocity_u
> >    calc_v = servermanager.filters.Calculator(Input=calc_u)
> >    calc_v.ResultArrayName ='velocity_v'
> >    calc_v.AddScalarVariable = ['velocity', 'velocity', '1']
> >    calc_v.Function = 'velocity'
> >
> > # Use calculator to get the first component of velocity into the
> >    # scalar array velocity_u
> >    calc_w = servermanager.filters.Calculator(Input=calc_v)
> >    calc_w.ResultArrayName ='velocity_w'
> >    calc_w.AddScalarVariable = ['velocity', 'velocity', '2']
> >    calc_w.Function = 'velocity'
> >
> > # I NO LONGER NEED THE WHOLE VELOCITY FIELD I WOULD LIKE TO DELETE IT
> >
> > #calculate gradiants du
> >    grad_u= servermanager.filters.UnstructuredGradient(Input=calc_w)
> >    grad_u.ResultArrayName = "du"
> >    grad_u.SelectInputScalars = ["0","0","0","0","velocity_u"]
> > #calculate gradiants dv
> >    grad_v= servermanager.filters.UnstructuredGradient(Input=grad_u)
> >    grad_v.ResultArrayName = "dv"
> >    grad_v.SelectInputScalars = ["0","0","0","0","velocity_v"]
> > #calculate gradiants dw
> >    grad_w= servermanager.filters.UnstructuredGradient(Input=grad_v)
> >    grad_w.ResultArrayName = "dw"
> >    grad_w.SelectInputScalars = ["0","0","0","0","velocity_w"]
> >
> > # I NO LONGER NEED THE WHOLE VELOCITY SCALAR FIELDS I WOULD LIKE TO
> DELETE
> > THEM
> >
> > #calculate vorticity magnitude
> >    calc_vort = servermanager.filters.Calculator(Input=grad_w)
> >    calc_vort.ResultArrayName ='VortMag'
> >    calc_vort.AddScalarVariable = \
> >       ['dudx', 'du', '0','dudy', 'du', '1','dudz', 'du', '2',\
> >        'dvdx', 'dv', '0','dvdy', 'dv', '1','dvdz', 'dv', '2',\
> >        'dwdx', 'dw', '0','dwdy', 'dw', '1','dwdz', 'dw', '2', ]
> >    calc_vort.Function = 'sqrt( (dwdy - dvdz)^2  + (dudz - dwdx)^2 + (dvdx
> -
> > dvd
> > y )^2 )'
> >
> > # ALL DONE ! I WOULD LIKE TO DELETE EVERYTHING EXCEPT THE REQUIRED
> VORTICITY
> > MAGNITUDE SCALAR FIELD
> >
> >    writer =
> > servermanager.writers.XMLUnstructuredGridWriter(Input=calc_vort,\
> >             FileName=out_file )
> >    writer.UpdatePipeline()
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the ParaView Wiki at:
> > http://paraview.org/Wiki/ParaView
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.paraview.org/mailman/listinfo/paraview
> >
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20090305/aaaf6119/attachment-0001.htm>


More information about the ParaView mailing list