comparison src/SbpOperators/readoperator.jl @ 766:7624a1350ece operator_storage_array_of_table

Add parse_stencil
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 13 Feb 2021 22:17:55 +0100
parents fdd48f6ace1c
children 210d3f58bd56
comparison
equal deleted inserted replaced
765:fdd48f6ace1c 766:7624a1350ece
1 using TOML 1 using TOML
2 2
3 export read_stencil_set 3 export read_stencil_set
4 export get_stencil_set 4 export get_stencil_set
5
6 export parse_stencil
5 7
6 export read_D2_operator 8 export read_D2_operator
7 export read_stencil 9 export read_stencil
8 export read_stencils 10 export read_stencils
9 export read_tuple 11 export read_tuple
83 85
84 i = matches[1] 86 i = matches[1]
85 return parsed_toml["stencil_set"][i] 87 return parsed_toml["stencil_set"][i]
86 end 88 end
87 89
90 function parse_stencil(toml)
91 check_stencil_toml(toml)
92
93 if toml isa Array
94 weights = Float64.(parse_rational.(toml))
95 return CenteredStencil(weights...)
96 end
97
98 weights = Float64.(parse_rational.(toml["s"]))
99 return Stencil(weights..., center = toml["c"])
100 end
101
102 function check_stencil_toml(toml)
103 if !(toml isa Dict || toml isa Vector{String})
104 throw(ArgumentError("the TOML for a stecil must be a vector of strings or a table."))
105 end
106
107 if toml isa Vector{String}
108 return
109 end
110
111 if !(haskey(toml, "s") && haskey(toml, "c"))
112 throw(ArgumentError("the table form of a stencil must have fields `s` and `c`."))
113 end
114
115 if !(toml["s"] isa Vector{String})
116 throw(ArgumentError("a stencil must be specified as a vector of strings."))
117 end
118
119 if !(toml["c"] isa Int)
120 throw(ArgumentError("the center of a stencil must be specified as an integer."))
121 end
122 end
123
88 """ 124 """
89 read_stencil(fn, path...; [center]) 125 read_stencil(fn, path...; [center])
90 126
91 Read a stencil at `path` from the file with name `fn`. 127 Read a stencil at `path` from the file with name `fn`.
92 If a center is specified the given element of the stecil is set as the center. 128 If a center is specified the given element of the stecil is set as the center.