Mercurial > repos > public > sbplib_julia
comparison diffOp.jl @ 99:6b6d680f2e25 cell_based_test
Allow apply(::Laplace) to take Index types
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 06 Feb 2019 09:09:55 +0100 |
parents | 9d53ecca34f7 |
children | a274d6384e91 |
comparison
equal
deleted
inserted
replaced
98:50273f745f05 | 99:6b6d680f2e25 |
---|---|
67 return uᵢ | 67 return uᵢ |
68 end | 68 end |
69 | 69 |
70 using UnsafeArrays | 70 using UnsafeArrays |
71 | 71 |
72 # u = L*v | 72 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} |
73 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::CartesianIndex{2}) | |
74 h = Grid.spacings(L.grid) | 73 h = Grid.spacings(L.grid) |
75 | 74 |
76 # 2nd x-derivative | 75 # 2nd x-derivative |
77 @inbounds vx = uview(v, :, I[2]) | 76 @inbounds vx = uview(v, :, Int(I[2])) |
78 @inbounds uᵢ = apply(L.op, h[1], vx , I[1]) | 77 @inbounds uᵢ = apply(L.op, h[1], vx , I[1]) |
79 # 2nd y-derivative | 78 # 2nd y-derivative |
80 @inbounds vy = uview(v, I[1], :) | 79 @inbounds vy = uview(v, Int(I[1]), :) |
81 @inbounds uᵢ += apply(L.op, h[2], vy, I[2]) | 80 @inbounds uᵢ += apply(L.op, h[2], vy, I[2]) |
82 | 81 |
83 return uᵢ | 82 return uᵢ |
84 end | 83 end |
84 | |
85 # Slow but maybe convenient? | |
86 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, i::CartesianIndex{2}) | |
87 I = Index{Unknown}.(Tuple(i)) | |
88 apply(L, v, I) | |
89 end |