archimedes.approximation.ConcatBasis¶

class archimedes.approximation.ConcatBasis(pieces: tuple[Basis, ...], quad_rule: Quadrature)¶

A basis made of combining other bases.

The functions in this basis are the set of functions from one or more bases:

\[\Phi(x) = \big[\, \Phi_1(x) ~ \Phi_2(x) ~ \cdots \,\big]\]

This is a direct sum of the spaces, not a linear combination.

Parameters:
  • pieces (tuple of Basis) – The bases to concatenate, in order. Must all report the same Parameters type (i.e. live on the same kind of domain: interval, half-line, or real-line), but may otherwise be unrelated families.

  • quad_rule (Quadrature) – This basis’s default quadrature rule. There is no “natural rule” for an arbitrarily concatenated basis, so this is required.

Examples

Augment a quadratic polynomial basis with four sine modes:

>>> import numpy as np
>>> from archimedes.approximation import ConcatBasis, FourierBasis, MonomialBasis
>>> from archimedes.quadrature import gauss_legendre
>>> poly = MonomialBasis(3)
>>> sines = FourierBasis(4, kind="sine")
>>> basis = ConcatBasis((poly, sines), quad_rule=gauss_legendre(16))
>>> basis.n_basis
7
>>> basis.evaluate(np.array([0.0, 0.5])).shape
(2, 7)

A spectral-element “vertex + bubble” basis pairs two linear Lagrange vertex functions (which carry the boundary values) with interior Legendre modes that vanish at both endpoints:

>>> from archimedes.approximation import (
...     ConstrainedBasis,
...     LagrangeBasis,
...     OrthogonalPolynomialBasis,
... )
>>> from archimedes.measure import LegendreMeasure
>>> vertex = LagrangeBasis(reference_nodes=np.array([-1.0, 1.0]))
>>> legendre = OrthogonalPolynomialBasis(LegendreMeasure(), 6)
>>> bubble = ConstrainedBasis.dirichlet(legendre)
>>> sem = ConcatBasis((vertex, bubble), quad_rule=gauss_legendre(8))
>>> sem.n_basis
6
>>> sem.boundary_dofs()
(0, 1)

Methods

boundary_dofs([order])

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

evaluate(x[, deriv, side])

Evaluate all n_basis basis functions at x.

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

Total number of functions across all pieces.

ndim

Number of independent variables the basis functions take.

pieces

quad_rule

__init__(pieces: tuple[Basis, ...], quad_rule: Quadrature) → 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, *, side: str = RIGHT, **domain_kwargs)¶

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¶

Total number of functions across all pieces.

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.