@@ -190,6 +190,16 @@ struct System <: IntermediateDeprecationSystem
190190 """
191191 tstops:: Vector{Any}
192192 """
193+ $INTERNAL_FIELD_WARNING
194+ The list of input variables of the system.
195+ """
196+ inputs:: OrderedSet{BasicSymbolic}
197+ """
198+ $INTERNAL_FIELD_WARNING
199+ The list of output variables of the system.
200+ """
201+ outputs:: OrderedSet{BasicSymbolic}
202+ """
193203 The `TearingState` of the system post-simplification with `mtkcompile`.
194204 """
195205 tearing_state:: Any
@@ -255,8 +265,9 @@ struct System <: IntermediateDeprecationSystem
255265 brownians, iv, observed, parameter_dependencies, var_to_name, name, description,
256266 defaults, guesses, systems, initialization_eqs, continuous_events, discrete_events,
257267 connector_type, assertions = Dict {BasicSymbolic, String} (),
258- metadata = MetadataT (), gui_metadata = nothing ,
259- is_dde = false , tstops = [], tearing_state = nothing , namespacing = true ,
268+ metadata = MetadataT (), gui_metadata = nothing , is_dde = false , tstops = [],
269+ inputs = Set {BasicSymbolic} (), outputs = Set {BasicSymbolic} (),
270+ tearing_state = nothing , namespacing = true ,
260271 complete = false , index_cache = nothing , ignored_connections = nothing ,
261272 preface = nothing , parent = nothing , initializesystem = nothing ,
262273 is_initializesystem = false , is_discrete = false , isscheduled = false ,
@@ -296,7 +307,8 @@ struct System <: IntermediateDeprecationSystem
296307 observed, parameter_dependencies, var_to_name, name, description, defaults,
297308 guesses, systems, initialization_eqs, continuous_events, discrete_events,
298309 connector_type, assertions, metadata, gui_metadata, is_dde,
299- tstops, tearing_state, namespacing, complete, index_cache, ignored_connections,
310+ tstops, inputs, outputs, tearing_state, namespacing,
311+ complete, index_cache, ignored_connections,
300312 preface, parent, initializesystem, is_initializesystem, is_discrete,
301313 isscheduled, schedule)
302314 end
@@ -367,15 +379,35 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
367379
368380 defaults = anydict (defaults)
369381 guesses = anydict (guesses)
382+ inputs = OrderedSet {BasicSymbolic} ()
383+ outputs = OrderedSet {BasicSymbolic} ()
384+ for subsys in systems
385+ for var in ModelingToolkit. inputs (subsys)
386+ push! (inputs, renamespace (subsys, var))
387+ end
388+ for var in ModelingToolkit. outputs (subsys)
389+ push! (outputs, renamespace (subsys, var))
390+ end
391+ end
370392 var_to_name = anydict ()
371393
372394 let defaults = discover_from_metadata ? defaults : Dict (),
373- guesses = discover_from_metadata ? guesses : Dict ()
395+ guesses = discover_from_metadata ? guesses : Dict (),
396+ inputs = discover_from_metadata ? inputs : Set (),
397+ outputs = discover_from_metadata ? outputs : Set ()
374398
375399 process_variables! (var_to_name, defaults, guesses, dvs)
376400 process_variables! (var_to_name, defaults, guesses, ps)
377401 process_variables! (var_to_name, defaults, guesses, [eq. lhs for eq in observed])
378402 process_variables! (var_to_name, defaults, guesses, [eq. rhs for eq in observed])
403+
404+ for var in dvs
405+ if isinput (var)
406+ push! (inputs, var)
407+ elseif isoutput (var)
408+ push! (outputs, var)
409+ end
410+ end
379411 end
380412 filter! (! (isnothing ∘ last), defaults)
381413 filter! (! (isnothing ∘ last), guesses)
@@ -417,7 +449,8 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
417449 costs, consolidate, dvs, ps, brownians, iv, observed, Equation[],
418450 var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
419451 continuous_events, discrete_events, connector_type, assertions, metadata, gui_metadata, is_dde,
420- tstops, tearing_state, true , false , nothing , ignored_connections, preface, parent,
452+ tstops, inputs, outputs, tearing_state, true , false ,
453+ nothing , ignored_connections, preface, parent,
421454 initializesystem, is_initializesystem, is_discrete; checks)
422455end
423456
@@ -1143,6 +1176,8 @@ function Base.isapprox(sysa::System, sysb::System)
11431176 isequal (get_metadata (sysa), get_metadata (sysb)) &&
11441177 isequal (get_is_dde (sysa), get_is_dde (sysb)) &&
11451178 issetequal (get_tstops (sysa), get_tstops (sysb)) &&
1179+ issetequal (get_inputs (sysa), get_inputs (sysb)) &&
1180+ issetequal (get_outputs (sysa), get_outputs (sysb)) &&
11461181 safe_issetequal (get_ignored_connections (sysa), get_ignored_connections (sysb)) &&
11471182 isequal (get_is_initializesystem (sysa), get_is_initializesystem (sysb)) &&
11481183 isequal (get_is_discrete (sysa), get_is_discrete (sysb)) &&
0 commit comments