comparison sbpD2.jl @ 24:55fea1ceb6aa

Start implementing reading 1D operator stencils from file into struct
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 10 Jan 2019 10:12:11 +0100
parents 433008d3b7d3
children bb841977d198 91e662512e9a
comparison
equal deleted inserted replaced
18:49b1a6454f55 24:55fea1ceb6aa
1
2 struct D2{T} 1 struct D2{T}
3 quadratureClosure::Vector{T} 2 quadratureClosure::Vector{T}
4 innerStencil::Stencil 3 innerStencil::Stencil
5 closureStencils::Vector{Stencil} # TBD: Should this be a tuple? 4 closureStencils::Vector{Stencil} # TBD: Should this be a tuple?
6 eClosure::Vector{T} 5 eClosure::Vector{T}
8 end 7 end
9 8
10 function closureSize(D::D2)::Int 9 function closureSize(D::D2)::Int
11 return length(quadratureClosure) 10 return length(quadratureClosure)
12 end 11 end
12
13 function readOperator(D2fn, Hfn)
14 d = readSectionedFile(D2fn)
15 h = readSectionedFile(Hfn)
16
17 # Create inner stencil
18 innerStencilWeights = stringToVector(Float64, d["inner_stencil"])
19 width = length(innerStencilWeights)
20 r = (-width//2, width//2)
21 innerStencil = Stencil(r, innerStencilWeights)
22
23 # Create boundary stencils
24 boundarySize = length(d["boundary_stencils"])
25 closureStencils = Vector{Stencil}()
26 for i ∈ 1:boundarySize
27 stencilWeights = stringToVector(Float64, d["boundary_stencils"][i])
28
29 end
30
31 d2 = D2(
32 stringToVector(Float64, h["closure"]),
33 innerStencil,
34 closureStencils,
35 stringToVector(Float64, d["e"]),
36 stringToVector(Float64, d["d1"]),
37 )
38
39 # Return d2!
40
41 return nothing
42 end
43
44
45 function readSectionedFile(filename)::Dict{String, Vector{String}}
46 f = open(filename)
47 sections = Dict{String, Vector{String}}()
48 currentKey = ""
49
50 for ln ∈ eachline(f)
51 if ln == "" || ln[1] == '#' # Skip comments and empty lines
52 continue
53 end
54
55 if isletter(ln[1]) # Found start of new section
56 if ~haskey(sections, ln)
57 sections[ln] = Vector{String}()
58 end
59 currentKey = ln
60 continue
61 end
62
63 push!(sections[currentKey], ln)
64 end
65
66 return sections
67 end
68
69 function stringToVector(T::DataType, s::String; delimiter = " ")
70 return parse(T, split(s, delimiter))
71 end