diff 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
line wrap: on
line diff
--- a/diffOp.jl	Thu Jan 17 15:19:33 2019 +0100
+++ b/diffOp.jl	Thu Jan 17 15:22:10 2019 +0100
@@ -47,30 +47,21 @@
     return u
 end
 
-# Differential operator for a*d^2/dx^2
-struct Laplace1D <: DiffOp
-    grid::Grid.EquidistantGrid
+struct Laplace{Dim} <: DiffOp
+    grid::Grid.EquidistantGrid{Dim}
     a::Real
     op::D2{Float64}
 end
 
 # u = L*v
-function apply(L::Laplace1D, v::AbstractVector, i::Int)
+function apply(L::Laplace{1}, v::AbstractVector, i::Int)
     h = Grid.spacings(L.grid)[1]
     uᵢ = L.a * apply(L.op, h, v, i)
     return uᵢ
 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, v::AbstractVector, i::Int)
+function apply(L::Laplace{2}, v::AbstractVector, i::Int)
     h = Grid.spacings(L.grid)
 
     li = LinearIndices(L.grid.numberOfPointsPerDim)