# Modes (Basis functions)¶

## Function Spaces¶

class modepy.FunctionSpace[source]

An opaque object representing a finite-dimensional function space of functions $$\mathbb{R}^n \to \mathbb{R}$$.

spatial_dim

$$n$$ in the above definition, the number of spatial dimensions in which the functions in the space operate.

space_dim

The number of dimensions of the function space.

class modepy.PN(spatial_dim: int, order: int)[source]

The function space of polynomials with total degree $$N$$ = order.

$P^N:=\operatorname{span}\left\{\prod_{i=1}^d x_i^{n_i}:\sum n_i\le N\right\}.$
order
__init__(spatial_dim: int, order: int) None[source]
class modepy.QN(spatial_dim: int, order: int)[source]

The function space of polynomials with maximum degree $$N$$ = order:

$Q^N:=\operatorname{span} \left \{\prod_{i=1}^d x_i^{n_i}:\max n_i\le N\right\}.$
order
__init__(spatial_dim: int, order: int) None[source]
modepy.space_for_shape(shape: modepy.shapes.Shape, order: int) [source]

Return an unspecified instance of FunctionSpace suitable for approximation on shape attaining interpolation error of $$O(h^{\text{order}+1})$$.

This functionality provides sets of basis functions for the reference elements in modepy.shapes.

class modepy.modes.RealValueT

TypeVar for basis function inputs and outputs, can be one of numpy.ndarray, pymbolic.primitives.Expression or a numbers.Number.

## Basis Retrieval¶

exception modepy.BasisNotOrthonormal[source]
class modepy.Basis[source]
orthonormality_weight() [source]

Can raise BasisNotOrthonormal if the basis does not have a weight.

mode_ids

A tuple of of mode (basis function) identifiers, one for each basis function. Mode identifiers should generally be viewed as opaque. They are hashable. For some bases, they are tuples of length matching the number of dimensions and indicating the order along each reference axis.

functions

A tuple of (callable) basis functions of length matching mode_ids. Each function takes a vector of $$(r, s, t)$$ reference coordinates (depending on dimension) as input.

A tuple of basis functions of length matching mode_ids. Each function takes a vector of $$(r, s, t)$$ reference coordinates (depending on dimension) as input.

modepy.basis_for_space(space: modepy.spaces.FunctionSpace, shape: modepy.shapes.Shape) [source]
modepy.orthonormal_basis_for_space(space: modepy.spaces.FunctionSpace, shape: modepy.shapes.Shape) [source]
modepy.monomial_basis_for_space(space: modepy.spaces.FunctionSpace, shape: modepy.shapes.Shape) [source]

## Jacobi polynomials¶

modepy.jacobi(alpha: float, beta: float, n: int, x: modepy.modes.RealValueT) [source]

Evaluate Jacobi polynomials of type $$(\alpha, \beta)$$, with $$\alpha, \beta > -1$$, and order n at a vector of points x. The points x must lie on the interval $$[-1, 1]$$.

The polynomials are normalized to be orthonormal with respect to the Jacobi weight $$(1 - x)^\alpha (1 + x)^\beta$$.

Observe that choosing $$\alpha = \beta = 0$$ will yield the Legendre polynomials.

Returns

a vector of $$P^{(\alpha, \beta)}_n$$ evaluated at all x.

modepy.grad_jacobi(alpha: float, beta: float, n: int, x: modepy.modes.RealValueT) [source]

Evaluate the derivative of jacobi(), with the same meanings and restrictions for all arguments.

## Conversion to Symbolic¶

modepy.symbolicize_function(f: Callable[[modepy.modes.RealValueT], Union[modepy.modes.RealValueT, Tuple[modepy.modes.RealValueT, ...]]], dim: int, ref_coord_var_name: str = 'r') Union[modepy.modes.RealValueT, Tuple[modepy.modes.RealValueT, ...]][source]

For a function f (basis or gradient) returned by one of the functions in this module, return a pymbolic expression representing the same function.

Parameters

dim – the number of dimensions of the reference element on which basis is defined.

New in version 2020.2.

class modepy.TensorProductBasis(bases_1d: Sequence[Sequence[Callable[[numpy.ndarray], numpy.ndarray]]], grad_bases_1d: Sequence[Sequence[Callable[[numpy.ndarray], Tuple[numpy.ndarray, ...]]]], orth_weight: Optional[float])[source]

Adapts multiple one-dimensional bases into a tensor product basis.

__init__(bases_1d: Sequence[Sequence[Callable[[numpy.ndarray], numpy.ndarray]]], grad_bases_1d: Sequence[Sequence[Callable[[numpy.ndarray], Tuple[numpy.ndarray, ...]]]], orth_weight: Optional[float]) None[source]
Parameters
• bases_1d – a sequence (one entry per axis/dimension) of sequences (representing the basis) of 1D functions representing the approximation basis.

• grad_bases_1d – a sequence (one entry per axis/dimension) representing the derivatives of bases_1d.

## PKDO basis functions¶

modepy.modes.pkdo_2d(order: Tuple[int, int], rs: numpy.ndarray) [source]

Evaluate a 2D orthonormal (with weight 1) polynomial on the unit simplex.

Parameters
• order – A tuple (i, j) representing the order of the polynomial.

• rsrs[0], rs[1] are arrays of $$(r,s)$$ coordinates. (See Coordinates on the triangle)

Returns

a vector of values of the same length as the rs arrays.

See the following publications:

• Proriol, Joseph. “Sur une famille de polynomes á deux variables orthogonaux dans un triangle.” CR Acad. Sci. Paris 245 (1957): 2459-2461.

• Koornwinder, T. “Two-variable analogues of the classical orthogonal polynomials.” Theory and Applications of Special Functions. 1975, pp. 435-495.

• Dubiner, Moshe. “Spectral Methods on Triangles and Other Domains.” Journal of Scientific Computing 6, no. 4 (December 1, 1991): 345–390. http://dx.doi.org/10.1007/BF01060030

modepy.modes.grad_pkdo_2d(order: Tuple[int, int], rs: numpy.ndarray) [source]

Evaluate the derivatives of pkdo_2d().

Parameters
• order – A tuple (i, j) representing the order of the polynomial.

• rsrs[0], rs[1] are arrays of $$(r, s)$$ coordinates. (See Coordinates on the triangle)

Returns

a tuple of vectors (dphi_dr, dphi_ds), each of the same length as the rs arrays.

See the following publications:

• Proriol, Joseph. “Sur une famille de polynomes á deux variables orthogonaux dans un triangle.” CR Acad. Sci. Paris 245 (1957): 2459-2461.

• Koornwinder, T. “Two-variable analogues of the classical orthogonal polynomials.” Theory and Applications of Special Functions. 1975, pp. 435-495.

• Dubiner, Moshe. “Spectral Methods on Triangles and Other Domains.” Journal of Scientific Computing 6, no. 4 (December 1, 1991): 345–390. http://dx.doi.org/10.1007/BF01060030

modepy.modes.pkdo_3d(order: Tuple[int, int, int], rst: numpy.ndarray) [source]

Evaluate a 2D orthonormal (with weight 1) polynomial on the unit simplex.

Parameters
• order – A tuple (i, j, k) representing the order of the polynomial.

• rsrst[0], rst[1], rst[2] are arrays of $$(r, s, t)$$ coordinates. (See Coordinates on the tetrahedron)

Returns

a vector of values of the same length as the rst arrays.

See the following publications:

• Proriol, Joseph. “Sur une famille de polynomes á deux variables orthogonaux dans un triangle.” CR Acad. Sci. Paris 245 (1957): 2459-2461.

• Koornwinder, T. “Two-variable analogues of the classical orthogonal polynomials.” Theory and Applications of Special Functions. 1975, pp. 435-495.

• Dubiner, Moshe. “Spectral Methods on Triangles and Other Domains.” Journal of Scientific Computing 6, no. 4 (December 1, 1991): 345–390. http://dx.doi.org/10.1007/BF01060030

modepy.modes.grad_pkdo_3d(order: Tuple[int, int, int], rst: numpy.ndarray) [source]

Evaluate the derivatives of pkdo_3d().

Parameters
• order – A tuple (i, j, k) representing the order of the polynomial.

• rsrs[0], rs[1], rs[2] are arrays of $$(r,s,t)$$ coordinates. (See Coordinates on the tetrahedron)

Returns

a tuple of vectors (dphi_dr, dphi_ds, dphi_dt), each of the same length as the rst arrays.

See the following publications:

• Proriol, Joseph. “Sur une famille de polynomes á deux variables orthogonaux dans un triangle.” CR Acad. Sci. Paris 245 (1957): 2459-2461.

• Koornwinder, T. “Two-variable analogues of the classical orthogonal polynomials.” Theory and Applications of Special Functions. 1975, pp. 435-495.

• Dubiner, Moshe. “Spectral Methods on Triangles and Other Domains.” Journal of Scientific Computing 6, no. 4 (December 1, 1991): 345–390. http://dx.doi.org/10.1007/BF01060030

## Monomials¶

modepy.modes.monomial(order: Tuple[int, ...], rst: numpy.ndarray) [source]

Evaluate the monomial of order order at the points rst.

Parameters
• order – A tuple (i, j,…) representing the order of the polynomial.

• rstrst[0], rst[1] are arrays of $$(r, s, ...)$$ coordinates. (See Coordinates on the triangle)

modepy.modes.grad_monomial(order: Tuple[int, ...], rst: numpy.ndarray) Tuple[modepy.modes.RealValueT, ...][source]

Evaluate the derivative of the monomial of order order at the points rst.

Parameters
• order – A tuple (i, j,…) representing the order of the polynomial.

• rstrst[0], rst[1] are arrays of $$(r, s, ...)$$ coordinates. (See Coordinates on the triangle)

Returns

a tuple of vectors (dphi_dr, dphi_ds, dphi_dt, ….), each of the same length as the rst arrays.

New in version 2016.1.