[Paraview] Using Value of Variable At Point in Calculator Filter

Cory Quammen cory.quammen at kitware.com
Thu Jul 6 15:38:03 EDT 2017


On Mon, Jul 3, 2017 at 9:01 PM, Jeremias Gonzalez
<jgonzalez49 at ucmerced.edu> wrote:
> Hi, I've been trying to figure out, in Paraview, how to use the value of a
> variable at a point in the calculator filter over a geometry. So, for
> example, I have 3 vtk files of a cube geometry with a scalar and vector
> field (x,y,z components) as data sets. I create a gradient filter for each
> one of the vector components, then use the append attributes filter to
> combine the gradients into one object, then use the calculator filter to
> compute some quantity using the gradients as well as {the value of a vector
> field component of each vtk in the middle of the cube} and plot the result
> over the cubic geometry, maybe take a slice of that cube at the end. I have
> some roadblocks that prevent me from doing this in a less manual,
> straightforward fashion:
>
> 1. I do not see a command in the calculator filter like
> EvaluateAtPoint(myvectorfieldxcomponentvtk1,(x=0,y=0,z=0.5)) to grab the
> value of the x component of the vector field from vtk1 at point (0,0,0.5) in
> Cartesian coordinates and use it in some quantity like
> gradientx*5*EvaluateAtPoint(...) which would be evaluated over the entire
> cubic geometry, but always use the value of that point in the middle. I have
> used this sort of thing before in a program called COMSOL, which possesses
> such a feature in the Scoped Evaluation list called at3_geometry, among many
> other variations.

Indeed, ParaView does not have such a command in the Calculator filter.

> 2. Even if there was a command like in #1, the append attributes command
> doesn't seem to respect the different sources of the vector field, so I see
> only one vector field in the resulting array (by contrast, I can name the
> gradients of the vector field components uniquely in each of the filters
> that outputs them, and the append attributes filter shows three distinct
> batches of gradients from each filter I applied to each vtk).

If I understand you correctly, you are describing how only one of the
data arrays from the inputs with the same name is copied to the
output. That is unfortunately the behavior in ParaView 5.4 and prior.
The good news is that the next version of ParaView should instead copy
all the data arrays and mangle the names of the vector field so that
you can have all three distinct vector arrays in the output of the
Append Attribute filter when you do this. See

https://gitlab.kitware.com/paraview/paraview/merge_requests/1639

which added this feature.

> 3. I tried to create a probe at the location I need, but the geometry it
> produces is a single point and thus using it either {directly with append
> attributes to the other gradient results} or {with a calculator filter first
> to get only the quantity I want instead of the scalar field and the vector
> fields evaluated at that point and then use the append attributes command}
> doesn't work because the append attributes apparently uses only the
> overlapping geometry, which of course is only the one point.

Good thinking using the Probe filter (see below), but yep, this won't
quite work.

> 4. I tried to use group datasets instead, thinking maybe it would just take
> the value I make in the calculator filter from the probe location filter and
> use it in the final calculator filter, but it just throws a bunch of errors
> which I assume again stem from the mismatch of geometry.

The Group datasets filter will create a multi block data set, which
won't exactly help you.

> 5. I had an idea to maybe just clone each of the original vtks to get the
> geometry I need in a new array, and then somehow set all the datapoints in
> each one to the value I get from the probe location filter, but this would
> not only again encounter the problem in #2 with the nonunique naming, but I
> also do not know how to edit the individual data points in the file (I see
> an inkling of this idea in the blog post here:
> https://blog.kitware.com/zero-copy-arrays/ but it's quite beyond my current
> level of understanding of Paraview).

This would also be wasteful in terms of memory usage.

> The current alternative (that definitely works) is to just manually copy the
> value I get from {the probe location filter or plot over line filter or
> something like that } into the final calculator filter, but I'd have to do
> that for every one of the batches of 3 vtk files I get, which is going to
> get very large when I start varying my more complicated geometry with
> parametric sweeps (I also need to figure out how to automate the process of
> outputting the slice I take at the end, but one problem at a time! I welcome
> any suggestions on this front).

I would look at using the Python scripting capabilities within
ParaView for this. You can write a Python script and run it with
pvpython - this is especially useful for running an analysis in a
batch fashion. Within your script you use the Probe filter to get the
data value at a particular location and add that value to some
Calculator expression as needed. Here's a quick example:

from paraview.simple import *

data = FindSource('MyDataSource')
probe = ProbeLocation(Input=data, ProbeType='Fixed Radius Point Source')
probe.ProbeType.Center = [1.0, 0.0, 0.0]
probe.UpdatePipeline()
probePoint = paraview.servermanager.Fetch(probe)
value_at_probe = probePoint.GetPointData().GetArray('my array name').GetValue(0)

calculator_expression = #... value_at_probe + other expression
c1 = Calculator(Input=appendedData)
c1.Function = calculator_expression
...


I hope that helps get you started. Let us know if you have other
questions about the scripting.

Thanks,
Cory

> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/paraview



-- 
Cory Quammen
Staff R&D Engineer
Kitware, Inc.


More information about the ParaView mailing list