comparison src/SbpOperators/readoperator.jl @ 764:d34b515b0ae7 operator_storage_array_of_table

Add functions for reading stencil sets
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 06 Feb 2021 20:45:34 +0100
parents ec7490fb4404
children fdd48f6ace1c
comparison
equal deleted inserted replaced
763:5ff162f3ed72 764:d34b515b0ae7
1 using TOML 1 using TOML
2
3 export read_stencil_set
4 export get_stencil_set
2 5
3 export read_D2_operator 6 export read_D2_operator
4 export read_stencil 7 export read_stencil
5 export read_stencils 8 export read_stencils
6 export read_tuple 9 export read_tuple
51 read_stencil_set(fn, filter_pairs::Vararg{Pair}) 54 read_stencil_set(fn, filter_pairs::Vararg{Pair})
52 55
53 Picks out a stencil set from the given toml file based on some filters. 56 Picks out a stencil set from the given toml file based on some filters.
54 If more than one set matches the filters an error is raised. 57 If more than one set matches the filters an error is raised.
55 58
59 The stencil set is not parsed beyond the inital toml parse. To get usable
60 stencils use the `parse_stencil` functions on the fields of the stencil set.
56 """ 61 """
57 read_stencil_set(fn, filter_pairs::Vararg{Pair}) = get_stencil_set(TOML.parsefile(fn), filter_pairs...) 62 read_stencil_set(fn, filter_pairs::Vararg{Pair}) = get_stencil_set(TOML.parsefile(fn), filter_pairs...)
58 63
59 function get_stencil_set(parsed_toml, filter_pairs::Vararg{Pair}) 64 """
65 get_stencil_set(parsed_toml; filters...)
60 66
67 Same as `read_stencil_set` but works on already parsed TOML.
68 """
69 function get_stencil_set(parsed_toml; filters...)
70 matches = findall(parsed_toml["stencil_set"]) do set
71 for (key, val) ∈ filters
72 if set[string(key)] != val
73 return false
74 end
75 end
76
77 return true
78 end
79
80 if length(matches) != 1
81 throw(ArgumentError("filters must pick out a single stencil set"))
82 end
83
84 i = matches[1]
85 return parsed_toml["stencil_set"][i]
61 end 86 end
62 87
63 """ 88 """
64 read_stencil(fn, path...; [center]) 89 read_stencil(fn, path...; [center])
65 90