Mercurial > repos > public > sbplib_julia
changeset 83:b795ec7f9ca0 cell_based_test
Merge
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 24 Jan 2019 17:46:57 +0100 |
parents | 45dece5e4928 (diff) fbf7398f8154 (current diff) |
children | 8d505e9bc715 |
files | diffOp.jl sbpD2.jl stencil.jl |
diffstat | 3 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/diffOp.jl Thu Jan 24 14:38:14 2019 +0100 +++ b/diffOp.jl Thu Jan 24 17:46:57 2019 +0100 @@ -60,8 +60,10 @@ return uᵢ end +using UnsafeArrays + # u = L*v -@inline function apply(L::Laplace{2}, v::AbstractVector, i::Int) +function apply(L::Laplace{2}, v::AbstractVector, i::Int) h = Grid.spacings(L.grid) li = LinearIndices(L.grid.numberOfPointsPerDim) @@ -69,10 +71,10 @@ I = ci[i] # 2nd x-derivative - vx = @inbounds view(v, view(li,:,I[2])) + @inbounds vx = uview(v, uview(li,:,I[2])) uᵢ = apply(L.op, h[1], vx , I[1]) # 2nd y-derivative - vy = @inbounds view(v, view(li,I[1],:)) + @inbounds vy = uview(v, uview(li,I[1],:)) uᵢ += apply(L.op, h[2], vy, I[2]) return uᵢ
--- a/sbpD2.jl Thu Jan 24 14:38:14 2019 +0100 +++ b/sbpD2.jl Thu Jan 24 17:46:57 2019 +0100 @@ -5,11 +5,11 @@ N = length(v) if i ∈ range(1; length=cSize) - uᵢ = @inbounds apply(op.closureStencils[i], v, i)/h^2 + @inbounds uᵢ = apply(op.closureStencils[i], v, i)/h^2 elseif i ∈ range(N - cSize+1, length=cSize) - uᵢ = @inbounds Int(op.parity)*apply(flip(op.closureStencils[N-i+1]), v, i)/h^2 + @inbounds uᵢ = Int(op.parity)*apply(flip(op.closureStencils[N-i+1]), v, i)/h^2 else - uᵢ = @inbounds apply(op.innerStencil, v, i)/h^2 + @inbounds uᵢ = apply(op.innerStencil, v, i)/h^2 end return uᵢ
--- a/stencil.jl Thu Jan 24 14:38:14 2019 +0100 +++ b/stencil.jl Thu Jan 24 17:46:57 2019 +0100 @@ -18,17 +18,18 @@ # 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 + @boundscheck if i < s.range[1] || s.range[2] < i return eltype(s.weights)(0) end + + return s.weights[1 + i - s.range[1]] end -@inline function apply(s::Stencil, v::AbstractVector, i::Int) +Base.@propagate_inbounds function apply(s::Stencil, v::AbstractVector, i::Int) w = zero(eltype(v)) for j ∈ s.range[1]:s.range[2] - @inbounds w += s[j]*v[i+j] + @inbounds weight = s[j] + w += weight*v[i+j] end return w end