comparison src/SbpOperators/stencil.jl @ 671:e14627e79a54 feature/stencil_convenience

Add stencil constructor for centered stencils and change from tuple to vararg in stencil constructor taking cneter
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 06 Feb 2021 21:42:57 +0100
parents 03ef4d4740ab
children 59a81254fefc
comparison
equal deleted inserted replaced
664:7d7c1d636de3 671:e14627e79a54
1 export CenteredStencil
2
1 struct Stencil{T<:Real,N} 3 struct Stencil{T<:Real,N}
2 range::Tuple{Int,Int} 4 range::Tuple{Int,Int}
3 weights::NTuple{N,T} 5 weights::NTuple{N,T}
4 6
5 function Stencil(range::Tuple{Int,Int},weights::NTuple{N,T}) where {T <: Real, N} 7 function Stencil(range::Tuple{Int,Int},weights::NTuple{N,T}) where {T <: Real, N}
11 """ 13 """
12 Stencil(weights::NTuple; center::Int) 14 Stencil(weights::NTuple; center::Int)
13 15
14 Create a stencil with the given weights with element `center` as the center of the stencil. 16 Create a stencil with the given weights with element `center` as the center of the stencil.
15 """ 17 """
16 function Stencil(weights::NTuple; center::Int) 18 function Stencil(weights::Vararg{Number}; center::Int)
17 N = length(weights) 19 N = length(weights)
18 range = (1, N) .- center 20 range = (1, N) .- center
19 21
20 return Stencil(range, weights) 22 return Stencil(range, weights)
23 end
24
25
26 function CenteredStencil(weights::Vararg)
27 if iseven(length(weights))
28 throw(ArgumentError("a centered stencil must have an odd number of weights."))
29 end
30
31 r = length(weights) รท 2
32
33 return Stencil((-r, r), weights)
21 end 34 end
22 35
23 """ 36 """
24 scale(s::Stencil, a) 37 scale(s::Stencil, a)
25 38