comparison diffOp.jl @ 65:7054230b639c cell_based_test

Make dimension a type parameter in Laplace
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 17 Jan 2019 15:22:10 +0100
parents 178a203f3e6d
children 543b7a5ab831
comparison
equal deleted inserted replaced
64:a88222fc01de 65:7054230b639c
45 u = zeros(eltype(v), size(v)) 45 u = zeros(eltype(v), size(v))
46 apply!(D,v,u) 46 apply!(D,v,u)
47 return u 47 return u
48 end 48 end
49 49
50 # Differential operator for a*d^2/dx^2 50 struct Laplace{Dim} <: DiffOp
51 struct Laplace1D <: DiffOp 51 grid::Grid.EquidistantGrid{Dim}
52 grid::Grid.EquidistantGrid
53 a::Real 52 a::Real
54 op::D2{Float64} 53 op::D2{Float64}
55 end 54 end
56 55
57 # u = L*v 56 # u = L*v
58 function apply(L::Laplace1D, v::AbstractVector, i::Int) 57 function apply(L::Laplace{1}, v::AbstractVector, i::Int)
59 h = Grid.spacings(L.grid)[1] 58 h = Grid.spacings(L.grid)[1]
60 uᵢ = L.a * apply(L.op, h, v, i) 59 uᵢ = L.a * apply(L.op, h, v, i)
61 return uᵢ 60 return uᵢ
62 end 61 end
63 62
64
65 # Differential operator for a*d^2/dx^2 + a*d^2/dy^2
66 struct Laplace2D <: DiffOp
67 grid::Grid.EquidistantGrid
68 a::Real
69 op::D2{Float64}
70 end
71
72 # u = L*v 63 # u = L*v
73 function apply(L::Laplace2D, v::AbstractVector, i::Int) 64 function apply(L::Laplace{2}, v::AbstractVector, i::Int)
74 h = Grid.spacings(L.grid) 65 h = Grid.spacings(L.grid)
75 66
76 li = LinearIndices(L.grid.numberOfPointsPerDim) 67 li = LinearIndices(L.grid.numberOfPointsPerDim)
77 ci = CartesianIndices(L.grid.numberOfPointsPerDim) 68 ci = CartesianIndices(L.grid.numberOfPointsPerDim)
78 I = ci[i] 69 I = ci[i]