Tools

Version query

modepy.version.VERSION

A tuple like (2013, 1, 1) indicating modepy’s version.

modepy.version.VERSION_TEXT

A textual representation of the modepy version.

Interpolation matrices

modepy.vandermonde(functions, nodes)

Return a (generalized) Vandermonde matrix.

The Vandermonde Matrix is given by \(V_{i,j} := f_j(x_i)\) where functions is the list of \(f_j\) and nodes is the array of \(x_i\), shaped as (d, npts), where d is the number of dimensions and npts is the number of nodes.

functions are allowed to return tuple instances. In this case, a tuple of matrices is returned–i.e. this function works directly on modepy.grad_simplex_onb() and returns a tuple of matrices.

Vandermonde matrices are very useful to concisely express interpolation. For instance, one may use the inverse \(V^{-1}\) of a Vandermonde matrix \(V\) to map nodal values (i.e. point values at the nodes corresponding to \(V\)) into modal (i.e. basis) coefficients. \(V\) itself maps modal coefficients to nodal values. This allows easy resampling:

modepy.resampling_matrix(basis, new_nodes, old_nodes, least_squares_ok=False)

Return a matrix that maps nodal values on old_nodes onto nodal values on new_nodes.

Parameters:
  • basis – A sequence of basis functions accepting arrays of shape (dims, npts), like those returned by modepy.simplex_onb().
  • new_nodes – An array of shape (dims, n_new_nodes)
  • old_nodes – An array of shape (dims, n_old_nodes)
  • least_squares_ok – If False, then nodal values at old_nodes are required to determine the interpolant uniquely, i.e. the Vandermonde matrix must be square. If True, then a point-wise least-squares best-approximant is used (by ways of the pseudo-inverse of the Vandermonde matrix).

Vandermonde matrices also obey the following relationship useful for obtaining point interpolants:

\[V^T [\text{interpolation coefficents to point $x$}] = \phi_i(x),\]

where \((\phi_i)_i\) is the basis of functions underlying \(V\).

modepy.inverse_mass_matrix(basis, nodes)

Return a matrix \(A=M^{-1}\), which is the inverse of the one returned by mass_matrix().

New in version 2015.1.

modepy.mass_matrix(basis, nodes)

Return a mass matrix \(M\), which obeys

\[M_{ij} = \int_\triangle \phi_i(x) \phi_j(x) dx = (V^{-T} V^{-1})_{ij}.\]
Parameters:basis – assumed to be an orthonormal basis with respect to the \(L^2\) inner product.

New in version 2014.1.

modepy.modal_face_mass_matrix(trial_basis, order, face_vertices, test_basis=None)
Parameters:face_vertices – an array of shape [dim, npts], where npts should equal dim.

New in version 2016.1.

modepy.nodal_face_mass_matrix(trial_basis, volume_nodes, face_nodes, order, face_vertices, test_basis=None)
Parameters:face_vertices – an array of shape [dim, npts], where npts should equal dim.

New in version 2016.1.

Differentiation is also convenient to express by using \(V^{-1}\) to obtain modal values and then using a Vandermonde matrix for the derivatives of the basis to return to nodal values.

modepy.differentiation_matrices(basis, grad_basis, nodes, from_nodes=None)

Return matrices carrying out differentiation on nodal values in the \((r,s,t)\) unit directions. (See Coordinates on the triangle and Coordinates on the tetrahedron.)

Parameters:
  • basis – A sequence of basis functions accepting arrays of shape (dims, npts), like those returned by modepy.simplex_onb().
  • grad_basis – A sequence of functions returning the gradients of basis, like those returned by modepy.grad_simplex_onb().
  • nodes – An array of shape (dims, n_nodes)
  • from_nodes – An array of shape (dims, n_from_nodes). If None, assumed to be the same as nodes.
Returns:

If grad_basis returned tuples (i.e. in 2D and 3D), returns a tuple of length dims containing differentiation matrices. If not, returns just one differentiation matrix.

Changed in version 2013.4: Added from_nodes.

Modal decay/residual

Estimate the smoothness of a function represented in a basis returned by modepy.simplex_onb().

The method implemented in this module follows this article:

A. Kloeckner, T. Warburton, and J. S. Hesthaven. “Viscous Shock Capturing in a Time-Explicit Discontinuous Galerkin Method”. Mathematical Modelling of Natural Phenomena 6, No. 3 (May 16, 2011): 57-83. http://dx.doi.org/10.1051/mmnp/20116303 http://arxiv.org/abs/1102.3190

New in version 2013.2.

modepy.modal_decay.simplex_interp_error_coefficient_estimator_matrix(unit_nodes, order, n_tail_orders)

Return a matrix \(C\) that, when multiplied by a vector of nodal values, yields the coeffiicients belonging to the basis functions of the n_tail_orders highest orders.

The 2-norm of the resulting coefficents can be used as an estimate of the interpolation error.

New in version 2018.1.

modepy.modal_decay.fit_modal_decay(coeffs, dims, n, ignored_modes=1)

Fit a curve to the modal decay on each element.

Parameters:
  • coeffs – a array of shape (num_elements, num_modes) containing modal coefficients of the functions to be analyzed
  • dims – number of dimensions
  • ignored_modes – the number of modal coefficients to ignore at the beginning. The default value of ‘1’ ignores the constant.
Returns:

a tuple (expn, constant) of arrays of length num_elements, where the modal decay is fit to the curve constant * total_degree**exponent.

-exponent-1 can be used as a rough indicator of how many continuous derivatives the underlying function possesses.

modepy.modal_decay.estimate_relative_expansion_residual(coeffs, dims, n, ignored_modes=1)

Use the modal fit to estimate the relative residual of the expansion. The arguments to this function exactly match fit_modal_decay().

Returns:An array of estimates of the fraction of the \(L^2\) norm contained in the (unrepresented) tail of

An idea like this is described in this article:

H. Feng and C. Mavriplis, “Adaptive Spectral Element Simulations of Thin Premixed Flame Sheet Deformations”, Journal of Scientific Computing, Volume 17, Nr. 1, S. 385-395, Dec. 2002. http://dx.doi.org/10.1023/A:1015137722700

For this function, however, the decay curve is fitted using the Kloeckner/Warburton/Hesthaven technique (see above).

Interpolation quality

modepy.tools.estimate_lebesgue_constant(n, nodes, visualize=False)

Estimate the Lebesgue constant of the nodes at polynomial order n.

Parameters:
  • nodes – an array of shape (dims, nnodes) as returned by modepy.warp_and_blend_nodes().
  • visualize – visualize the function that gives rise to the returned Lebesgue constant. (2D only for now)
Returns:

the Lebesgue constant, a scalar

New in version 2013.2.