Mercurial > repos > public > sbplib_julia
changeset 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 | 93c833019857 |
children | 2be36b38389d |
files | diffOp.jl plotDerivative.jl plotDerivative2d.jl |
diffstat | 3 files changed, 9 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/diffOp.jl Thu Jan 17 15:19:33 2019 +0100 +++ b/diffOp.jl Thu Jan 24 09:24:21 2019 +0100 @@ -33,30 +33,22 @@ end # Differential operator for a*d^2/dx^2 -struct Laplace1D <: DiffOp - grid::Grid.EquidistantGrid - a::Real +struct Laplace{D, T<:Real} <: DiffOp + grid::Grid.EquidistantGrid{D,T} + a::T op::D2{Float64} end # u = L*v -function apply!(L::Laplace1D, u::AbstractVector, v::AbstractVector) +function apply!(L::Laplace{1}, u::AbstractVector, v::AbstractVector) h = Grid.spacings(L.grid)[1] apply!(L.op, u, v, h) u .= L.a * u return nothing end - -# Differential operator for a*d^2/dx^2 + a*d^2/dy^2 -struct Laplace2D <: DiffOp - grid::Grid.EquidistantGrid - a::Real - op::D2{Float64} -end - # u = L*v -function apply!(L::Laplace2D, u::AbstractVector, v::AbstractVector) +function apply!(L::Laplace{2}, u::AbstractVector, v::AbstractVector) u .= 0*u h = Grid.spacings(L.grid)
--- a/plotDerivative.jl Thu Jan 17 15:19:33 2019 +0100 +++ b/plotDerivative.jl Thu Jan 24 09:24:21 2019 +0100 @@ -1,6 +1,6 @@ -g = sbp.Grid.EquidistantGrid(200,(0, 2pi)) +g = sbp.Grid.EquidistantGrid((200,), (0.0,), (2pi,)) op =sbp.readOperator("d2_4th.txt","h_4th.txt") -Laplace = sbp.Laplace1D(g,1,op) +Laplace = sbp.Laplace(g,1.0,op) init(x) = sin(x) v = sbp.Grid.evalOn(g,init)
--- a/plotDerivative2d.jl Thu Jan 17 15:19:33 2019 +0100 +++ b/plotDerivative2d.jl Thu Jan 24 09:24:21 2019 +0100 @@ -1,6 +1,6 @@ -g = sbp.Grid.EquidistantGrid((100,75),((0, 0), (2pi, 3/2*pi))) +g = sbp.Grid.EquidistantGrid((100,75), (0.0, 0.0), (2pi, 3/2*pi)) op = sbp.readOperator("d2_4th.txt","h_4th.txt") -Laplace = sbp.Laplace2D(g,1,op) +Laplace = sbp.Laplace(g, 1.0, op) init(x,y) = sin(x) + cos(y) v = sbp.Grid.evalOn(g,init)