comparison sbpD2.jl @ 8:433008d3b7d3

Move stencil to its own file
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 17 Dec 2018 14:30:59 +0100
parents 2737156fb884
children 55fea1ceb6aa
comparison
equal deleted inserted replaced
7:99591b5c34a6 8:433008d3b7d3
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{T}
15 range::NTuple{2,Int}
16 weights::Vector{T} # TBD: Should this be a tuple?
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 function flip(s::Stencil)
27 range = (-s.range[2], -s.range[1])
28 s = Stencil(range, s.weights(end:-1:1))
29 end
30
31 # Provides index into the Stencil based on offset for the root element
32 function Base.getindex(s::Stencil, i::Int)
33 if s.range[1] <= i <= s.range[2]
34 return s.weights[1 + i - s.range[1]]
35 else
36 return 0
37 end
38 end
39
40 function apply(s::Stencil, v::AbstractVector, i::Int)
41 w = zero(v[0])
42 for j ∈ i+(s.range[1]:s.range[2])
43 w += v[j]
44 end
45 return w
46 end