comparison diffOp.jl @ 82:45dece5e4928 cell_based_test

Use unsafe views
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 24 Jan 2019 17:42:51 +0100
parents e4fa13137d12
children b795ec7f9ca0
comparison
equal deleted inserted replaced
72:4640839b1616 82:45dece5e4928
58 h = Grid.spacings(L.grid)[1] 58 h = Grid.spacings(L.grid)[1]
59 uᵢ = L.a * apply(L.op, h, v, i) 59 uᵢ = L.a * apply(L.op, h, v, i)
60 return uᵢ 60 return uᵢ
61 end 61 end
62 62
63 using UnsafeArrays
64
63 # u = L*v 65 # u = L*v
64 function apply(L::Laplace{2}, v::AbstractVector, i::Int) 66 function apply(L::Laplace{2}, v::AbstractVector, i::Int)
65 h = Grid.spacings(L.grid) 67 h = Grid.spacings(L.grid)
66 68
67 li = LinearIndices(L.grid.numberOfPointsPerDim) 69 li = LinearIndices(L.grid.numberOfPointsPerDim)
68 ci = CartesianIndices(L.grid.numberOfPointsPerDim) 70 ci = CartesianIndices(L.grid.numberOfPointsPerDim)
69 I = ci[i] 71 I = ci[i]
70 72
71 # 2nd x-derivative 73 # 2nd x-derivative
72 vx = view(v, view(li,:,I[2])) 74 vx = uview(v, uview(li,:,I[2]))
73 uᵢ = apply(L.op, h[1], vx , I[1]) 75 uᵢ = apply(L.op, h[1], vx , I[1])
74 # 2nd y-derivative 76 # 2nd y-derivative
75 vy = view(v, view(li,I[1],:)) 77 vy = uview(v, uview(li,I[1],:))
76 uᵢ += apply(L.op, h[2], vy, I[2]) 78 uᵢ += apply(L.op, h[2], vy, I[2])
77 79
78 return uᵢ 80 return uᵢ
79 end 81 end