comparison src/SbpOperators/stencil.jl @ 675:1ce3a104afc8 feature/boundary_quads

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 07 Feb 2021 21:28:53 +0100
parents 59a81254fefc
children 9fc6d38da03f
comparison
equal deleted inserted replaced
670:538ccbaeb1f8 675:1ce3a104afc8
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)
21 end 23 end
24
25 function CenteredStencil(weights::Vararg)
26 if iseven(length(weights))
27 throw(ArgumentError("a centered stencil must have an odd number of weights."))
28 end
29
30 r = length(weights) รท 2
31
32 return Stencil((-r, r), weights)
33 end
34
22 35
23 """ 36 """
24 scale(s::Stencil, a) 37 scale(s::Stencil, a)
25 38
26 Scale the weights of the stencil `s` with `a` and return a new stencil. 39 Scale the weights of the stencil `s` with `a` and return a new stencil.