Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/stencil.jl @ 633:a78bda7084f6 feature/quadrature_as_outer_product
Merge w. default
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 01 Jan 2021 16:34:55 +0100 |
parents | 03ef4d4740ab |
children | e14627e79a54 |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Mon Nov 30 16:28:32 2020 +0100 +++ b/src/SbpOperators/stencil.jl Fri Jan 01 16:34:55 2021 +0100 @@ -8,6 +8,29 @@ end end +""" + Stencil(weights::NTuple; center::Int) + +Create a stencil with the given weights with element `center` as the center of the stencil. +""" +function Stencil(weights::NTuple; center::Int) + N = length(weights) + range = (1, N) .- center + + return Stencil(range, weights) +end + +""" + scale(s::Stencil, a) + +Scale the weights of the stencil `s` with `a` and return a new stencil. +""" +function scale(s::Stencil, a) + return Stencil(s.range, a.*s.weights) +end + +Base.eltype(::Stencil{T}) where T = T + function flip(s::Stencil) range = (-s.range[2], -s.range[1]) return Stencil(range, reverse(s.weights)) @@ -16,7 +39,7 @@ # Provides index into the Stencil based on offset for the root element @inline function Base.getindex(s::Stencil, i::Int) @boundscheck if i < s.range[1] || s.range[2] < i - return eltype(s.weights)(0) + return zero(eltype(s)) end return s.weights[1 + i - s.range[1]] end