comparison diffOp.jl @ 108:d0a28888528a cell_based_test

Change input type of apply(::Laplace) to ::DiffOpCartesian
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 08 Feb 2019 12:47:21 +0100
parents e3e32299fe72
children b3fbef345810
comparison
equal deleted inserted replaced
107:e3e32299fe72 108:d0a28888528a
42 end 42 end
43 43
44 return nothing 44 return nothing
45 end 45 end
46 46
47 function apply!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T
48 apply!(D, u, v, Lower, Lower)
49 apply!(D, u, v, Lower, Interior)
50 apply!(D, u, v, Lower, Upper)
51 apply!(D, u, v, Interior, Lower)
52 apply!(D, u, v, Interior, Interior)
53 apply!(D, u, v, Interior, Upper)
54 apply!(D, u, v, Upper, Lower)
55 apply!(D, u, v, Upper, Interior)
56 apply!(D, u, v, Upper, Upper)
57 return nothing
58 end
59
60 function apply!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}, r1::Type{<:Region}, r2::Type{<:Region}) where T
61 N = D.grid.numberOfPointsPerDim
62 closuresize = closureSize(D.op)
63 for I ∈ regionindices(N, closuresize, (r1,r2))
64 @inbounds indextuple = (Index(I[1], r1), Index(I[2], r2))
65 @inbounds u[I] = apply(D, v, indextuple)
66 end
67 return nothing
68 end
69
47 function apply(D::DiffOp, v::AbstractVector)::AbstractVector 70 function apply(D::DiffOp, v::AbstractVector)::AbstractVector
48 u = zeros(eltype(v), size(v)) 71 u = zeros(eltype(v), size(v))
49 apply!(D,v,u) 72 apply!(D,v,u)
50 return u 73 return u
51 end 74 end
65 h = Grid.spacings(L.grid)[1] 88 h = Grid.spacings(L.grid)[1]
66 uᵢ = L.a * apply(L.op, h, v, i) 89 uᵢ = L.a * apply(L.op, h, v, i)
67 return uᵢ 90 return uᵢ
68 end 91 end
69 92
70 function apply!(L::Laplace{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T
71 apply!(L, u, v, Lower, Lower)
72 apply!(L, u, v, Lower, Interior)
73 apply!(L, u, v, Lower, Upper)
74 apply!(L, u, v, Interior, Lower)
75 apply!(L, u, v, Interior, Interior)
76 apply!(L, u, v, Interior, Upper)
77 apply!(L, u, v, Upper, Lower)
78 apply!(L, u, v, Upper, Interior)
79 apply!(L, u, v, Upper, Upper)
80 return nothing
81 end
82
83 function apply!(L::Laplace{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}, r1::Type{<:Region}, r2::Type{<:Region}) where T
84 N = L.grid.numberOfPointsPerDim
85 closuresize = closureSize(L.op)
86 for I ∈ regionindices(N, closuresize, (r1,r2))
87 @inbounds indextuple = (Index(I[1], r1), Index(I[2], r2))
88 @inbounds u[I] = apply(L, v, indextuple)
89 end
90 return nothing
91 end
92
93 using UnsafeArrays 93 using UnsafeArrays
94 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} 94 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2}
95 h = Grid.spacings(L.grid) 95 h = Grid.spacings(L.grid)
96 # 2nd x-derivative 96 # 2nd x-derivative
97 @inbounds vx = uview(v, :, Int(I[2])) 97 @inbounds vx = uview(v, :, Int(I[2]))