@@ -1292,15 +1292,11 @@ $(TYPEDSIGNATURES)
12921292Get the unknown variables of the system `sys` and its subsystems.
12931293
12941294See also [`ModelingToolkit.get_unknowns`](@ref).
1295-
1296- Arguments:
1297- - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
12981295"""
1299- function unknowns (sys:: AbstractSystem ; toplevel = false )
1300- toplevel && (sys = recursive_get_parent (sys))
1296+ function unknowns (sys:: AbstractSystem )
13011297 sts = get_unknowns (sys)
13021298 systems = get_systems (sys)
1303- nonunique_unknowns = if toplevel || isempty (systems)
1299+ nonunique_unknowns = if isempty (systems)
13041300 sts
13051301 else
13061302 system_unknowns = reduce (vcat, namespace_variables .(systems))
@@ -1317,18 +1313,28 @@ function unknowns(sys::AbstractSystem; toplevel = false)
13171313 unique (nonunique_unknowns)
13181314end
13191315
1316+ """
1317+ unknowns_toplevel(sys::AbstractSystem)
1318+
1319+ Replicates the behaviour of `unknowns`, but ignores unknowns of subsystems.
1320+ """
1321+ function unknowns_toplevel (sys:: AbstractSystem )
1322+ if has_parent (sys) && (parent = get_parent (sys)) != = nothing
1323+ return unknowns_toplevel (parent)
1324+ end
1325+ return get_unknowns (sys)
1326+ end
1327+
1328+
13201329"""
13211330$(TYPEDSIGNATURES)
13221331
13231332Get the parameters of the system `sys` and its subsystems.
13241333
13251334See also [`@parameters`](@ref) and [`ModelingToolkit.get_ps`](@ref).
13261335
1327- Arguments:
1328- - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
13291336"""
1330- function parameters (sys:: AbstractSystem ; initial_parameters = false , toplevel = false )
1331- toplevel && (sys = recursive_get_parent (sys))
1337+ function parameters (sys:: AbstractSystem ; initial_parameters = false )
13321338 ps = get_ps (sys)
13331339 if ps == SciMLBase. NullParameters ()
13341340 return []
@@ -1337,7 +1343,7 @@ function parameters(sys::AbstractSystem; initial_parameters = false, toplevel =
13371343 ps = first .(ps)
13381344 end
13391345 systems = get_systems (sys)
1340- result = unique (toplevel || isempty (systems) ?
1346+ result = unique (isempty (systems) ?
13411347 ps : [ps; reduce (vcat, namespace_parameters .(systems))])
13421348 if ! initial_parameters
13431349 if is_time_dependent (sys)
@@ -1362,19 +1368,15 @@ function dependent_parameters(sys::AbstractSystem)
13621368end
13631369
13641370"""
1365- recursive_get_parent (sys::AbstractSystem)
1371+ parameters_toplevel (sys::AbstractSystem)
13661372
1367- Loops through parent systems to find the original parent system.
1368-
1369- Warning:
1370- - Curently only used (and tested) in the context of accessor functions (e.g. `parameters`),
1371- specifically in the context of the `toplevel` keyword argument.
1373+ Replicates the behaviour of `parameters`, but ignores parameters of subsystems.
13721374"""
1373- function recursive_get_parent (sys:: AbstractSystem )
1374- if ModelingToolkit . has_parent (sys) && (p = ModelingToolkit . get_parent (sys)) != = nothing
1375- return recursive_get_parent (p )
1375+ function parameters_toplevel (sys:: AbstractSystem )
1376+ if has_parent (sys) && (parent = get_parent (sys)) != = nothing
1377+ return parameters_toplevel (parent )
13761378 end
1377- return sys
1379+ return get_ps ( sys)
13781380end
13791381
13801382"""
@@ -1514,10 +1516,8 @@ function controls(sys::AbstractSystem)
15141516 isempty (systems) ? ctrls : [ctrls; reduce (vcat, namespace_controls .(systems))]
15151517end
15161518
1517- function observed (sys:: AbstractSystem ; toplevel = false )
1518- toplevel && (sys = recursive_get_parent (sys))
1519+ function observed (sys:: AbstractSystem )
15191520 obs = get_observed (sys)
1520- toplevel && return obs
15211521 systems = get_systems (sys)
15221522 [obs;
15231523 reduce (vcat,
@@ -1536,7 +1536,7 @@ If they are not explicitly provided, variables and parameters are initialized to
15361536
15371537See also [`initialization_equations`](@ref), [`parameter_dependencies`](@ref) and [`ModelingToolkit.get_defaults`](@ref).
15381538"""
1539- function defaults (sys:: AbstractSystem ; toplevel = false )
1539+ function defaults (sys:: AbstractSystem )
15401540 systems = get_systems (sys)
15411541 defs = get_defaults (sys)
15421542 # `mapfoldr` is really important!!! We should prefer the base model for
@@ -1545,8 +1545,7 @@ function defaults(sys::AbstractSystem; toplevel = false)
15451545 # `compose(ODESystem(...; defaults=defs), ...)`
15461546 #
15471547 # Thus, right associativity is required and crucial for correctness.
1548- (toplevel || isempty (systems)) ?
1549- defs : mapfoldr (namespace_defaults, merge, systems; init = defs)
1548+ isempty (systems) ? defs : mapfoldr (namespace_defaults, merge, systems; init = defs)
15501549end
15511550
15521551function defaults_and_guesses (sys:: AbstractSystem )
@@ -1576,14 +1575,11 @@ It is often the most useful way to inspect the equations of a system.
15761575
15771576See also [`full_equations`](@ref) and [`ModelingToolkit.get_eqs`](@ref).
15781577
1579- Arguments:
1580- - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
15811578"""
1582- function equations (sys:: AbstractSystem ; toplevel = false )
1583- toplevel && (sys = recursive_get_parent (sys))
1579+ function equations (sys:: AbstractSystem )
15841580 eqs = get_eqs (sys)
15851581 systems = get_systems (sys)
1586- if toplevel || isempty (systems)
1582+ if isempty (systems)
15871583 return eqs
15881584 else
15891585 eqs = Equation[eqs;
@@ -1594,6 +1590,23 @@ function equations(sys::AbstractSystem; toplevel = false)
15941590 end
15951591end
15961592
1593+
1594+ """
1595+ equations_toplevel(sys::AbstractSystem)
1596+
1597+ Replicates the behaviour of `equations`, but ignores equations of subsystems.
1598+
1599+ Notes:
1600+ - Cannot be applied to non-complete systems.
1601+ """
1602+ function equations_toplevel (sys:: AbstractSystem )
1603+ iscomplete (sys) && error (" Cannot apply `equations_toplevel` to complete systems." )
1604+ if has_parent (sys) && (parent = get_parent (sys)) != = nothing
1605+ return equations_toplevel (parent)
1606+ end
1607+ return get_eqs (sys)
1608+ end
1609+
15971610"""
15981611$(TYPEDSIGNATURES)
15991612
0 commit comments