@@ -161,10 +161,18 @@ function independent_variable(sys::AbstractSystem)
161161 isdefined (sys, :iv ) ? getfield (sys, :iv ) : nothing
162162end
163163
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`."
168176 if isdefined (sys, :iv )
169177 return [getfield (sys, :iv )]
170178 elseif isdefined (sys, :ivs )
@@ -174,14 +182,102 @@ function SymbolicIndexingInterface.independent_variables(sys::AbstractSystem)
174182 end
175183end
176184
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
179195end
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
183206end
184207
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+
185281iscomplete (sys:: AbstractSystem ) = isdefined (sys, :complete ) && getfield (sys, :complete )
186282
187283"""
@@ -534,12 +630,15 @@ function states(sys::AbstractSystem)
534630 [sts; reduce (vcat, namespace_variables .(systems))])
535631end
536632
537- function SymbolicIndexingInterface . parameters (sys:: AbstractSystem )
633+ function parameters (sys:: AbstractSystem )
538634 ps = get_ps (sys)
539635 systems = get_systems (sys)
540636 unique (isempty (systems) ? ps : [ps; reduce (vcat, namespace_parameters .(systems))])
541637end
542638
639+ # required in `src/connectors.jl:437`
640+ parameters (_) = []
641+
543642function controls (sys:: AbstractSystem )
544643 ctrls = get_ctrls (sys)
545644 systems = get_systems (sys)
@@ -638,8 +737,6 @@ function time_varying_as_func(x, sys::AbstractTimeDependentSystem)
638737 return x
639738end
640739
641- SymbolicIndexingInterface. is_indep_sym (sys:: AbstractSystem , sym) = isequal (sym, get_iv (sys))
642-
643740"""
644741$(SIGNATURES)
645742
@@ -653,20 +750,6 @@ function unknown_states(sys::AbstractSystem)
653750 return sts
654751end
655752
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-
670753# ##
671754# ## System utils
672755# ##
0 commit comments