Mercurial > repos > public > sbplib_julia
comparison diffOp.jl @ 129:1aaeb46ba5f4 cell_based_test
Improve efficiency of apply by the following:
- Remove divisions in interior loop by storing and multiplying by the reciprocal of grid spacing instead.
- Add @inline to apply(::Laplace
- Remove initialization of w = 0 in apply(::Stencil) by manually unrolling first iteration of the loop.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 14 Feb 2019 16:25:22 +0100 |
parents | 631eb9b35d72 |
children | bb1cc9c7877c c6aaf061c0a9 |
comparison
equal
deleted
inserted
replaced
128:7c0b9bb7ab4d | 129:1aaeb46ba5f4 |
---|---|
111 function apply(L::Laplace{1}, v::AbstractVector, i::Int) | 111 function apply(L::Laplace{1}, v::AbstractVector, i::Int) |
112 uᵢ = L.a * apply(L.op, L.grid.spacing[1], v, i) | 112 uᵢ = L.a * apply(L.op, L.grid.spacing[1], v, i) |
113 return uᵢ | 113 return uᵢ |
114 end | 114 end |
115 | 115 |
116 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} | 116 @inline function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} |
117 # 2nd x-derivative | 117 # 2nd x-derivative |
118 @inbounds vx = view(v, :, Int(I[2])) | 118 @inbounds vx = view(v, :, Int(I[2])) |
119 @inbounds uᵢ = L.a*apply(L.op, L.grid.spacing[1], vx , I[1]) | 119 @inbounds uᵢ = L.a*apply(L.op, L.grid.inverse_spacing[1], vx , I[1]) |
120 # 2nd y-derivative | 120 # 2nd y-derivative |
121 @inbounds vy = view(v, Int(I[1]), :) | 121 @inbounds vy = view(v, Int(I[1]), :) |
122 @inbounds uᵢ += L.a*apply(L.op, L.grid.spacing[2], vy, I[2]) | 122 @inbounds uᵢ += L.a*apply(L.op, L.grid.inverse_spacing[2], vy, I[2]) |
123 return uᵢ | 123 return uᵢ |
124 end | 124 end |
125 | 125 |
126 # Slow but maybe convenient? | 126 # Slow but maybe convenient? |
127 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, i::CartesianIndex{2}) | 127 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, i::CartesianIndex{2}) |