Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/readoperator.jl @ 598:19e1b169aa9c refactor/toml_operator_format
Add funcitons for reading several stecils or reading tuples
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 04 Dec 2020 13:11:24 +0100 |
parents | 98cd99237176 |
children | a21fe9b6e5b6 |
comparison
equal
deleted
inserted
replaced
597:98cd99237176 | 598:19e1b169aa9c |
---|---|
46 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "D2", "inner_stencil") | 46 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "D2", "inner_stencil") |
47 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "d1", "closure"; center=1) | 47 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "d1", "closure"; center=1) |
48 ``` | 48 ``` |
49 """ | 49 """ |
50 read_stencil(fn, path...; center=nothing) = get_stencil(TOML.parsefile(fn), path...; center=center) | 50 read_stencil(fn, path...; center=nothing) = get_stencil(TOML.parsefile(fn), path...; center=center) |
51 read_stencils(fn, path..., centers=nothing) = get_stencils(TOML.parsefile(fn), path...; centers=centers) | |
52 read_tuple(fn, path..., centers=nothing) = get_tuple(TOML.parsefile(fn), path...) | |
51 | 53 |
52 function get_stencil(parsed_toml, path...; center=nothing) | 54 get_stencil(parsed_toml, path...; center=nothing) = get_stencil(parsed_toml[path[1]], path[2:end]...; center=center) |
53 if length(path) == 0 | 55 function get_stencil(parsed_toml; center=nothing) |
54 @assert parsed_toml isa Vector | 56 @assert parsed_toml isa Vector{String} |
55 stencil_weights = Float64.(parse_rational.(parsed_toml)) | 57 stencil_weights = Float64.(parse_rational.(parsed_toml)) |
56 | 58 |
57 width = length(stencil_weights) | 59 width = length(stencil_weights) |
58 | 60 |
59 if isnothing(center) | 61 if isnothing(center) |
60 center = div(width,2)+1 | 62 center = div(width,2)+1 |
61 end | |
62 | |
63 return Stencil(Tuple(stencil_weights), center=center) | |
64 end | 63 end |
65 | 64 |
66 return get_stencil(parsed_toml[path[1]], path[2:end]...; center=center) | 65 return Stencil(Tuple(stencil_weights), center=center) |
66 end | |
67 | |
68 get_stencils(parsed_toml, path...; centers) = get_stencils(parsed_toml[path[1]], path[2:end]...; centers=centers) | |
69 function get_stencils(parsed_toml; centers) | |
70 @assert parsed_toml isa Vector{Vector{String}} | |
71 @assert length(centers) == length(parsed_toml) | |
72 | |
73 stencils = () | |
74 for i ∈ 1:length(parsed_toml) | |
75 stencil = get_stencil(parsed_toml[i]), center = centers[i] | |
76 stencils = (stencils..., stencil) | |
77 end | |
78 | |
79 return stencils | |
80 end | |
81 | |
82 get_tuple(parsed_toml, path...) = get_tuple(parsed_toml[path[1]], path[2:end]...) | |
83 function get_tuple(parsed_toml, path...) | |
84 @assert parsed_toml isa Vector{String} | |
85 t = Tuple(Float64.(parse_rational.(parsed_toml))) | |
86 return t | |
67 end | 87 end |
68 | 88 |
69 # TODO: Probably should be deleted once we have gotten rid of read_D2_operator() | 89 # TODO: Probably should be deleted once we have gotten rid of read_D2_operator() |
70 function toml_string_array_to_tuple(::Type{T}, arr::AbstractVector{String}) where T | 90 function toml_string_array_to_tuple(::Type{T}, arr::AbstractVector{String}) where T |
71 return Tuple(T.(parse_rational.(arr))) | 91 return Tuple(T.(parse_rational.(arr))) |