API

Univariate bases

Smolyak bases

SpectralKit.SmolyakBasis — Type
SmolyakBasis(family, kind, domain_transformations, level)
SmolyakBasis(
    family,
    kind,
    domain_transformations,
    level,
    grid_level
)

Smolyak (sparse) basis from family, using the given kind.

domain_transformations::Tuple determine the domain and the relevant transformation to the domain of family along each coordinate.

level is a SmolyakLevel, specifying the number of blocks used to build the grid.

grid_level can be either nothing, in which case it defaults to be the same as level, or a SmolyakLevel.

Miscellaneous

As a convenience, smolyak_basis[i] returns an univariate basis along coordinate i.

source
SpectralKit.SmolyakLevel — Type
SmolyakLevel(; total, each)

Level specification for a Smolyak basis.

total constrains the sum of levels in all axes.

each constrains the level along each axis.

Formally, $0 ≤ ℓᵢ ≤ each ∀ i; ∑ᵢ ℓᵢ ≤ total$ where each i is an axis.

If each > total, the normalization each = total is set with a warning.

source

Families and grid types

SpectralKit.Endpoints — Type
struct Endpoints

Chebyshev-Lobatto grid. The extrema of Chebyshev polynomials, including endpoints of [-1,1].

Note

For small dimensions may fall back to a grid that does not contain endpoints.

source

Domain transformations

SpectralKit.BoundedLinear — Type
BoundedLinear(lower, upper)
BoundedLinear(lower, upper, outside_domain)

Transform the domain to y ∈ (lower, upper), using a linear mapping.

lower < upper is enforced.

outside_domain determines how values outside [lower, upper] are handled. See ErrorOutsideDomain and NearestInDomain.

source
SpectralKit.SemiInfRational — Type
SemiInfRational(; endpoint, scale)

The domian transformed to [endpoint, Inf) (when scale > 0) or (-Inf,endpoint] (when scale < 0) using $y = endpoint + scale ⋅ (1 + x) / (1 - x)$.

When used with Chebyshev polynomials, also known as a “rational Chebyshev” basis.

Example mappings for the domain $(-1,1)$

  • $-1/2 ↦ endpoint + scale / 3$
  • $0 ↦ endpoint + scale$
  • $1/2 ↦ endpoint + 3 ⋅ scale$
source
SpectralKit.InfRational — Type
InfRational(center, scale)

The domain transformed to (-Inf, Inf) using $y = center + scale ⋅ x / √(1 - x^2)$, with scale > 0.

Example mappings (for domain $(-1,1)$)

  • $0 ↦ center$
  • $±0.5 ↦ center ± scale / √3$
source

API for all bases

SpectralKit.is_function_basis — Function

is_function_basis(::Type{F})

is_function_basis(f::F)

Test if the argument (value or type) is a function basis, supporting the following interface:

  • domain for querying the domain,

  • dimension for the dimension,

  • basis_at for function evaluation,

  • grid to obtain collocation points.

  • for multivariate bases: length; and getindex which returns a compatible marginal basis

linear_combination and collocation_matrix are also supported, building on the above.

Can be used on both types (preferred) and values (for convenience).

source
SpectralKit.domain — Function

domain(basis)

The domain of a function basis. A tuple for multivariate bases.

domain(transformation)

The (co)domain of a transformation. The “other” domain (codomain, depending on the mapping) is provided explicitly for transformations, and should be compatible with thedomain of the basis.

source
SpectralKit.linear_combination — Function
linear_combination(basis, θ, x)

Evaluate the linear combination of $∑ θₖ⋅fₖ(x)$ of function basis $f₁, …$ at x, for the given order.

The length of θ should equal dimension(θ).

source
linear_combination(basis, θ)

Return a callable that calculates linear_combination(basis, θ, x) when called with x.

You can use linear_combination(basis, θ) ∘ transformation for domain transformations, though working with basis ∘ transformation may be preferred.

source
SpectralKit.basis_at — Function

basis_at(basis, x)

Return an iterable with known element type and length (Base.HasEltype(), Base.HasLength()) of basis functions in basis evaluated at x.

Univariate bases operate on real numbers, while for multivariate bases, Tuples or StaticArrays.SVector are preferred for performance, though all <:AbstractVector types should work.

Methods are type stable.

Note

Consequences are undefined when evaluating outside the domain.

source
SpectralKit.grid — Function

grid([T], basis)

Return an iterator for the grid recommended for collocation, with dimension(basis) elements.

T for the element type of grid coordinates, and defaults to Float64. Methods are type stable.

source
SpectralKit.collocation_matrix — Function
collocation_matrix(basis)
collocation_matrix(basis, x)

Convenience function to obtain a “collocation matrix” at points x, which is assumed to have a concrete eltype. The default is x = grid(basis), specialized methods may exist for this when it makes sense.

The collocation matrix may not be an AbstractMatrix, all it needs to support is C \ y for compatible vectors y = f.(x).

Methods are type stable.

source
SpectralKit.constant_coefficients — Function

constant_coefficients(basis, y)

Return coefficients θ so that linear_combination(basis, θ, x) ≈ y for all x in the domain.

The value is a vector, but may not be mutable. collect the result if you want to modify.

source
SpectralKit.adjust_coefficients — Function

adjust_coefficients(θ1, basis1, basis2)

Return a set of coefficients θ2 for basis2 such that

linear_combination(basis1, θ1, x) ≈ linear_combination(basis2, θ2, x)

for any x in the domain. In practice this means either padding with zeros, or truncating the coefficients.

Throw an error if this is not possible.

source

Transformations

SpectralKit.transform_to — Function

transform_to(domain, transformation, x)

Transform x to domain using transformation.

domain can be replaced by basis for a shortcut which uses domain(basis).

Transformations to infinity make sure that $\pm\infty$ is mapped to the limit for values and derivatives.

source
SpectralKit.transform_from — Function

transform_from(domain, transformation, x)

Transform x from domain using transformation.

domain can be replaced by basis for a shortcut which uses domain(basis).

Transformations to infinity make sure that $\pm\infty$ is mapped to the limit for values and derivatives.

source