Python calculator and programmable filter: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
Line 17: Line 17:




:A more complete way to access displacement data.  We explicitly pull DISPL from the first input to the filter.
:A more complete way to access displacement data.  We explicitly pull DISPL from the first input to the filter.  Don't forget that the first input is [0], the second is [1], etc.
* Change Expression to '''(inputs[0].PointData['DISPL'])*2'''.  Apply.  Rescale to Data Range.
* Change Expression to '''(inputs[0].PointData['DISPL'])*2'''.  Apply.  Rescale to Data Range.



Revision as of 19:48, 15 December 2015

Introduction

ParaView has two filters that give a user access to python math functions as well as the underlying VTK library. These are the Python Calculator and the Programmable Filter. This tutorial explains both.


Python Calculator

The Python Calculator allows a user to apply calculations that are available in Python. These include such functions as get volume of cells, get area of cells, get the cross product, dot product, curl, etc. The whole formula must fit on one line. Lets go over the Python Calculator with an example.

Lets create a new point variable, loaded with 5.
  • Open can.exo. All variables on. Apply.
  • Filters → Alphabetical → Python Calculator.
  • Change Expression to 5, Array Association as Point Data, and change Array Name to Calculated Variable. Apply.
  • Paint by Calculated Variable.


Lets create a variable equal to two times displacement.
  • Change Expression to DISPL*2. Apply.
  • Go to last timestep. Rescale to Data Range.


A more complete way to access displacement data. We explicitly pull DISPL from the first input to the filter. Don't forget that the first input is [0], the second is [1], etc.
  • Change Expression to (inputs[0].PointData['DISPL'])*2. Apply. Rescale to Data Range.


To recap, we are pointing to the first input to the filter, point data, the DISPL variable. We are multiplying by 2, and putting this into the Calculated Variable var.
If a function requires a variable input, use the string above. If the function needs the input mesh, use inputs[].
Notice that Python uses square brackets for arrays, and parenthesis to group parts of your formula. Also, to designate a string (i.e., variable name), use either single or double quotation marks.


A common request is to return a cell volume. It is done like this:
  • Change expression to volume(inputs[0]). Apply. Rescale to Data Range.


Interesting functions available through the Python Calculator:
  • area(dataset)
  • aspect(dataset)
  • cos(array)
  • cross(X,Y) where X and Y are two 3D vector arrays
  • curl(array)
  • divergence(array)
  • dot(a1,a2)
  • eigenvalue and eigenvector(array)
  • gradient(array)
  • max(array)
  • mean(array)
  • min(array)
  • norm(array)
  • sin(array)
  • strain(array)
  • volume(array)
  • vorticity(array)
The complete list can be found in the ParaView Guide, http://www.paraview.org/paraview-guide/


PvBatch

PvBatch is like PvPython, with two exceptions. PvBatch only accepts commands from input scripts, and PvBatch will run in parallel if it was built using MPI. Input is exactly like PvPython.


Where do you go next?

  • Python calculator and programmable fitler.

Acknowledgements

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000.