mpl.tri.CubicTriInterpolator

class mpl.tri.CubicTriInterpolator(triangulation, z, kind=u'min_E', trifinder=None, dz=None)[source]

A CubicTriInterpolator performs cubic interpolation on triangular grids.

In one-dimension - on a segment - a cubic interpolating function is defined by the values of the function and its derivative at both ends. This is almost the same in 2-d inside a triangle, except that the values of the function and its 2 derivatives have to be defined at each triangle node.

The CubicTriInterpolator takes the value of the function at each node - provided by the user - and internally computes the value of the derivatives, resulting in a smooth interpolation. (As a special feature, the user can also impose the value of the derivatives at each node, but this is not supposed to be the common usage.)

Parameters:

triangulation : Triangulation object

The triangulation to interpolate over.

z : array_like of shape (npoints,)

Array of values, defined at grid points, to interpolate between.

kind : {‘min_E’, ‘geom’, ‘user’}, optional

Choice of the smoothing algorithm, in order to compute the interpolant derivatives (defaults to ‘min_E’):

  • if ‘min_E’: (default) The derivatives at each node is computed to minimize a bending energy.
  • if ‘geom’: The derivatives at each node is computed as a weighted average of relevant triangle normals. To be used for speed optimization (large grids).
  • if ‘user’: The user provides the argument dz, no computation is hence needed.

trifinder : TriFinder object, optional

If not specified, the Triangulation’s default TriFinder will be used by calling matplotlib.tri.Triangulation.get_trifinder().

dz : tuple of array_likes (dzdx, dzdy), optional

Used only if kind =’user’. In this case dz must be provided as (dzdx, dzdy) where dzdx, dzdy are arrays of the same shape as z and are the interpolant first derivatives at the triangulation points.

Notes

This note is a bit technical and details the way a CubicTriInterpolator computes a cubic interpolation.

The interpolation is based on a Clough-Tocher subdivision scheme of the triangulation mesh (to make it clearer, each triangle of the grid will be divided in 3 child-triangles, and on each child triangle the interpolated function is a cubic polynomial of the 2 coordinates). This technique originates from FEM (Finite Element Method) analysis; the element used is a reduced Hsieh-Clough-Tocher (HCT) element. Its shape functions are described in [R1]. The assembled function is guaranteed to be C1-smooth, i.e. it is continuous and its first derivatives are also continuous (this is easy to show inside the triangles but is also true when crossing the edges).

In the default case (kind =’min_E’), the interpolant minimizes a curvature energy on the functional space generated by the HCT element shape functions - with imposed values but arbitrary derivatives at each node. The minimized functional is the integral of the so-called total curvature (implementation based on an algorithm from [R2] - PCG sparse solver):

\[E(z) = \ \frac{1}{2} \int_{\Omega} \left( \left( \frac{\partial^2{z}}{\partial{x}^2} \right)^2 + \left( \frac{\partial^2{z}}{\partial{y}^2} \right)^2 + 2\left( \frac{\partial^2{z}}{\partial{y}\partial{x}} \right)^2 \right) dx\,dy\]

If the case kind =’geom’ is chosen by the user, a simple geometric approximation is used (weighted average of the triangle normal vectors), which could improve speed on very large grids.

References

[R1](1, 2) Michel Bernadou, Kamal Hassan, “Basis functions for general Hsieh-Clough-Tocher triangles, complete or reduced.”, International Journal for Numerical Methods in Engineering, 17(5):784 - 789. 2.01.
[R2](1, 2) C.T. Kelley, “Iterative Methods for Optimization”.

Methods

__call__ (x, y) ( Returns interpolated values at x,y points)
gradient (x, y) (Returns interpolated derivatives at x,y points)
__init__(triangulation, z, kind=u'min_E', trifinder=None, dz=None)[source]

Methods

__init__(triangulation, z[, kind, trifinder, dz])
gradient(x, y) Returns a list of 2 masked arrays containing interpolated derivatives at the specified x,y points.