Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/stencil.jl @ 866:1784b1c0af3e feature/laplace_opset
Merge with default
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 19 Jan 2022 14:44:24 +0100 |
parents | 4433be383840 |
children | 313648b01504 11767fbb29f4 |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Fri Jul 02 14:23:33 2021 +0200 +++ b/src/SbpOperators/stencil.jl Wed Jan 19 14:44:24 2022 +0100 @@ -1,10 +1,10 @@ export CenteredStencil -struct Stencil{T<:Real,N} +struct Stencil{T,N} range::Tuple{Int,Int} weights::NTuple{N,T} - function Stencil(range::Tuple{Int,Int},weights::NTuple{N,T}) where {T <: Real, N} + function Stencil(range::Tuple{Int,Int},weights::NTuple{N,T}) where {T, N} @assert range[2]-range[1]+1 == N new{T,N}(range,weights) end @@ -15,13 +15,19 @@ Create a stencil with the given weights with element `center` as the center of the stencil. """ -function Stencil(weights::Vararg{Number}; center::Int) +function Stencil(weights::Vararg{T}; center::Int) where T # Type parameter T makes sure the weights are valid for the Stencil constuctors and throws an earlier, more readable, error N = length(weights) range = (1, N) .- center return Stencil(range, weights) end +function Stencil{T}(s::Stencil) where T + return Stencil(s.range, T.(s.weights)) +end + +Base.convert(::Type{Stencil{T}}, stencil) where T = Stencil{T}(stencil) + function CenteredStencil(weights::Vararg) if iseven(length(weights)) throw(ArgumentError("a centered stencil must have an odd number of weights."))