|
1 | 1 | """ |
2 | | -$(TYPEDSIGNATURES) |
| 2 | + symbolic_container(p) |
3 | 3 |
|
4 | | -Get an iterable over the independent variables for the given system. Default to an empty |
5 | | -vector. |
6 | | -""" |
7 | | -function independent_variables end |
8 | | -independent_variables(::Any) = [] |
| 4 | +Using `p`, return an object that implements the symbolic indexing interface. In case `p` |
| 5 | +itself implements the interface, `p` can be returned as-is. All symbolic indexing interface |
| 6 | +methods fall back to calling the same method on `symbolic_container(p)`, so this may be |
| 7 | +used for trivial implementations of the interface that forward all calls to another object. |
9 | 8 |
|
| 9 | +This is also used by [`ParameterIndexingProxy`](@ref) |
10 | 10 | """ |
11 | | -$(TYPEDSIGNATURES) |
| 11 | +function symbolic_container end |
12 | 12 |
|
13 | | -Check if the given sym is an independent variable in the given system. Default to checking |
14 | | -if the given `sym` exists in the iterable returned by `independent_variables`. |
15 | 13 | """ |
16 | | -function is_indep_sym end |
17 | | - |
18 | | -function is_indep_sym(store, sym) |
19 | | - any(isequal(Symbol(sym)), Symbol.(independent_variables(store))) |
20 | | -end |
| 14 | + is_variable(sys, sym) |
21 | 15 |
|
| 16 | +Check whether the given `sym` is a variable in `sys`. |
22 | 17 | """ |
23 | | -$(TYPEDSIGNATURES) |
| 18 | +is_variable(sys, sym) = is_variable(symbolic_container(sys), sym) |
24 | 19 |
|
25 | | -Get an iterable over the states for the given system. Default to an empty vector. |
26 | 20 | """ |
27 | | -function states end |
28 | | - |
29 | | -states(::Any) = [] |
| 21 | + variable_index(sys, sym, [i]) |
30 | 22 |
|
| 23 | +Return the index of the given variable `sym` in `sys`, or `nothing` otherwise. If |
| 24 | +[`constant_structure`](@ref) is `false`, this accepts the current time index as an |
| 25 | +additional parameter `i`. |
31 | 26 | """ |
32 | | -$(TYPEDSIGNATURES) |
| 27 | +variable_index(sys, sym) = variable_index(symbolic_container(sys), sym) |
| 28 | +variable_index(sys, sym, i) = variable_index(symbolic_container(sys), sym, i) |
33 | 29 |
|
34 | | -Get an iterable over the unknown states for the given system. Default to an empty vector. |
35 | 30 | """ |
36 | | -function unknown_states end |
37 | | - |
38 | | -unknown_states(::Any) = [] |
| 31 | + variable_symbols(sys, [i]) |
39 | 32 |
|
| 33 | +Return a vector of the symbolic variables being solved for in the system `sys`. If |
| 34 | +`constant_structure(sys) == false` this accepts an additional parameter indicating |
| 35 | +the current time index. The returned vector should not be mutated. |
40 | 36 | """ |
41 | | -$(TYPEDSIGNATURES) |
| 37 | +variable_symbols(sys) = variable_symbols(symbolic_container(sys)) |
| 38 | +variable_symbols(sys, i) = variable_symbols(symbolic_container(sys), i) |
42 | 39 |
|
43 | | -Find the index of the given sym in the given system. Default to the index of the first |
44 | | -symbol in the iterable returned by `states` which matches the given `sym`. Return |
45 | | -`nothing` if the given `sym` does not match. |
46 | 40 | """ |
47 | | -function state_sym_to_index end |
48 | | - |
49 | | -function state_sym_to_index(store, sym) |
50 | | - findfirst(isequal(Symbol(sym)), Symbol.(states(store))) |
51 | | -end |
| 41 | + is_parameter(sys, sym) |
52 | 42 |
|
| 43 | +Check whether the given `sym` is a parameter in `sys`. |
53 | 44 | """ |
54 | | -$(TYPEDSIGNATURES) |
| 45 | +is_parameter(sys, sym) = is_parameter(symbolic_container(sys), sym) |
55 | 46 |
|
56 | | -Check if the given sym is a state variable in the given system. Default to checking if |
57 | | -the value returned by `state_sym_to_index` is not `nothing`. |
58 | 47 | """ |
59 | | -function is_state_sym end |
60 | | - |
61 | | -is_state_sym(store, sym) = !isnothing(state_sym_to_index(store, sym)) |
| 48 | + parameter_index(sys, sym) |
62 | 49 |
|
| 50 | +Return the index of the given parameter `sym` in `sys`, or `nothing` otherwise. |
63 | 51 | """ |
64 | | -$(TYPEDSIGNATURES) |
| 52 | +parameter_index(sys, sym) = parameter_index(symbolic_container(sys), sym) |
65 | 53 |
|
66 | | -Get an iterable over the parameters variables for the given system. Default to an empty |
67 | | -vector. |
68 | 54 | """ |
69 | | -function parameters end |
70 | | - |
71 | | -parameters(::Any) = [] |
| 55 | + parameter_symbols(sys) |
72 | 56 |
|
| 57 | +Return a vector of the symbolic parameters of the given system `sys`. The returned |
| 58 | +vector should not be mutated. |
73 | 59 | """ |
74 | | -$(TYPEDSIGNATURES) |
| 60 | +parameter_symbols(sys) = parameter_symbols(symbolic_container(sys)) |
75 | 61 |
|
76 | | -Find the index of the given sym in the given system. Default to the index of the first |
77 | | -symbol in the iterable retruned by `parameters` which matches the given `sym`. Return |
78 | | -`nothing` if the given `sym` does not match. |
79 | 62 | """ |
80 | | -function param_sym_to_index end |
81 | | - |
82 | | -param_sym_to_index(store, sym) = findfirst(isequal(Symbol(sym)), Symbol.(parameters(store))) |
| 63 | + is_independent_variable(sys, sym) |
83 | 64 |
|
| 65 | +Check whether the given `sym` is an independent variable in `sys`. The returned vector |
| 66 | +should not be mutated. |
84 | 67 | """ |
85 | | -$(TYPEDSIGNATURES) |
| 68 | +is_independent_variable(sys, sym) = is_independent_variable(symbolic_container(sys), sym) |
86 | 69 |
|
87 | | -Check if the given sym is a parameter variable in the given system. Default |
88 | | -to checking if the value returned by `param_sym_to_index` is not `nothing`. |
89 | 70 | """ |
90 | | -function is_param_sym end |
91 | | - |
92 | | -is_param_sym(store, sym) = !isnothing(param_sym_to_index(store, sym)) |
| 71 | + independent_variable_symbols(sys) |
93 | 72 |
|
| 73 | +Return a vector of the symbolic independent variables of the given system `sys`. |
94 | 74 | """ |
95 | | -$(TYPEDSIGNATURES) |
| 75 | +independent_variable_symbols(sys) = independent_variable_symbols(symbolic_container(sys)) |
96 | 76 |
|
97 | | -Get an iterable over the observed variable expressions for the given system. |
98 | | -Default to an empty vector. |
99 | 77 | """ |
100 | | -function observed end |
101 | | - |
102 | | -observed(::Any) = [] |
| 78 | + is_observed(sys, sym) |
103 | 79 |
|
| 80 | +Check whether the given `sym` is an observed value in `sys`. |
104 | 81 | """ |
105 | | -$(TYPEDSIGNATURES) |
| 82 | +is_observed(sys, sym) = is_observed(symbolic_container(sys), sym) |
106 | 83 |
|
107 | | -Check if the given sym is an observed variable in the given system. Default |
108 | | -to checking if the value returned by `observed_sym_to_index` is not `nothing`. |
109 | 84 | """ |
110 | | -function is_observed_sym end |
| 85 | + observed(sys, sym, [states]) |
111 | 86 |
|
112 | | -is_observed_sym(store, sym) = !isnothing(observed_sym_to_index(store, sym)) |
| 87 | +Return the observed function of the given `sym` in `sys`. The returned function should |
| 88 | +have the signature `(u, p) -> [values...]` where `u` and `p` is the current state and |
| 89 | +parameter vector. If `istimedependent(sys) == true`, the function should accept |
| 90 | +the current time `t` as its third parameter. If `constant_structure(sys) == false`, |
| 91 | +accept a third parameter which can either be a vector of symbols indicating the order |
| 92 | +of states or a time index which identifies the order of states. |
113 | 93 |
|
| 94 | +See also: [`is_time_dependent`](@ref), [`constant_structure`](@ref) |
114 | 95 | """ |
115 | | -$(TYPEDSIGNATURES) |
| 96 | +observed(sys, sym) = observed(symbolic_container(sys), sym) |
| 97 | +observed(sys, sym, states) = observed(symbolic_container(sys), sym, states) |
116 | 98 |
|
117 | | -Find the index of the given sym in the given system. Default to the index of the first |
118 | | -symbol in the iterable returned by `states` which matches the given `sym`. Return |
119 | | -`nothing` if the given `sym` does not match. |
120 | 99 | """ |
121 | | -function observed_sym_to_index end |
122 | | - |
123 | | -function observed_sym_to_index(store, sym) |
124 | | - findfirst(o -> isequal(sym, o.lhs), observed(store)) |
125 | | -end |
| 100 | + is_time_dependent(sys) |
126 | 101 |
|
| 102 | +Check if `sys` has time as (one of) its independent variables. |
127 | 103 | """ |
128 | | -$(TYPEDSIGNATURES) |
| 104 | +is_time_dependent(sys) = is_time_dependent(symbolic_container(sys)) |
129 | 105 |
|
130 | | -Return a list of the dependent state variables of an observed variable. Default to returning |
131 | | -an empty list. |
132 | 106 | """ |
133 | | -function get_state_dependencies end |
| 107 | + constant_structure(sys) |
134 | 108 |
|
135 | | -get_state_dependencies(store, sym) = [] |
136 | | - |
137 | | -""" |
138 | | -$(TYPEDSIGNATURES) |
139 | | -
|
140 | | -Return a list of the dependent observed variables of an observed variable. Default to returning |
141 | | -an empty list. |
142 | | -""" |
143 | | -function get_observed_dependencies end |
144 | | - |
145 | | -get_observed_dependencies(store, sym) = [] |
146 | | - |
147 | | -""" |
148 | | -$(TYPEDSIGNATURES) |
149 | | -
|
150 | | -Return a list of the dependent state variables of all observed equations of the system. |
151 | | -Default to returning an empty list. |
| 109 | +Check if `sys` has a constant structure. Constant structure systems do not change the |
| 110 | +number of variables or parameters over time. |
152 | 111 | """ |
153 | | -function get_deps_of_observed end |
154 | | - |
155 | | -function get_deps_of_observed(store) |
156 | | - obs = observed(store) |
157 | | - deps = mapreduce(vcat, obs, init = []) do eq |
158 | | - get_state_dependencies(store, eq.lhs) |
159 | | - end |> unique |
160 | | - |
161 | | - return deps |
162 | | -end |
| 112 | +constant_structure(sys) = constant_structure(symbolic_container(sys)) |
0 commit comments