[Paraview] Delete Data Array from unstructured mesh in pypython

Berk Geveci berk.geveci at kitware.com
Thu Mar 5 12:02:23 EST 2009


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
>


More information about the ParaView mailing list