@@ -190,6 +190,16 @@ struct System <: IntermediateDeprecationSystem
190
190
"""
191
191
tstops:: Vector{Any}
192
192
"""
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
+ """
193
203
The `TearingState` of the system post-simplification with `mtkcompile`.
194
204
"""
195
205
tearing_state:: Any
@@ -255,8 +265,9 @@ struct System <: IntermediateDeprecationSystem
255
265
brownians, iv, observed, parameter_dependencies, var_to_name, name, description,
256
266
defaults, guesses, systems, initialization_eqs, continuous_events, discrete_events,
257
267
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 ,
260
271
complete = false , index_cache = nothing , ignored_connections = nothing ,
261
272
preface = nothing , parent = nothing , initializesystem = nothing ,
262
273
is_initializesystem = false , is_discrete = false , isscheduled = false ,
@@ -296,7 +307,8 @@ struct System <: IntermediateDeprecationSystem
296
307
observed, parameter_dependencies, var_to_name, name, description, defaults,
297
308
guesses, systems, initialization_eqs, continuous_events, discrete_events,
298
309
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,
300
312
preface, parent, initializesystem, is_initializesystem, is_discrete,
301
313
isscheduled, schedule)
302
314
end
@@ -332,7 +344,8 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
332
344
continuous_events = SymbolicContinuousCallback[], discrete_events = SymbolicDiscreteCallback[],
333
345
connector_type = nothing , assertions = Dict {BasicSymbolic, String} (),
334
346
metadata = MetadataT (), gui_metadata = nothing ,
335
- is_dde = nothing , tstops = [], tearing_state = nothing ,
347
+ is_dde = nothing , tstops = [], inputs = OrderedSet {BasicSymbolic} (),
348
+ outputs = OrderedSet {BasicSymbolic} (), tearing_state = nothing ,
336
349
ignored_connections = nothing , parent = nothing ,
337
350
description = " " , name = nothing , discover_from_metadata = true ,
338
351
initializesystem = nothing , is_initializesystem = false , is_discrete = false ,
@@ -367,15 +380,35 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
367
380
368
381
defaults = anydict (defaults)
369
382
guesses = anydict (guesses)
383
+ inputs = OrderedSet {BasicSymbolic} (inputs)
384
+ outputs = OrderedSet {BasicSymbolic} (outputs)
385
+ for subsys in systems
386
+ for var in ModelingToolkit. inputs (subsys)
387
+ push! (inputs, renamespace (subsys, var))
388
+ end
389
+ for var in ModelingToolkit. outputs (subsys)
390
+ push! (outputs, renamespace (subsys, var))
391
+ end
392
+ end
370
393
var_to_name = anydict ()
371
394
372
395
let defaults = discover_from_metadata ? defaults : Dict (),
373
- guesses = discover_from_metadata ? guesses : Dict ()
396
+ guesses = discover_from_metadata ? guesses : Dict (),
397
+ inputs = discover_from_metadata ? inputs : Set (),
398
+ outputs = discover_from_metadata ? outputs : Set ()
374
399
375
400
process_variables! (var_to_name, defaults, guesses, dvs)
376
401
process_variables! (var_to_name, defaults, guesses, ps)
377
402
process_variables! (var_to_name, defaults, guesses, [eq. lhs for eq in observed])
378
403
process_variables! (var_to_name, defaults, guesses, [eq. rhs for eq in observed])
404
+
405
+ for var in dvs
406
+ if isinput (var)
407
+ push! (inputs, var)
408
+ elseif isoutput (var)
409
+ push! (outputs, var)
410
+ end
411
+ end
379
412
end
380
413
filter! (! (isnothing ∘ last), defaults)
381
414
filter! (! (isnothing ∘ last), guesses)
@@ -417,7 +450,8 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
417
450
costs, consolidate, dvs, ps, brownians, iv, observed, Equation[],
418
451
var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
419
452
continuous_events, discrete_events, connector_type, assertions, metadata, gui_metadata, is_dde,
420
- tstops, tearing_state, true , false , nothing , ignored_connections, preface, parent,
453
+ tstops, inputs, outputs, tearing_state, true , false ,
454
+ nothing , ignored_connections, preface, parent,
421
455
initializesystem, is_initializesystem, is_discrete; checks)
422
456
end
423
457
@@ -731,6 +765,7 @@ function flatten(sys::System, noeqs = false)
731
765
discrete_events = discrete_events (sys), assertions = assertions (sys),
732
766
is_dde = is_dde (sys), tstops = symbolic_tstops (sys),
733
767
initialization_eqs = initialization_equations (sys),
768
+ inputs = inputs (sys), outputs = outputs (sys),
734
769
# without this, any defaults/guesses obtained from metadata that were
735
770
# later removed by the user will be re-added. Right now, we just want to
736
771
# retain `defaults(sys)` as-is.
@@ -1143,6 +1178,8 @@ function Base.isapprox(sysa::System, sysb::System)
1143
1178
isequal (get_metadata (sysa), get_metadata (sysb)) &&
1144
1179
isequal (get_is_dde (sysa), get_is_dde (sysb)) &&
1145
1180
issetequal (get_tstops (sysa), get_tstops (sysb)) &&
1181
+ issetequal (get_inputs (sysa), get_inputs (sysb)) &&
1182
+ issetequal (get_outputs (sysa), get_outputs (sysb)) &&
1146
1183
safe_issetequal (get_ignored_connections (sysa), get_ignored_connections (sysb)) &&
1147
1184
isequal (get_is_initializesystem (sysa), get_is_initializesystem (sysb)) &&
1148
1185
isequal (get_is_discrete (sysa), get_is_discrete (sysb)) &&
0 commit comments