-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface for general bases (#100)
* add initial interface for general bases * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix least squares in tutorial * fix SpatialDiscretization * format * fix docstring rendering * fix TemporalDiscretization * fix unit tests * add unit tests * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix docstring rendering * use StandardBasis in some examples --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
cc418aa
commit 73ef24a
Showing
12 changed files
with
287 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
AbstractBasis | ||
Abstract type for a basis of a kernel function space. Every basis represents a | ||
set of functions, which can be obtained by indexing the basis object. Every basis | ||
object holds a kernel function and a [`NodeSet`](@ref) of centers and potentially | ||
more fields depending on the concrete basis type. | ||
""" | ||
abstract type AbstractBasis end | ||
|
||
function (basis::AbstractBasis)(x) | ||
return [basis[i](x) for i in eachindex(basis)] | ||
end | ||
|
||
""" | ||
interpolation_kernel(basis) | ||
Return the kernel from a basis. | ||
""" | ||
interpolation_kernel(basis::AbstractBasis) = basis.kernel | ||
|
||
""" | ||
centers(basis) | ||
Return the centers from a basis object. | ||
""" | ||
centers(basis::AbstractBasis) = basis.centers | ||
|
||
""" | ||
order(basis) | ||
Return the order ``m`` of the polynomial, which is needed by this `basis` for | ||
the interpolation, i.e., the polynomial degree plus 1. If ``m = 0``, | ||
no polynomial is added. | ||
""" | ||
order(basis::AbstractBasis) = order(interpolation_kernel(basis)) | ||
dim(basis::AbstractBasis) = dim(basis.centers) | ||
Base.length(basis::AbstractBasis) = length(centers(basis)) | ||
Base.eachindex(basis::AbstractBasis) = Base.OneTo(length(basis)) | ||
function Base.iterate(basis::AbstractBasis, state = 1) | ||
state > length(basis) ? nothing : (basis[state], state + 1) | ||
end | ||
Base.collect(basis::AbstractBasis) = Function[basis[i] for i in 1:length(basis)] | ||
|
||
function Base.show(io::IO, basis::AbstractBasis) | ||
return print(io, | ||
"$(nameof(typeof(basis))) with $(length(centers(basis))) centers and kernel $(interpolation_kernel(basis)).") | ||
end | ||
|
||
@doc raw""" | ||
StandardBasis(centers, kernel) | ||
The standard basis for a function space defined by a kernel and a [`NodeSet`](@ref) of `centers`. | ||
The basis functions are given by | ||
```math | ||
b_j(x) = K(x, x_j) | ||
``` | ||
where `K` is the kernel and `x_j` are the nodes in `centers`. | ||
""" | ||
struct StandardBasis{Kernel} <: AbstractBasis | ||
centers::NodeSet | ||
kernel::Kernel | ||
function StandardBasis(centers::NodeSet, kernel::Kernel) where {Kernel} | ||
if dim(kernel) != dim(centers) | ||
throw(DimensionMismatch("The dimension of the kernel and the centers must be the same")) | ||
end | ||
new{typeof(kernel)}(centers, kernel) | ||
end | ||
end | ||
|
||
Base.getindex(basis::StandardBasis, i) = x -> basis.kernel(x, centers(basis)[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.