diff sbpD2.jl @ 104:1862e901febb cell_based_test

Merge with tip
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 07 Feb 2019 17:17:31 +0100
parents 19031733bbbf
children 6c6979ff17f4 f01b70b81e95
line wrap: on
line diff
--- a/sbpD2.jl	Thu Feb 07 17:15:26 2019 +0100
+++ b/sbpD2.jl	Thu Feb 07 17:17:31 2019 +0100
@@ -42,11 +42,11 @@
 end
 
 struct D2{T,N,M,K} <: ConstantStencilOperator
-    quadratureClosure::Vector{T}
+    quadratureClosure::NTuple{M,T}
     innerStencil::Stencil{T,N}
-    closureStencils::NTuple{M, Stencil{T,K}}
-    eClosure::Vector{T}
-    dClosure::Vector{T}
+    closureStencils::NTuple{M,Stencil{T,K}}
+    eClosure::NTuple{M,T}
+    dClosure::NTuple{M,T}
     parity::Parity
 end
 
@@ -59,29 +59,33 @@
     h = readSectionedFile(Hfn)
 
     # Create inner stencil
-    innerStencilWeights = stringToVector(Float64, d["inner_stencil"][1])
+    innerStencilWeights = stringToTuple(Float64, d["inner_stencil"][1])
     width = length(innerStencilWeights)
     r = (-div(width,2), div(width,2))
 
-    innerStencil = Stencil(r, Tuple(innerStencilWeights))
+    innerStencil = Stencil(r, innerStencilWeights)
 
     # Create boundary stencils
     boundarySize = length(d["boundary_stencils"])
     closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type?
 
     for i ∈ 1:boundarySize
-        stencilWeights = stringToVector(Float64, d["boundary_stencils"][i])
+        stencilWeights = stringToTuple(Float64, d["boundary_stencils"][i])
         width = length(stencilWeights)
         r = (1-i,width-i)
-        closureStencils = (closureStencils..., Stencil(r, Tuple(stencilWeights)))
+        closureStencils = (closureStencils..., Stencil(r, stencilWeights))
     end
 
+    quadratureClosure = pad_tuple(stringToTuple(Float64, h["closure"][1]), boundarySize)
+    eClosure = pad_tuple(stringToTuple(Float64, d["e"][1]), boundarySize)
+    dClosure = pad_tuple(stringToTuple(Float64, d["d1"][1]), boundarySize)
+
     d2 = D2(
-        stringToVector(Float64, h["closure"][1]),
+        quadratureClosure,
         innerStencil,
         closureStencils,
-        stringToVector(Float64, d["e"][1]),
-        stringToVector(Float64, d["d1"][1]),
+        eClosure,
+        dClosure,
         even
     )
 
@@ -113,6 +117,19 @@
     return sections
 end
 
+function stringToTuple(T::DataType, s::String)
+    return Tuple(stringToVector(T,s))
+end
+
 function stringToVector(T::DataType, s::String)
     return T.(eval.(Meta.parse.(split(s))))
 end
+
+
+function pad_tuple(t::NTuple{N, T}, n::Integer) where {N,T}
+    if N >= n
+        return t
+    else
+        return pad_tuple((t..., zero(T)), n)
+    end
+end