Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/readoperator.jl @ 609:7975143118e8 refactor/toml_operator_format
Add some documentation
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 05 Dec 2020 14:16:15 +0100 |
parents | 8ae63e775f9d |
children | 4a81812150f4 |
comparison
equal
deleted
inserted
replaced
608:8ae63e775f9d | 609:7975143118e8 |
---|---|
50 read_stencil(fn, path...; [center]) | 50 read_stencil(fn, path...; [center]) |
51 | 51 |
52 Read a stencil at `path` from the file with name `fn`. | 52 Read a stencil at `path` from the file with name `fn`. |
53 If a center is specified the given element of the stecil is set as the center. | 53 If a center is specified the given element of the stecil is set as the center. |
54 | 54 |
55 See also: [`read_stencils`](@ref), [`read_tuple`](@ref), [`get_stencil`](@ref). | |
56 | |
55 # Examples | 57 # Examples |
56 ``` | 58 ``` |
57 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "D2", "inner_stencil") | 59 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "D2", "inner_stencil") |
58 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "d1", "closure"; center=1) | 60 read_stencil(sbp_operators_path()*"standard_diagonal.toml", "order2", "d1", "closure"; center=1) |
59 ``` | 61 ``` |
60 """ | 62 """ |
61 read_stencil(fn, path...; center=nothing) = get_stencil(TOML.parsefile(fn), path...; center=center) | 63 read_stencil(fn, path...; center=nothing) = get_stencil(TOML.parsefile(fn), path...; center=center) |
64 | |
65 """ | |
66 read_stencils(fn, path...; centers) | |
67 | |
68 Read stencils at `path` from the file `fn`. | |
69 Centers of the stencils are specified as a tuple or array in `centers`. | |
70 | |
71 See also: [`read_stencil`](@ref), [`read_tuple`](@ref), [`get_stencils`](@ref). | |
72 """ | |
62 read_stencils(fn, path...; centers) = get_stencils(TOML.parsefile(fn), path...; centers=centers) | 73 read_stencils(fn, path...; centers) = get_stencils(TOML.parsefile(fn), path...; centers=centers) |
74 | |
75 """ | |
76 read_tuple(fn, path...) | |
77 | |
78 Read tuple at `path` from the file `fn`. | |
79 | |
80 See also: [`read_stencil`](@ref), [`read_stencils`](@ref), [`get_tuple`](@ref). | |
81 """ | |
63 read_tuple(fn, path...) = get_tuple(TOML.parsefile(fn), path...) | 82 read_tuple(fn, path...) = get_tuple(TOML.parsefile(fn), path...) |
64 | 83 |
84 """ | |
85 get_stencil(parsed_toml, path...; center=nothing) | |
86 | |
87 Same as [`read_stencil`](@ref)) but takes already parsed toml. | |
88 """ | |
65 get_stencil(parsed_toml, path...; center=nothing) = get_stencil(parsed_toml[path[1]], path[2:end]...; center=center) | 89 get_stencil(parsed_toml, path...; center=nothing) = get_stencil(parsed_toml[path[1]], path[2:end]...; center=center) |
66 function get_stencil(parsed_toml; center=nothing) | 90 function get_stencil(parsed_toml; center=nothing) |
67 @assert parsed_toml isa Vector{String} | 91 @assert parsed_toml isa Vector{String} |
68 stencil_weights = Float64.(parse_rational.(parsed_toml)) | 92 stencil_weights = Float64.(parse_rational.(parsed_toml)) |
69 | 93 |
74 end | 98 end |
75 | 99 |
76 return Stencil(Tuple(stencil_weights), center=center) | 100 return Stencil(Tuple(stencil_weights), center=center) |
77 end | 101 end |
78 | 102 |
103 """ | |
104 get_stencils(parsed_toml, path...; centers) | |
105 | |
106 Same as [`read_stencils`](@ref)) but takes already parsed toml. | |
107 """ | |
79 get_stencils(parsed_toml, path...; centers) = get_stencils(parsed_toml[path[1]], path[2:end]...; centers=centers) | 108 get_stencils(parsed_toml, path...; centers) = get_stencils(parsed_toml[path[1]], path[2:end]...; centers=centers) |
80 function get_stencils(parsed_toml; centers) | 109 function get_stencils(parsed_toml; centers) |
81 @assert parsed_toml isa Vector{Vector{String}} | 110 @assert parsed_toml isa Vector{Vector{String}} |
82 @assert length(centers) == length(parsed_toml) | 111 @assert length(centers) == length(parsed_toml) |
83 | 112 |
88 end | 117 end |
89 | 118 |
90 return stencils | 119 return stencils |
91 end | 120 end |
92 | 121 |
122 """ | |
123 get_tuple(parsed_toml, path...) | |
124 | |
125 Same as [`read_tuple`](@ref)) but takes already parsed toml. | |
126 """ | |
93 get_tuple(parsed_toml, path...) = get_tuple(parsed_toml[path[1]], path[2:end]...) | 127 get_tuple(parsed_toml, path...) = get_tuple(parsed_toml[path[1]], path[2:end]...) |
94 function get_tuple(parsed_toml) | 128 function get_tuple(parsed_toml) |
95 @assert parsed_toml isa Vector{String} | 129 @assert parsed_toml isa Vector{String} |
96 t = Tuple(Float64.(parse_rational.(parsed_toml))) | 130 t = Tuple(Float64.(parse_rational.(parsed_toml))) |
97 return t | 131 return t |