CompactBases.jl

CompactBases.jl is a package for various bases for function approximation with compact support in the framework of ContinuumArrays

CompactBases logo

Example usage

julia> a,b = 0.0,1.0 # Extents
(0.0, 1.0)

julia> N = 13 # Number of nodes
13

julia> k = 5 # Order of B-splines
5

julia> x = range(a, stop=b, length=1000)
0.0:0.001001001001001001:1.0

julia> Δx = (b-a)/(N+1) # Grid spacing
0.07142857142857142

julia> # Standard, uniform finite-differences
           fd = FiniteDifferences(N, Δx)
Finite differences basis {Float64} on 0.0..1.0 with 13 points spaced by Δx = 0.07142857142857142

julia> # Staggered, uniform finite-differences
           sfd_uni = StaggeredFiniteDifferences(N, Δx)
Staggered finite differences basis {Float64} on 0.0..0.9642857142857144 with 13 points spaced by ρ = 0.07142857142857142

julia> # Staggered, non-uniform finite-differences
           sfd_nonuni = StaggeredFiniteDifferences(0.01, 0.5, 0.1, b)
Staggered finite differences basis {Float64} on 0.0..1.1112312795594823 with 39 points

julia> # Finite-element boundaries
           tf = range(a, stop=b, length=N+2)
0.0:0.07142857142857142:1.0

julia> using LazyArrays, FillArrays

julia> # We can vary the polynomial order in each element
           forder = Vcat(7, Fill(4,length(tf)-2))
14-element ApplyArray{Int64,1,typeof(vcat),Tuple{Int64,Fill{Int64,1,Tuple{Base.OneTo{Int64}}}}}:
 7
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4

julia> # By indexing the second dimension, we can implement Dirichlet0
           # boundary conditions.
           fem = FEDVR(tf, forder)[:,2:end-1]
FEDVR{Float64} basis with 14 elements on 0.0..1.0, restricted to elements 1:14, basis functions 2..45 ⊂ 1..46

julia> tb = ExpKnotSet(k, -2.0, log10(b), N+1)
23-element ExpKnotSet{5,5,5,Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Array{Float64,1}}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.01
 0.014251026703029978
 0.020309176209047358
 0.028942661247167503
 0.04124626382901352
 0.05878016072274912
 0.0837677640068292
 0.11937766417144363
 0.17012542798525887
 0.24244620170823283
 0.3455107294592219
 0.4923882631706739
 0.7017038286703828
 1.0
 1.0
 1.0
 1.0
 1.0

julia> splines = BSpline(tb)[:,2:end-1]
BSpline{Float64} basis with ExpKnotSet(Float64) of  on order k = 5 (quartic) on 0,0.01..1.0 (14 intervals), restricted to basis functions 2..17 ⊂ 1..18

Simple example

Reference

CompactBases.orthogonality — Function
orthogonality(B)

Returns the BasisOrthogonality trait of the basis B.

Examples

julia> orthogonality(BSpline(LinearKnotSet(7, 0, 1, 11)))
CompactBases.NonOrthogonal()

julia> orthogonality(FEDVR(range(0, stop=1, length=11), 7))
CompactBases.Orthonormal()

julia> orthogonality(StaggeredFiniteDifferences(0.1, 0.3, 0.1, 10.0))
CompactBases.Orthonormal()

julia> orthogonality(FiniteDifferences(range(0, stop=1, length=11)))
CompactBases.Orthogonal()
source
CompactBases.centers — Function
centers(B)

Return the locations of the mass centers of all basis functions of B; for orthogonal bases such as finite-differences and FE-DVR, this is simply locs, i.e. the location of the quadrature nodes.

source
CompactBases.metric_shape — Function
metric_shape(B)

Returns the shape of the metric or mass matrix of the basis B, i.e. Diagonal, BandedMatrix, etc.

source
CompactBases.operator_matrix — Function
operator_matrix(T, Ac, ops..., B)

Allocate an uninitialized matrix with element type T, suitable for storing the matrix representation of the operator product ops... between the bra basis Ac and the ket basis B. See also operator_matrix!.

source
CompactBases.operator_matrix! — Function
operator_matrix!(dest, Ac, ops..., B)

Compute the matrix representation of the operator product ops... between the bra basis Ac and the ket basis B, storing the result in dest, which has been allocated by operator_matrix.

source
CompactBases.materialize_operator — Function
materialize_operator(Ac, ops..., B)

Compute the matrix representation of the operator product ops... between the bra basis Ac and the ket basis B. The default implementation allocates the matrix via operator_matrix and fills it via operator_matrix!, but this method may be overloaded for operators whose representation is not a plain matrix (e.g. implicit finite-differences).

source
CompactBases.change_interval! — Function
change_interval!(xs, ws, x, w[, a=0, b=1, γ=1])

Transform the Gaußian quadrature roots x and weights w on the elementary interval [-1,1] to the interval [γ*a,γ*b] and store the result in xs and ws, respectively. γ is an optional root of unity, used to complex-rotate the roots (but not the weights).

source
CompactBases.LinearOperator — Type
LinearOperator(A, B⁻¹, temp)

A helper object used to apply the action of a linear operator, whose matrix representation is given by A, in the basis whose metric inverse is B⁻¹. For orthogonal bases (such as e.g. FiniteDifferences and FEDVR), only multiplication by A is necessary, but non-orthonal bases (such as BSpline) necessitates the application of the metric inverse as well.

source