comparison src/SbpOperators/readoperator.jl @ 596:a9744aa5e235 refactor/toml_operator_format

Simplify read_D2_operator by introducing a get_stencil function
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 02 Dec 2020 17:12:04 +0100
parents cc86b920531a
children 98cd99237176
comparison
equal deleted inserted replaced
595:03ef4d4740ab 596:a9744aa5e235
5 H = operators["H"] 5 H = operators["H"]
6 e = operators["e"] 6 e = operators["e"]
7 d1 = operators["d1"] 7 d1 = operators["d1"]
8 8
9 # Create inner stencil 9 # Create inner stencil
10 innerStencilWeights = toml_string_array_to_tuple(Float64, D2["inner_stencil"]) 10 innerStencil = get_stencil(operators, "D2", "inner_stencil")
11
12 width = length(innerStencilWeights)
13 r = (-div(width,2), div(width,2))
14
15 innerStencil = Stencil(r, innerStencilWeights)
16 11
17 # Create boundary stencils 12 # Create boundary stencils
18 boundarySize = length(D2["closure_stencils"]) 13 boundarySize = length(D2["closure_stencils"])
19 closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type? 14 closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type?
20 15
21 for i ∈ 1:boundarySize 16 for i ∈ 1:boundarySize
22 stencilWeights = toml_string_array_to_tuple(Float64, D2["closure_stencils"][i]) 17 closureStencils = (closureStencils..., get_stencil(operators, "D2", "closure_stencils", i; center=i))
23 width = length(stencilWeights)
24 r = (1-i,width-i)
25 closureStencils = (closureStencils..., Stencil(r, stencilWeights))
26 end 18 end
27 19
20 # TODO: Get rid of the padding here. Any padding should be handled by the consturctor accepting the stencils.
28 quadratureClosure = pad_tuple(toml_string_array_to_tuple(Float64, H["closure"]), boundarySize) 21 quadratureClosure = pad_tuple(toml_string_array_to_tuple(Float64, H["closure"]), boundarySize)
29 eClosure = Stencil((0,boundarySize-1), pad_tuple(toml_string_array_to_tuple(Float64, e["closure"]), boundarySize)) 22 eClosure = Stencil(pad_tuple(toml_string_array_to_tuple(Float64, e["closure"]), boundarySize), center=1)
30 dClosure = Stencil((0,boundarySize-1), pad_tuple(toml_string_array_to_tuple(Float64, d1["closure"]), boundarySize)) 23 dClosure = Stencil(pad_tuple(toml_string_array_to_tuple(Float64, d1["closure"]), boundarySize), center=1)
31 24
32 d2 = SbpOperators.D2( 25 d2 = SbpOperators.D2(
33 quadratureClosure, 26 quadratureClosure,
34 innerStencil, 27 innerStencil,
35 closureStencils, 28 closureStencils,
39 ) 32 )
40 33
41 return d2 34 return d2
42 end 35 end
43 36
37 function get_stencil(parsed_toml, path...; center=nothing)
38 if length(path) == 0
39 @assert parsed_toml isa Vector
40 stencil_weights = Float64.(parse_rational.(parsed_toml))
41
42 width = length(stencil_weights)
43
44 if isnothing(center)
45 center = div(width,2)+1
46 end
47
48 return Stencil(Tuple(stencil_weights), center=center)
49 end
50
51 return get_stencil(parsed_toml[path[1]], path[2:end]...; center=center)
52 end
53
54 # TODO: Probably should be deleted once we have gotten rid of read_D2_operator()
44 function toml_string_array_to_tuple(::Type{T}, arr::AbstractVector{String}) where T 55 function toml_string_array_to_tuple(::Type{T}, arr::AbstractVector{String}) where T
45 return Tuple(T.(parse_rational.(arr))) 56 return Tuple(T.(parse_rational.(arr)))
46 end 57 end
47 58
48 function parse_rational(str) 59 function parse_rational(str)