Mercurial > repos > public > sbplib_julia
changeset 8:433008d3b7d3
Move stencil to its own file
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Dec 2018 14:30:59 +0100 |
parents | 99591b5c34a6 |
children | aafc4bdbe675 7f075bacbd68 |
files | diffOp.jl sbp.jl sbpD2.jl stencil.jl |
diffstat | 4 files changed, 36 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/diffOp.jl Mon Dec 17 14:30:14 2018 +0100 +++ b/diffOp.jl Mon Dec 17 14:30:59 2018 +0100 @@ -29,7 +29,7 @@ end # u = L*v -function apply(L::Laplace, u::AbstractVector, v::AbstractVector)::AbstractVector +function apply(L::Laplace1D, u::AbstractVector, v::AbstractVector)::AbstractVector N = closureSize(L.op) M = length(v)
--- a/sbp.jl Mon Dec 17 14:30:14 2018 +0100 +++ b/sbp.jl Mon Dec 17 14:30:59 2018 +0100 @@ -1,5 +1,6 @@ module sbp include("grid.jl") include("diffOp.jl") +include("stencil.jl") include("sbpD2.jl") end # module
--- a/sbpD2.jl Mon Dec 17 14:30:14 2018 +0100 +++ b/sbpD2.jl Mon Dec 17 14:30:59 2018 +0100 @@ -9,38 +9,4 @@ function closureSize(D::D2)::Int return length(quadratureClosure) -end - -struct Stencil{T} - range::NTuple{2,Int} - weights::Vector{T} # TBD: Should this be a tuple? - 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 - -function flip(s::Stencil) - range = (-s.range[2], -s.range[1]) - s = Stencil(range, s.weights(end:-1:1)) -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 +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stencil.jl Mon Dec 17 14:30:59 2018 +0100 @@ -0,0 +1,33 @@ +struct Stencil + range::NTuple{2,Int} + weights::Vector # TBD: Should this be a tuple? + 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 + +function flip(s::Stencil) + range = (-s.range[2], -s.range[1]) + s = Stencil(range, s.weights[end:-1:1]) +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