@@ -1292,15 +1292,11 @@ $(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.
1298
1295
"""
1299
- function unknowns (sys:: AbstractSystem ; toplevel = false )
1300
- toplevel && (sys = recursive_get_parent (sys))
1296
+ function unknowns (sys:: AbstractSystem )
1301
1297
sts = get_unknowns (sys)
1302
1298
systems = get_systems (sys)
1303
- nonunique_unknowns = if toplevel || isempty (systems)
1299
+ nonunique_unknowns = if isempty (systems)
1304
1300
sts
1305
1301
else
1306
1302
system_unknowns = reduce (vcat, namespace_variables .(systems))
@@ -1317,18 +1313,28 @@ function unknowns(sys::AbstractSystem; toplevel = false)
1317
1313
unique (nonunique_unknowns)
1318
1314
end
1319
1315
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
+
1320
1329
"""
1321
1330
$(TYPEDSIGNATURES)
1322
1331
1323
1332
Get the parameters of the system `sys` and its subsystems.
1324
1333
1325
1334
See also [`@parameters`](@ref) and [`ModelingToolkit.get_ps`](@ref).
1326
1335
1327
- Arguments:
1328
- - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
1329
1336
"""
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 )
1332
1338
ps = get_ps (sys)
1333
1339
if ps == SciMLBase. NullParameters ()
1334
1340
return []
@@ -1337,7 +1343,7 @@ function parameters(sys::AbstractSystem; initial_parameters = false, toplevel =
1337
1343
ps = first .(ps)
1338
1344
end
1339
1345
systems = get_systems (sys)
1340
- result = unique (toplevel || isempty (systems) ?
1346
+ result = unique (isempty (systems) ?
1341
1347
ps : [ps; reduce (vcat, namespace_parameters .(systems))])
1342
1348
if ! initial_parameters
1343
1349
if is_time_dependent (sys)
@@ -1362,19 +1368,15 @@ function dependent_parameters(sys::AbstractSystem)
1362
1368
end
1363
1369
1364
1370
"""
1365
- recursive_get_parent (sys::AbstractSystem)
1371
+ parameters_toplevel (sys::AbstractSystem)
1366
1372
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.
1372
1374
"""
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 )
1376
1378
end
1377
- return sys
1379
+ return get_ps ( sys)
1378
1380
end
1379
1381
1380
1382
"""
@@ -1514,10 +1516,8 @@ function controls(sys::AbstractSystem)
1514
1516
isempty (systems) ? ctrls : [ctrls; reduce (vcat, namespace_controls .(systems))]
1515
1517
end
1516
1518
1517
- function observed (sys:: AbstractSystem ; toplevel = false )
1518
- toplevel && (sys = recursive_get_parent (sys))
1519
+ function observed (sys:: AbstractSystem )
1519
1520
obs = get_observed (sys)
1520
- toplevel && return obs
1521
1521
systems = get_systems (sys)
1522
1522
[obs;
1523
1523
reduce (vcat,
@@ -1536,7 +1536,7 @@ If they are not explicitly provided, variables and parameters are initialized to
1536
1536
1537
1537
See also [`initialization_equations`](@ref), [`parameter_dependencies`](@ref) and [`ModelingToolkit.get_defaults`](@ref).
1538
1538
"""
1539
- function defaults (sys:: AbstractSystem ; toplevel = false )
1539
+ function defaults (sys:: AbstractSystem )
1540
1540
systems = get_systems (sys)
1541
1541
defs = get_defaults (sys)
1542
1542
# `mapfoldr` is really important!!! We should prefer the base model for
@@ -1545,8 +1545,7 @@ function defaults(sys::AbstractSystem; toplevel = false)
1545
1545
# `compose(ODESystem(...; defaults=defs), ...)`
1546
1546
#
1547
1547
# 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)
1550
1549
end
1551
1550
1552
1551
function defaults_and_guesses (sys:: AbstractSystem )
@@ -1576,14 +1575,11 @@ It is often the most useful way to inspect the equations of a system.
1576
1575
1577
1576
See also [`full_equations`](@ref) and [`ModelingToolkit.get_eqs`](@ref).
1578
1577
1579
- Arguments:
1580
- - `toplevel = false`: if set to true, do not return the continuous events of the subsystems.
1581
1578
"""
1582
- function equations (sys:: AbstractSystem ; toplevel = false )
1583
- toplevel && (sys = recursive_get_parent (sys))
1579
+ function equations (sys:: AbstractSystem )
1584
1580
eqs = get_eqs (sys)
1585
1581
systems = get_systems (sys)
1586
- if toplevel || isempty (systems)
1582
+ if isempty (systems)
1587
1583
return eqs
1588
1584
else
1589
1585
eqs = Equation[eqs;
@@ -1594,6 +1590,23 @@ function equations(sys::AbstractSystem; toplevel = false)
1594
1590
end
1595
1591
end
1596
1592
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
+
1597
1610
"""
1598
1611
$(TYPEDSIGNATURES)
1599
1612
0 commit comments