archimedes.approximation.LagrangeBasis¶

class archimedes.approximation.LagrangeBasis(
reference_nodes: ndarray,
node_family: Callable[[int], ndarray] | None = None,
)¶

Lagrange (nodal) interpolating polynomial basis

The basis is constructed from Lagrange cardinal polynomials \(\{\ell_0, \ldots, \ell_{n-1}\}\) for a fixed set of nodes.

Evaluated via the first, “true” barycentric formula ([1], [2]):

\[\ell_i(x) = \frac{w_i / (x - x_i)}{\sum_j w_j / (x - x_j)}, \qquad w_i = \frac{1}{\prod_{j \neq i} (x_i - x_j)}\]

where \(\ell_i(x_k) = \delta_{ik}\) at \(x = x_k\).

Derivatives of every order are supported and exact: \(\ell_j^{(k)}\) is itself a polynomial of degree \(\leq n - 1\) and so is represented exactly in this same basis,

\[\ell_j^{(k)}(x) = \sum_i D^k_{ij} \, \ell_i(x),\]

where \(D_{ij} = \ell_j'(x_i)\) is the classical differentiation matrix.

Typically not constructed directly; instead, one usually works with a PiecewiseBasis based on Lagrange elements or the higher-level FunctionSpace constructed from FunctionSpace.piecewise(kind="lagrange", ...).

Parameters:
  • reference_nodes (array_like) – Distinct interpolation nodes on the reference domain [-1, 1].

  • node_family (callable, optional) –

    n -> nodes, used internally to pick the node set whenever a differently sized basis of the same kind is needed. Defaults to Gauss-Lobatto.

    Any n distinct nodes span the same \(P_{n-1}\), so the choice affects only conditioning and which degrees of freedom are nodal.

See also

FunctionSpace.piecewise

Convenience constructor for a FunctionSpace that supports piecewise Lagrange elements.

References

Methods

boundary_dofs([order])

Indices of the degrees of freedom at the left/right ends of the domain.

equispaced(n)

Construct a Lagrange basis using evenly spaced nodes.

evaluate(x[, deriv, a, b, side])

Evaluate all n_basis basis functions at x.

gauss_legendre(n)

Construct a Lagrange basis using Gauss-Legendre nodes.

gauss_lobatto(n)

Construct a Lagrange basis using Gauss-Lobatto nodes

gauss_radau(n[, endpoint])

Construct a Lagrange basis using Gauss-Radau nodes.

Attributes

Parameters

The target-domain parameters this basis expects.

density

Whether this basis is orthonormal with respect to a probability measure (unit mass) rather than the raw weight of the associated Measure.

n_basis

ndim

Number of independent variables the basis functions take.

node_family

reference_nodes

classmethod equispaced(
n: int,
) → LagrangeBasis¶

Construct a Lagrange basis using evenly spaced nodes.

Parameters:

n (int) – Number of evenly spaced nodes. Also the number of Lagrange basis functions.

Returns:

Lagrange basis with evenly spaced nodes.

Return type:

LagrangeBasis

classmethod gauss_legendre(
n: int,
) → LagrangeBasis¶

Construct a Lagrange basis using Gauss-Legendre nodes.

Parameters:

n (int) – Number of Gauss-Legendre quadrature nodes. Also the number of Lagrange basis functions.

Returns:

Lagrange basis with Gauss-Legendre nodes.

Return type:

LagrangeBasis

classmethod gauss_lobatto(
n: int,
) → LagrangeBasis¶

Construct a Lagrange basis using Gauss-Lobatto nodes

Parameters:

n (int) – Number of Gauss-Lobatto quadrature nodes. Also the number of Lagrange basis functions.

Returns:

Lagrange basis with Gauss-Lobatto nodes.

Return type:

LagrangeBasis

classmethod gauss_radau(
n: int,
endpoint: str = 'left',
) → LagrangeBasis¶

Construct a Lagrange basis using Gauss-Radau nodes.

Parameters:
  • n (int) – Number of Gauss-Radau quadrature nodes. Also the number of Lagrange basis functions.

  • endpoint (str, default "left") – Which endpoint to fix (“left” or “right”).

Returns:

Lagrange basis with Gauss-Radau nodes.

Return type:

LagrangeBasis

__init__(
reference_nodes: ndarray,
node_family: Callable[[int], ndarray] | None = None,
) → None¶
boundary_dofs(order: int = 0) → tuple[int | None, int | None]¶

Indices of the degrees of freedom at the left/right ends of the domain.

Can be used for example to set boundary conditions or enforce continuity at the domain endpoints.

Parameters:

order (int, optional) – Derivative order to look up. Default 0 (the endpoint value).

Returns:

left, right – Index into this basis’s functions, or None where there is no degree of freedom of that order at that end.

Return type:

int or None

Notes

Only meaningful for nodal families (e.g. LagrangeBasis) with nodes at the endpoints. Modal families (e.g. OrthogonalPolynomialBasis) and nodal bases with interior-only nodes (Gauss-Legendre points, for instance) do not have boundary DOFs.

evaluate(x, deriv: int = 0, *, a=None, b=None, side: str = RIGHT)¶

Evaluate all n_basis basis functions at x.

Parameters:
  • x (array_like) – Evaluation points, shape (npts,).

  • deriv (int, optional) – Order of derivative to evaluate. Default 0.

  • side ({"right", "left"}, optional) – Which one-sided limit to take where the basis is two-valued. Default "right". Irrelevant for smooth bases.

  • **domain_kwargs – Target-domain parameters; see the subclass docstring.

Returns:

phi – Basis values (or deriv-th derivatives), shape (npts, n_basis).

Return type:

ndarray

property Parameters: type¶

The target-domain parameters this basis expects.

A Parameters subclass (e.g. UnitInterval.Parameters). Returns the type, not an instance.

Determines which reference domain the basis is defined on, for example:

density: bool = False¶

Whether this basis is orthonormal with respect to a probability measure (unit mass) rather than the raw weight of the associated Measure.

Only meaningful for orthogonal polynomial families based on a Measure (in particular OrthogonalPolynomialBasis); other families should leave this False.

property n_basis: int¶
ndim: int = 1¶

Number of independent variables the basis functions take.

Typically 1, since most bases are univariate. TensorBasis is the exception, with one variable per tensored factor.