@@ -161,10 +161,18 @@ function independent_variable(sys::AbstractSystem)
161
161
isdefined (sys, :iv ) ? getfield (sys, :iv ) : nothing
162
162
end
163
163
164
- # Treat the result as a vector of symbols always
165
- function SymbolicIndexingInterface. independent_variables (sys:: AbstractSystem )
166
- systype = typeof (sys)
167
- @warn " Please declare ($systype ) as a subtype of `AbstractTimeDependentSystem`, `AbstractTimeIndependentSystem` or `AbstractMultivariateSystem`."
164
+ function independent_variables (sys:: AbstractTimeDependentSystem )
165
+ return [getfield (sys, :iv )]
166
+ end
167
+
168
+ independent_variables (:: AbstractTimeIndependentSystem ) = []
169
+
170
+ function independent_variables (sys:: AbstractMultivariateSystem )
171
+ return getfield (sys, :ivs )
172
+ end
173
+
174
+ function independent_variables (sys:: AbstractSystem )
175
+ @warn " Please declare ($(typeof (sys)) ) as a subtype of `AbstractTimeDependentSystem`, `AbstractTimeIndependentSystem` or `AbstractMultivariateSystem`."
168
176
if isdefined (sys, :iv )
169
177
return [getfield (sys, :iv )]
170
178
elseif isdefined (sys, :ivs )
@@ -174,14 +182,102 @@ function SymbolicIndexingInterface.independent_variables(sys::AbstractSystem)
174
182
end
175
183
end
176
184
177
- function SymbolicIndexingInterface. independent_variables (sys:: AbstractTimeDependentSystem )
178
- [getfield (sys, :iv )]
185
+ # Treat the result as a vector of symbols always
186
+ function SymbolicIndexingInterface. is_variable (sys:: AbstractSystem , sym)
187
+ if unwrap (sym) isa Int # [x, 1] coerces 1 to a Num
188
+ return unwrap (sym) in 1 : length (unknown_states (sys))
189
+ end
190
+ return any (isequal (sym), unknown_states (sys)) || hasname (sym) && is_variable (sys, getname (sym))
191
+ end
192
+
193
+ function SymbolicIndexingInterface. is_variable (sys:: AbstractSystem , sym:: Symbol )
194
+ return any (isequal (sym), getname .(unknown_states (sys))) || count (' ₊' , string (sym)) == 1 && count (isequal (sym), Symbol .(sys. name, :₊ , getname .(unknown_states (sys)))) == 1
179
195
end
180
- SymbolicIndexingInterface. independent_variables (sys:: AbstractTimeIndependentSystem ) = []
181
- function SymbolicIndexingInterface. independent_variables (sys:: AbstractMultivariateSystem )
182
- getfield (sys, :ivs )
196
+
197
+ function SymbolicIndexingInterface. variable_index (sys:: AbstractSystem , sym)
198
+ if unwrap (sym) isa Int
199
+ return unwrap (sym)
200
+ end
201
+ idx = findfirst (isequal (sym), unknown_states (sys))
202
+ if idx === nothing && hasname (sym)
203
+ idx = variable_index (sys, getname (sym))
204
+ end
205
+ return idx
183
206
end
184
207
208
+ function SymbolicIndexingInterface. variable_index (sys:: AbstractSystem , sym:: Symbol )
209
+ idx = findfirst (isequal (sym), getname .(unknown_states (sys)))
210
+ if idx != = nothing
211
+ return idx
212
+ elseif count (' ₊' , string (sym)) == 1
213
+ return findfirst (isequal (sym), Symbol .(sys. name, :₊ , getname .(unknown_states (sys))))
214
+ end
215
+ return nothing
216
+ end
217
+
218
+ function SymbolicIndexingInterface. variable_symbols (sys:: AbstractSystem )
219
+ return unknown_states (sys)
220
+ end
221
+
222
+ function SymbolicIndexingInterface. is_parameter (sys:: AbstractSystem , sym)
223
+ if unwrap (sym) isa Int
224
+ return unwrap (sym) in 1 : length (parameters (sys))
225
+ end
226
+
227
+ return any (isequal (sym), parameters (sys)) || hasname (sym) && is_parameter (sys, getname (sym))
228
+ end
229
+
230
+ function SymbolicIndexingInterface. is_parameter (sys:: AbstractSystem , sym:: Symbol )
231
+ return any (isequal (sym), getname .(parameters (sys))) ||
232
+ count (' ₊' , string (sym)) == 1 && count (isequal (sym), Symbol .(sys. name, :₊ , getname .(parameters (sys)))) == 1
233
+ end
234
+
235
+ function SymbolicIndexingInterface. parameter_index (sys:: AbstractSystem , sym)
236
+ if unwrap (sym) isa Int
237
+ return unwrap (sym)
238
+ end
239
+ idx = findfirst (isequal (sym), parameters (sys))
240
+ if idx === nothing && hasname (sym)
241
+ idx = parameter_index (sys, getname (sym))
242
+ end
243
+ return idx
244
+ end
245
+
246
+ function SymbolicIndexingInterface. parameter_index (sys:: AbstractSystem , sym:: Symbol )
247
+ idx = findfirst (isequal (sym), getname .(parameters (sys)))
248
+ if idx != = nothing
249
+ return idx
250
+ elseif count (' ₊' , string (sym)) == 1
251
+ return findfirst (isequal (sym), Symbol .(sys. name, :₊ , getname .(parameters (sys))))
252
+ end
253
+ return nothing
254
+ end
255
+
256
+ function SymbolicIndexingInterface. parameter_symbols (sys:: AbstractSystem )
257
+ return parameters (sys)
258
+ end
259
+
260
+ function SymbolicIndexingInterface. is_independent_variable (sys:: AbstractSystem , sym)
261
+ return any (isequal (sym), independent_variables (sys))
262
+ end
263
+
264
+ function SymbolicIndexingInterface. is_independent_variable (sys:: AbstractSystem , sym:: Symbol )
265
+ return any (isequal (sym), getname .(independent_variables (sys)))
266
+ end
267
+
268
+ function SymbolicIndexingInterface. independent_variable_symbols (sys:: AbstractSystem )
269
+ return independent_variables (sys)
270
+ end
271
+
272
+ function SymbolicIndexingInterface. is_observed (sys:: AbstractSystem , sym)
273
+ return ! is_variable (sys, sym) && ! is_parameter (sys, sym) && ! is_independent_variable (sys, sym) && symbolic_type (sym) != NotSymbolic ()
274
+ end
275
+
276
+ SymbolicIndexingInterface. is_time_dependent (:: AbstractTimeDependentSystem ) = true
277
+ SymbolicIndexingInterface. is_time_dependent (:: AbstractTimeIndependentSystem ) = false
278
+
279
+ SymbolicIndexingInterface. constant_structure (:: AbstractSystem ) = true
280
+
185
281
iscomplete (sys:: AbstractSystem ) = isdefined (sys, :complete ) && getfield (sys, :complete )
186
282
187
283
"""
@@ -534,12 +630,15 @@ function states(sys::AbstractSystem)
534
630
[sts; reduce (vcat, namespace_variables .(systems))])
535
631
end
536
632
537
- function SymbolicIndexingInterface . parameters (sys:: AbstractSystem )
633
+ function parameters (sys:: AbstractSystem )
538
634
ps = get_ps (sys)
539
635
systems = get_systems (sys)
540
636
unique (isempty (systems) ? ps : [ps; reduce (vcat, namespace_parameters .(systems))])
541
637
end
542
638
639
+ # required in `src/connectors.jl:437`
640
+ parameters (_) = []
641
+
543
642
function controls (sys:: AbstractSystem )
544
643
ctrls = get_ctrls (sys)
545
644
systems = get_systems (sys)
@@ -638,8 +737,6 @@ function time_varying_as_func(x, sys::AbstractTimeDependentSystem)
638
737
return x
639
738
end
640
739
641
- SymbolicIndexingInterface. is_indep_sym (sys:: AbstractSystem , sym) = isequal (sym, get_iv (sys))
642
-
643
740
"""
644
741
$(SIGNATURES)
645
742
@@ -653,20 +750,6 @@ function unknown_states(sys::AbstractSystem)
653
750
return sts
654
751
end
655
752
656
- function SymbolicIndexingInterface. state_sym_to_index (sys:: AbstractSystem , sym)
657
- findfirst (isequal (sym), unknown_states (sys))
658
- end
659
- function SymbolicIndexingInterface. is_state_sym (sys:: AbstractSystem , sym)
660
- ! isnothing (SymbolicIndexingInterface. state_sym_to_index (sys, sym))
661
- end
662
-
663
- function SymbolicIndexingInterface. param_sym_to_index (sys:: AbstractSystem , sym)
664
- findfirst (isequal (sym), SymbolicIndexingInterface. parameters (sys))
665
- end
666
- function SymbolicIndexingInterface. is_param_sym (sys:: AbstractSystem , sym)
667
- ! isnothing (SymbolicIndexingInterface. param_sym_to_index (sys, sym))
668
- end
669
-
670
753
# ##
671
754
# ## System utils
672
755
# ##
0 commit comments