Skip to content

Commit 1dcf7c6

Browse files
refactor: store ignored analysis points as IgnoredAnalysisPoint
1 parent 5691fa3 commit 1dcf7c6

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

src/systems/abstractsystem.jl

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,9 +1421,34 @@ function assertions(sys::AbstractSystem)
14211421
return merge(asserts, namespaced_asserts)
14221422
end
14231423

1424+
"""
1425+
$(TYPEDEF)
1426+
1427+
Information about an `AnalysisPoint` for which the corresponding connection must be
1428+
ignored during `expand_connections`, since the analysis point has been transformed.
1429+
1430+
# Fields
1431+
1432+
$(TYPEDFIELDS)
1433+
"""
1434+
struct IgnoredAnalysisPoint
1435+
"""
1436+
The input variable/connector.
1437+
"""
1438+
input::Union{BasicSymbolic, AbstractSystem}
1439+
"""
1440+
The output variables/connectors.
1441+
"""
1442+
outputs::Vector{Union{BasicSymbolic, AbstractSystem}}
1443+
end
1444+
14241445
const HierarchyVariableT = Vector{Union{BasicSymbolic, Symbol}}
14251446
const HierarchySystemT = Vector{Union{AbstractSystem, Symbol}}
14261447
"""
1448+
The type returned from `analysis_point_common_hierarchy`.
1449+
"""
1450+
const HierarchyAnalysisPointT = Vector{Union{IgnoredAnalysisPoint, Symbol}}
1451+
"""
14271452
The type returned from `as_hierarchy`.
14281453
"""
14291454
const HierarchyT = Union{HierarchyVariableT, HierarchySystemT}
@@ -1440,6 +1465,29 @@ function from_hierarchy(hierarchy::HierarchyT)
14401465
end
14411466
end
14421467

1468+
"""
1469+
$(TYPEDSIGNATURES)
1470+
1471+
Represent an ignored analysis point as a namespaced hierarchy. The hierarchy is built
1472+
using the common hierarchy of all involved systems/variables.
1473+
"""
1474+
function analysis_point_common_hierarchy(ap::IgnoredAnalysisPoint)::HierarchyAnalysisPointT
1475+
isys = as_hierarchy(ap.input)
1476+
osyss = as_hierarchy.(ap.outputs)
1477+
suffix = Symbol[]
1478+
while isys[end] == osyss[1][end] && allequal(last.(osyss))
1479+
push!(suffix, isys[end])
1480+
pop!(isys)
1481+
pop!.(osyss)
1482+
end
1483+
isys = from_hierarchy(isys)
1484+
osyss = from_hierarchy.(osyss)
1485+
newap = IgnoredAnalysisPoint(isys, osyss)
1486+
hierarchy = HierarchyAnalysisPointT([suffix; newap])
1487+
reverse!(hierarchy)
1488+
return hierarchy
1489+
end
1490+
14431491
"""
14441492
$(TYPEDSIGNATURES)
14451493
@@ -1466,19 +1514,20 @@ end
14661514
"""
14671515
$(TYPEDSIGNATURES)
14681516
1469-
Get the connections to ignore for `sys` and its subsystems. The returned value is a
1470-
`Tuple` similar in structure to the `ignored_connections` field. Each system (variable)
1471-
in the first (second) element of the tuple is also passed through `as_hierarchy`.
1517+
Get the analysis points to ignore for `sys` and its subsystems. The returned value is a
1518+
`Tuple` similar in structure to the `ignored_connections` field.
14721519
"""
14731520
function ignored_connections(sys::AbstractSystem)
1474-
has_ignored_connections(sys) || return (HierarchySystemT[], HierarchyVariableT[])
1521+
has_ignored_connections(sys) ||
1522+
return (HierarchyAnalysisPointT[], HierarchyAnalysisPointT[])
14751523

14761524
ics = get_ignored_connections(sys)
14771525
if ics === nothing
1478-
ics = (HierarchySystemT[], HierarchyVariableT[])
1526+
ics = (HierarchyAnalysisPointT[], HierarchyAnalysisPointT[])
14791527
end
14801528
# turn into hierarchies
1481-
ics = (map(as_hierarchy, ics[1]), map(as_hierarchy, ics[2]))
1529+
ics = (map(analysis_point_common_hierarchy, ics[1]),
1530+
map(analysis_point_common_hierarchy, ics[2]))
14821531
systems = get_systems(sys)
14831532
# for each subsystem, get its ignored connections, add the name of the subsystem
14841533
# to the hierarchy and concatenate corresponding buffers of the result
@@ -1487,7 +1536,8 @@ function ignored_connections(sys::AbstractSystem)
14871536
(map(Base.Fix2(push!, nameof(subsys)), sub_ics[1]),
14881537
map(Base.Fix2(push!, nameof(subsys)), sub_ics[2]))
14891538
end
1490-
return (Vector{HierarchySystemT}(result[1]), Vector{HierarchyVariableT}(result[2]))
1539+
return (Vector{HierarchyAnalysisPointT}(result[1]),
1540+
Vector{HierarchyAnalysisPointT}(result[2]))
14911541
end
14921542

14931543
"""

src/systems/diffeqs/odesystem.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,12 @@ struct ODESystem <: AbstractODESystem
189189
"""
190190
split_idxs::Union{Nothing, Vector{Vector{Int}}}
191191
"""
192-
The connections to ignore (since they're removed by analysis point transformations).
193-
The first element of the tuple are systems that can't be in the same connection set,
194-
and the second are variables (for the trivial form of `connect`).
192+
The analysis points removed by transformations, representing connections to be
193+
ignored. The first element of the tuple analysis points connecting systems and
194+
the second are ones connecting variables (for the trivial form of `connect`).
195195
"""
196-
ignored_connections::Union{Nothing, Tuple{Vector{ODESystem}, Vector{BasicSymbolic}}}
196+
ignored_connections::Union{
197+
Nothing, Tuple{Vector{IgnoredAnalysisPoint}, Vector{IgnoredAnalysisPoint}}}
197198
"""
198199
The hierarchical parent system before simplification.
199200
"""

0 commit comments

Comments
 (0)