Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/readoperator.jl @ 1018:5ec49dd2c7c4 feature/stencil_set_type
Reintroduce read_stencil_set
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 22 Mar 2022 09:57:28 +0100 |
parents | 37fd8c1cadb2 |
children |
comparison
equal
deleted
inserted
replaced
991:37fd8c1cadb2 | 1018:5ec49dd2c7c4 |
---|---|
1 using TOML | 1 using TOML |
2 | 2 |
3 export StencilSet | |
4 export get_stencil_set | |
5 | |
6 export parse_stencil | |
7 export parse_scalar | |
8 export parse_tuple | |
9 | |
10 export sbp_operators_path | |
11 | 3 |
12 """ | 4 """ |
13 StencilSet | 5 StencilSet |
14 | 6 |
15 A `StencilSet` contains a set of associated stencils. The stencils | 7 A `StencilSet` contains a set of associated stencils. The stencils |
20 end | 12 end |
21 Base.getindex(set::StencilSet,I...) = set.table[I...] | 13 Base.getindex(set::StencilSet,I...) = set.table[I...] |
22 | 14 |
23 | 15 |
24 """ | 16 """ |
25 StencilSet(filename; filters) | 17 read_stencil_set(filename; filters) |
26 | 18 |
27 Creates a `StencilSet` from a TOML file based on some key-value | 19 Creates a `StencilSet` from a TOML file based on some key-value |
28 filters. If more than one set matches the filters an error is raised. The | 20 filters. If more than one set matches the filters an error is raised. The |
29 table of the `StencilSet` is a parsed TOML intended for functions like | 21 table of the `StencilSet` is a parsed TOML intended for functions like |
30 `parse_scalar` and `parse_stencil`. | 22 `parse_scalar` and `parse_stencil`. |
36 general, and currently do not include any way to specify how to parse a given | 28 general, and currently do not include any way to specify how to parse a given |
37 section, the exact parsing is left to the user. | 29 section, the exact parsing is left to the user. |
38 | 30 |
39 For more information see [Operator file format](@ref) in the documentation. | 31 For more information see [Operator file format](@ref) in the documentation. |
40 | 32 |
41 See also [`sbp_operators_path`](@ref), [`get_stencil_set`](@ref), [`parse_stencil`](@ref), [`parse_scalar`](@ref), [`parse_tuple`](@ref),. | 33 See also [`StencilSet`](@ref), [`sbp_operators_path`](@ref), [`get_stencil_set`](@ref), [`parse_stencil`](@ref), [`parse_scalar`](@ref), [`parse_tuple`](@ref). |
42 """ | 34 """ |
43 StencilSet(filename; filters...) = StencilSet(get_stencil_set(TOML.parsefile(filename); filters...)) | 35 read_stencil_set(filename; filters...) = StencilSet(get_stencil_set(TOML.parsefile(filename); filters...)) |
44 | 36 |
45 | 37 |
46 """ | 38 """ |
47 get_stencil_set(parsed_toml; filters...) | 39 get_stencil_set(parsed_toml; filters...) |
48 | 40 |
49 Picks out a stencil set from an already parsed TOML based on some key-value | 41 Picks out a stencil set from an already parsed TOML based on some key-value |
50 filters. | 42 filters. |
51 | 43 |
52 See also [`StencilSet`](@ref). | 44 See also [`read_stencil_set`](@ref). |
53 """ | 45 """ |
54 function get_stencil_set(parsed_toml; filters...) | 46 function get_stencil_set(parsed_toml; filters...) |
55 matches = findall(parsed_toml["stencil_set"]) do set | 47 matches = findall(parsed_toml["stencil_set"]) do set |
56 for (key, val) ∈ filters | 48 for (key, val) ∈ filters |
57 if set[string(key)] != val | 49 if set[string(key)] != val |
73 """ | 65 """ |
74 parse_stencil(parsed_toml) | 66 parse_stencil(parsed_toml) |
75 | 67 |
76 Accepts parsed TOML and reads it as a stencil. | 68 Accepts parsed TOML and reads it as a stencil. |
77 | 69 |
78 See also [`StencilSet`](@ref), [`parse_scalar`](@ref), [`parse_tuple`](@ref). | 70 See also [`read_stencil_set`](@ref), [`parse_scalar`](@ref), [`parse_tuple`](@ref). |
79 """ | 71 """ |
80 function parse_stencil(parsed_toml) | 72 function parse_stencil(parsed_toml) |
81 check_stencil_toml(parsed_toml) | 73 check_stencil_toml(parsed_toml) |
82 | 74 |
83 if parsed_toml isa Array | 75 if parsed_toml isa Array |
121 """ | 113 """ |
122 parse_scalar(parsed_toml) | 114 parse_scalar(parsed_toml) |
123 | 115 |
124 Parse a scalar, represented as a string or a number in the TOML, and return it as a `Rational` | 116 Parse a scalar, represented as a string or a number in the TOML, and return it as a `Rational` |
125 | 117 |
126 See also [`StencilSet`](@ref), [`parse_stencil`](@ref) [`parse_tuple`](@ref). | 118 See also [`read_stencil_set`](@ref), [`parse_stencil`](@ref) [`parse_tuple`](@ref). |
127 """ | 119 """ |
128 function parse_scalar(parsed_toml) | 120 function parse_scalar(parsed_toml) |
129 try | 121 try |
130 return parse_rational(parsed_toml) | 122 return parse_rational(parsed_toml) |
131 catch e | 123 catch e |
136 """ | 128 """ |
137 parse_tuple(parsed_toml) | 129 parse_tuple(parsed_toml) |
138 | 130 |
139 Parse an array as a tuple of scalars. | 131 Parse an array as a tuple of scalars. |
140 | 132 |
141 See also [`StencilSet`](@ref), [`parse_stencil`](@ref), [`parse_scalar`](@ref). | 133 See also [`read_stencil_set`](@ref), [`parse_stencil`](@ref), [`parse_scalar`](@ref). |
142 """ | 134 """ |
143 function parse_tuple(parsed_toml) | 135 function parse_tuple(parsed_toml) |
144 if !(parsed_toml isa Array) | 136 if !(parsed_toml isa Array) |
145 throw(ArgumentError("argument must be an array")) | 137 throw(ArgumentError("argument must be an array")) |
146 end | 138 end |
165 """ | 157 """ |
166 sbp_operators_path() | 158 sbp_operators_path() |
167 | 159 |
168 Calculate the path for the operators folder with included stencil sets. | 160 Calculate the path for the operators folder with included stencil sets. |
169 | 161 |
170 See also [`StencilSet`](@ref) | 162 See also [`StencilSet`](@ref), [`read_stencil_set`](@ref). |
171 """ | 163 """ |
172 sbp_operators_path() = (@__DIR__) * "/operators/" | 164 sbp_operators_path() = (@__DIR__) * "/operators/" |