comparison sbpD2.jl @ 100:49796ca2dfa0 cell_based_test

Introduce and use the function stringToTuple in sbpD2.jl
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 06 Feb 2019 23:03:12 +0100
parents 50273f745f05
children 19031733bbbf
comparison
equal deleted inserted replaced
99:6b6d680f2e25 100:49796ca2dfa0
57 function readOperator(D2fn, Hfn) 57 function readOperator(D2fn, Hfn)
58 d = readSectionedFile(D2fn) 58 d = readSectionedFile(D2fn)
59 h = readSectionedFile(Hfn) 59 h = readSectionedFile(Hfn)
60 60
61 # Create inner stencil 61 # Create inner stencil
62 innerStencilWeights = stringToVector(Float64, d["inner_stencil"][1]) 62 innerStencilWeights = stringToTuple(Float64, d["inner_stencil"][1])
63 width = length(innerStencilWeights) 63 width = length(innerStencilWeights)
64 r = (-div(width,2), div(width,2)) 64 r = (-div(width,2), div(width,2))
65 65
66 innerStencil = Stencil(r, Tuple(innerStencilWeights)) 66 innerStencil = Stencil(r, innerStencilWeights)
67 67
68 # Create boundary stencils 68 # Create boundary stencils
69 boundarySize = length(d["boundary_stencils"]) 69 boundarySize = length(d["boundary_stencils"])
70 closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type? 70 closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type?
71 71
72 for i ∈ 1:boundarySize 72 for i ∈ 1:boundarySize
73 stencilWeights = stringToVector(Float64, d["boundary_stencils"][i]) 73 stencilWeights = stringToTuple(Float64, d["boundary_stencils"][i])
74 width = length(stencilWeights) 74 width = length(stencilWeights)
75 r = (1-i,width-i) 75 r = (1-i,width-i)
76 closureStencils = (closureStencils..., Stencil(r, Tuple(stencilWeights))) 76 closureStencils = (closureStencils..., Stencil(r, stencilWeights))
77 end 77 end
78 78
79 d2 = D2( 79 d2 = D2(
80 stringToVector(Float64, h["closure"][1]), 80 stringToVector(Float64, h["closure"][1]),
81 innerStencil, 81 innerStencil,
111 end 111 end
112 112
113 return sections 113 return sections
114 end 114 end
115 115
116 function stringToTuple(T::DataType, s::String)
117 return Tuple(stringToVector(T,s))
118 end
119
116 function stringToVector(T::DataType, s::String) 120 function stringToVector(T::DataType, s::String)
117 return T.(eval.(Meta.parse.(split(s)))) 121 return T.(eval.(Meta.parse.(split(s))))
118 end 122 end