Mercurial > repos > public > sbplib_julia
comparison sbpD2.jl @ 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 |
comparison
equal
deleted
inserted
replaced
2:43be32298ae2 | 3:19492ab142c3 |
---|---|
8 end | 8 end |
9 | 9 |
10 function closureSize(D::D2)::Int | 10 function closureSize(D::D2)::Int |
11 return length(quadratureClosure) | 11 return length(quadratureClosure) |
12 end | 12 end |
13 | |
14 struct Stencil | |
15 range::NTuple{2,Int} | |
16 weights::Vector{Float64} | |
17 function Stencil(range, weights) | |
18 width = range[2]-range[1]+1 | |
19 if width != length(weights) | |
20 error("The width and the number of weights must be the same") | |
21 end | |
22 new(range, weights) | |
23 end | |
24 end | |
25 | |
26 # Provides index into the Stencil based on offset for the root element | |
27 function Base.getindex(s::Stencil, i::Int) | |
28 if s.range[1] <= i <= s.range[2] | |
29 return s.weights[1 + i - s.range[1]] | |
30 else | |
31 return 0 | |
32 end | |
33 end | |
34 | |
35 function apply(s::Stencil, v::AbstractVector, i::Int) | |
36 w = zero(v[0]) | |
37 for j ∈ i+(s.range[1]:s.range[2]) | |
38 w += v[j] | |
39 end | |
40 return w | |
41 end |