changeset 84:48079bd39969

Change to using tuples in stencils and ops
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 25 Jan 2019 15:20:40 +0100
parents 2be36b38389d
children 8d505e9bc715 c0729ade65da 79699dda29be
files diffOp.jl sbpD2.jl stencil.jl
diffstat 3 files changed, 12 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/diffOp.jl	Thu Jan 24 13:33:07 2019 +0100
+++ b/diffOp.jl	Fri Jan 25 15:20:40 2019 +0100
@@ -33,10 +33,10 @@
 end
 
 # Differential operator for a*d^2/dx^2
-struct Laplace{D, T<:Real} <: DiffOp
-    grid::Grid.EquidistantGrid{D,T}
+struct Laplace{Dim,T<:Real,N,M,K} <: DiffOp
+    grid::Grid.EquidistantGrid{Dim,T}
     a::T
-    op::D2{Float64}
+    op::D2{Float64,N,M,K}
 end
 
 # u = L*v
--- a/sbpD2.jl	Thu Jan 24 13:33:07 2019 +0100
+++ b/sbpD2.jl	Fri Jan 25 15:20:40 2019 +0100
@@ -26,10 +26,10 @@
     even = 1
 end
 
-struct D2{T} <: ConstantStencilOperator
+struct D2{T,N,M,K} <: ConstantStencilOperator
     quadratureClosure::Vector{T}
-    innerStencil::Stencil
-    closureStencils::Vector{Stencil} # TBD: Should this be a tuple?
+    innerStencil::Stencil{T,N}
+    closureStencils::NTuple{M, Stencil{T,K}}
     eClosure::Vector{T}
     dClosure::Vector{T}
     parity::Parity
@@ -48,7 +48,7 @@
     width = length(innerStencilWeights)
     r = (-div(width,2), div(width,2))
 
-    innerStencil = Stencil(r, innerStencilWeights)
+    innerStencil = Stencil(r, Tuple(innerStencilWeights))
 
     # Create boundary stencils
     boundarySize = length(d["boundary_stencils"])
@@ -58,7 +58,7 @@
         stencilWeights = stringToVector(Float64, d["boundary_stencils"][i])
         width = length(stencilWeights)
         r = (1-i,width-i)
-        push!(closureStencils,Stencil(r, stencilWeights))
+        closureStencils = (closureStencils..., Stencil(r, Tuple(stencilWeights)))
     end
 
     d2 = D2(
--- a/stencil.jl	Thu Jan 24 13:33:07 2019 +0100
+++ b/stencil.jl	Fri Jan 25 15:20:40 2019 +0100
@@ -1,18 +1,11 @@
-struct Stencil
-    range::NTuple{2,Int}
-    weights::Vector # TBD: Should this be a tuple?
-    function Stencil(range, weights)
-        width = range[2]-range[1]+1
-        if width != length(weights)
-            error("The width and the number of weights must be the same")
-        end
-        new(range, weights)
-    end
+struct Stencil{T<:Real,N}
+    range::Tuple{Int,Int}
+    weights::NTuple{N,T}
 end
 
 function flip(s::Stencil)
     range = (-s.range[2], -s.range[1])
-    s = Stencil(range, s.weights[end:-1:1])
+    return Stencil(range, reverse(s.weights))
 end
 
 # Provides index into the Stencil based on offset for the root element