CompactBases.jl
CompactBases.jl is a package for various bases for function approximation with compact support in the framework of ContinuumArrays
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..18Reference
CompactBases.CompactBasis — Type
CompactBasis{T} <: Basis{T}Abstract supertype of all bases defined in this package, i.e. bases consisting of functions with compact support: finite-differences (AbstractFiniteDifferences), FEDVR, and BSpline.
CompactBases.BasisOrthogonality — Type
BasisOrthogonalityBase type for the orthogonality trait of a basis.
CompactBases.Ortho — Type
Ortho <: BasisOrthogonalityIntermediate type for the trait for all orthogonal bases.
CompactBases.Orthogonal — Type
Orthogonal <: OrthoConcrete type for the trait of orthogonal bases, i.e. with diagonal metric.
CompactBases.Orthonormal — Type
Orthonormal <: OrthoConcrete type for the trait of orthonormal bases, i.e. with metric I.
CompactBases.NonOrthogonal — Type
NonOrthogonal <: BasisOrthogonalityConcrete type for the trait of non-orthogonal bases, i.e. with non-diagonal metric.
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()CompactBases.assert_compatible_bases — Function
assert_compatible_bases(A, B)Assert that A and B are compatible for a certain operation, typically a bilinear form.
CompactBases.locs — Function
locs(B)Returns the interpolation nodes of a basis.
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.
CompactBases.vandermonde — Function
vandermonde(B)Returns the Vandermonde matrix suitable for interpolating functions over a basis.
CompactBases.metric — Function
metric(B)Returns the metric or mass matrix of the basis B, equivalent to S=B'B.
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.
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!.
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.
CompactBases.has_operator_matrix — Function
has_operator_matrix(Ac, ops..., B)Returns true if the matrix representation of the operator product ops... between Ac and B is implemented, i.e. if there is an applicable operator_matrix method.
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).
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).
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.
Base.MatrixCompactBases.AbstractFiniteDifferencesCompactBases.AbstractKnotSetCompactBases.ArbitraryKnotSetCompactBases.ArbitraryKnotSetCompactBases.BSplineCompactBases.BSplineCompactBases.BSplineCompactBases.BasisOrthogonalityCompactBases.CompactBasisCompactBases.CoulombDerivativeCompactBases.DensityCompactBases.DiagonalOperatorCompactBases.DiagonalOperatorCompactBases.ExpKnotSetCompactBases.ExpKnotSetCompactBases.FEDVRCompactBases.FiniteDifferencesCompactBases.FunctionProductCompactBases.FunctionProductCompactBases.FunctionProductCompactBases.ImplicitFiniteDifferencesCompactBases.LinearKnotSetCompactBases.LinearKnotSetCompactBases.LinearOperatorCompactBases.NonOrthogonalCompactBases.OrthoCompactBases.OrthogonalCompactBases.OrthonormalCompactBases.ShiftAndInvertCompactBases.StaggeredFiniteDifferencesCompactBases.UnitVectorBase.copyto!Base.copyto!Base.copyto!Base.firstBase.getindexBase.lastBase.lengthBase.stepCompactBases.assert_compatible_basesCompactBases.assert_multiplicitiesCompactBases.basis_overlapCompactBases.basis_transformCompactBases.centersCompactBases.change_interval!CompactBases.deBoorCompactBases.find_intervalCompactBases.findelementCompactBases.has_operator_matrixCompactBases.lagrangeder!CompactBases.leftmultiplicityCompactBases.lgwtCompactBases.local_stepCompactBases.locsCompactBases.materialize_operatorCompactBases.metricCompactBases.metric_shapeCompactBases.nonempty_intervalsCompactBases.num_quadrature_pointsCompactBases.numfunctionsCompactBases.numintervalsCompactBases.operator_matrixCompactBases.operator_matrix!CompactBases.orderCompactBases.orthogonalityCompactBases.rightmultiplicityCompactBases.vandermondeCompactBases.within_intervalCompactBases.within_supportLinearAlgebra.mul!