Mercurial > repos > public > sbplib_julia
changeset 29:19078a768c5a
Merge
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 10 Jan 2019 10:48:28 +0100 |
parents | 32a53cbee6c5 (current diff) 55fea1ceb6aa (diff) |
children | e86c65958aa1 91e662512e9a |
files | |
diffstat | 3 files changed, 81 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2_2nd.txt Thu Jan 10 10:48:28 2019 +0100 @@ -0,0 +1,13 @@ +# D2 order 2 + +boundary_stencils +1 -2 1 + +inner_stencil +1 -2 1 + +e +1 0 + +d1 +-3/2 2 -1/2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h_2nd.txt Thu Jan 10 10:48:28 2019 +0100 @@ -0,0 +1,7 @@ +# H order 2 + +closure +1/2 + +inner_stencil +1
--- a/sbpD2.jl Thu Jan 10 10:38:42 2019 +0100 +++ b/sbpD2.jl Thu Jan 10 10:48:28 2019 +0100 @@ -1,4 +1,3 @@ - struct D2{T} quadratureClosure::Vector{T} innerStencil::Stencil @@ -9,4 +8,64 @@ function closureSize(D::D2)::Int return length(quadratureClosure) -end \ No newline at end of file +end + +function readOperator(D2fn, Hfn) + d = readSectionedFile(D2fn) + h = readSectionedFile(Hfn) + + # Create inner stencil + innerStencilWeights = stringToVector(Float64, d["inner_stencil"]) + width = length(innerStencilWeights) + r = (-width//2, width//2) + innerStencil = Stencil(r, innerStencilWeights) + + # Create boundary stencils + boundarySize = length(d["boundary_stencils"]) + closureStencils = Vector{Stencil}() + for i ∈ 1:boundarySize + stencilWeights = stringToVector(Float64, d["boundary_stencils"][i]) + + end + + d2 = D2( + stringToVector(Float64, h["closure"]), + innerStencil, + closureStencils, + stringToVector(Float64, d["e"]), + stringToVector(Float64, d["d1"]), + ) + + # Return d2! + + return nothing +end + + +function readSectionedFile(filename)::Dict{String, Vector{String}} + f = open(filename) + sections = Dict{String, Vector{String}}() + currentKey = "" + + for ln ∈ eachline(f) + if ln == "" || ln[1] == '#' # Skip comments and empty lines + continue + end + + if isletter(ln[1]) # Found start of new section + if ~haskey(sections, ln) + sections[ln] = Vector{String}() + end + currentKey = ln + continue + end + + push!(sections[currentKey], ln) + end + + return sections +end + +function stringToVector(T::DataType, s::String; delimiter = " ") + return parse(T, split(s, delimiter)) +end