@@ -1292,8 +1292,12 @@ $(TYPEDSIGNATURES)
1292
1292
Get the unknown variables of the system `sys` and its subsystems.
1293
1293
1294
1294
See also [`ModelingToolkit.get_unknowns`](@ref).
1295
+
1296
+ Arguments:
1297
+ - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
1295
1298
"""
1296
1299
function unknowns (sys:: AbstractSystem ; toplevel = false )
1300
+ toplevel && (sys = recursive_get_parent (sys))
1297
1301
sts = get_unknowns (sys)
1298
1302
systems = get_systems (sys)
1299
1303
nonunique_unknowns = if toplevel || isempty (systems)
@@ -1319,8 +1323,12 @@ $(TYPEDSIGNATURES)
1319
1323
Get the parameters of the system `sys` and its subsystems.
1320
1324
1321
1325
See also [`@parameters`](@ref) and [`ModelingToolkit.get_ps`](@ref).
1326
+
1327
+ Arguments:
1328
+ - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
1322
1329
"""
1323
1330
function parameters (sys:: AbstractSystem ; initial_parameters = false , toplevel = false )
1331
+ toplevel && (sys = recursive_get_parent (sys))
1324
1332
ps = get_ps (sys)
1325
1333
if ps == SciMLBase. NullParameters ()
1326
1334
return []
@@ -1353,6 +1361,22 @@ function dependent_parameters(sys::AbstractSystem)
1353
1361
return map (eq -> eq. lhs, parameter_dependencies (sys))
1354
1362
end
1355
1363
1364
+ """
1365
+ recursive_get_parent(sys::AbstractSystem)
1366
+
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.
1372
+ """
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)
1376
+ end
1377
+ return sys
1378
+ end
1379
+
1356
1380
"""
1357
1381
$(TYPEDSIGNATURES)
1358
1382
Get the parameter dependencies of the system `sys` and its subsystems.
@@ -1491,6 +1515,7 @@ function controls(sys::AbstractSystem)
1491
1515
end
1492
1516
1493
1517
function observed (sys:: AbstractSystem ; toplevel = false )
1518
+ toplevel && (sys = recursive_get_parent (sys))
1494
1519
obs = get_observed (sys)
1495
1520
toplevel && return obs
1496
1521
systems = get_systems (sys)
@@ -1550,8 +1575,12 @@ It may include some abbreviations and aliases of observables.
1550
1575
It is often the most useful way to inspect the equations of a system.
1551
1576
1552
1577
See also [`full_equations`](@ref) and [`ModelingToolkit.get_eqs`](@ref).
1578
+
1579
+ Arguments:
1580
+ - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
1553
1581
"""
1554
1582
function equations (sys:: AbstractSystem ; toplevel = false )
1583
+ toplevel && (sys = recursive_get_parent (sys))
1555
1584
eqs = get_eqs (sys)
1556
1585
systems = get_systems (sys)
1557
1586
if toplevel || isempty (systems)
0 commit comments