Mercurial > repos > public > sbplib_julia
changeset 3:19492ab142c3
Add 1d stencil type
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Dec 2018 12:53:00 +0100 |
parents | 43be32298ae2 |
children | ef878a3df87d |
files | sbpD2.jl |
diffstat | 1 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/sbpD2.jl Mon Dec 17 12:45:30 2018 +0100 +++ b/sbpD2.jl Mon Dec 17 12:53:00 2018 +0100 @@ -10,3 +10,32 @@ function closureSize(D::D2)::Int return length(quadratureClosure) end + +struct Stencil + range::NTuple{2,Int} + weights::Vector{Float64} + function Stencil(range, weights) + width = range[2]-range[1]+1 + if width != length(weights) + error("The width and the number of weights must be the same") + end + new(range, weights) + end +end + +# Provides index into the Stencil based on offset for the root element +function Base.getindex(s::Stencil, i::Int) + if s.range[1] <= i <= s.range[2] + return s.weights[1 + i - s.range[1]] + else + return 0 + end +end + +function apply(s::Stencil, v::AbstractVector, i::Int) + w = zero(v[0]) + for j ∈ i+(s.range[1]:s.range[2]) + w += v[j] + end + return w +end