comparison diffOp.jl @ 76:81d9510cb2d0

Make Laplace take dimension as a parameter
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 24 Jan 2019 09:24:21 +0100
parents d04569696918
children 700a74c41b26 48079bd39969
comparison
equal deleted inserted replaced
75:93c833019857 76:81d9510cb2d0
31 function apply(c::Penalty, g, i::Int) 31 function apply(c::Penalty, g, i::Int)
32 error("not implemented") 32 error("not implemented")
33 end 33 end
34 34
35 # Differential operator for a*d^2/dx^2 35 # Differential operator for a*d^2/dx^2
36 struct Laplace1D <: DiffOp 36 struct Laplace{D, T<:Real} <: DiffOp
37 grid::Grid.EquidistantGrid 37 grid::Grid.EquidistantGrid{D,T}
38 a::Real 38 a::T
39 op::D2{Float64} 39 op::D2{Float64}
40 end 40 end
41 41
42 # u = L*v 42 # u = L*v
43 function apply!(L::Laplace1D, u::AbstractVector, v::AbstractVector) 43 function apply!(L::Laplace{1}, u::AbstractVector, v::AbstractVector)
44 h = Grid.spacings(L.grid)[1] 44 h = Grid.spacings(L.grid)[1]
45 apply!(L.op, u, v, h) 45 apply!(L.op, u, v, h)
46 u .= L.a * u 46 u .= L.a * u
47 return nothing 47 return nothing
48 end 48 end
49 49
50
51 # Differential operator for a*d^2/dx^2 + a*d^2/dy^2
52 struct Laplace2D <: DiffOp
53 grid::Grid.EquidistantGrid
54 a::Real
55 op::D2{Float64}
56 end
57
58 # u = L*v 50 # u = L*v
59 function apply!(L::Laplace2D, u::AbstractVector, v::AbstractVector) 51 function apply!(L::Laplace{2}, u::AbstractVector, v::AbstractVector)
60 u .= 0*u 52 u .= 0*u
61 h = Grid.spacings(L.grid) 53 h = Grid.spacings(L.grid)
62 54
63 li = LinearIndices(L.grid.numberOfPointsPerDim) 55 li = LinearIndices(L.grid.numberOfPointsPerDim)
64 n_x, n_y = L.grid.numberOfPointsPerDim 56 n_x, n_y = L.grid.numberOfPointsPerDim