Skip to content

Commit 3e381fc

Browse files
refactor: store ignored analysis points as IgnoredAnalysisPoint
1 parent 0ad773d commit 3e381fc

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
@@ -1397,9 +1397,34 @@ function assertions(sys::AbstractSystem)
13971397
return merge(asserts, namespaced_asserts)
13981398
end
13991399

1400+
"""
1401+
$(TYPEDEF)
1402+
1403+
Information about an `AnalysisPoint` for which the corresponding connection must be
1404+
ignored during `expand_connections`, since the analysis point has been transformed.
1405+
1406+
# Fields
1407+
1408+
$(TYPEDFIELDS)
1409+
"""
1410+
struct IgnoredAnalysisPoint
1411+
"""
1412+
The input variable/connector.
1413+
"""
1414+
input::Union{BasicSymbolic, AbstractSystem}
1415+
"""
1416+
The output variables/connectors.
1417+
"""
1418+
outputs::Vector{Union{BasicSymbolic, AbstractSystem}}
1419+
end
1420+
14001421
const HierarchyVariableT = Vector{Union{BasicSymbolic, Symbol}}
14011422
const HierarchySystemT = Vector{Union{AbstractSystem, Symbol}}
14021423
"""
1424+
The type returned from `analysis_point_common_hierarchy`.
1425+
"""
1426+
const HierarchyAnalysisPointT = Vector{Union{IgnoredAnalysisPoint, Symbol}}
1427+
"""
14031428
The type returned from `as_hierarchy`.
14041429
"""
14051430
const HierarchyT = Union{HierarchyVariableT, HierarchySystemT}
@@ -1416,6 +1441,29 @@ function from_hierarchy(hierarchy::HierarchyT)
14161441
end
14171442
end
14181443

1444+
"""
1445+
$(TYPEDSIGNATURES)
1446+
1447+
Represent an ignored analysis point as a namespaced hierarchy. The hierarchy is built
1448+
using the common hierarchy of all involved systems/variables.
1449+
"""
1450+
function analysis_point_common_hierarchy(ap::IgnoredAnalysisPoint)::HierarchyAnalysisPointT
1451+
isys = as_hierarchy(ap.input)
1452+
osyss = as_hierarchy.(ap.outputs)
1453+
suffix = Symbol[]
1454+
while isys[end] == osyss[1][end] && allequal(last.(osyss))
1455+
push!(suffix, isys[end])
1456+
pop!(isys)
1457+
pop!.(osyss)
1458+
end
1459+
isys = from_hierarchy(isys)
1460+
osyss = from_hierarchy.(osyss)
1461+
newap = IgnoredAnalysisPoint(isys, osyss)
1462+
hierarchy = HierarchyAnalysisPointT([suffix; newap])
1463+
reverse!(hierarchy)
1464+
return hierarchy
1465+
end
1466+
14191467
"""
14201468
$(TYPEDSIGNATURES)
14211469
@@ -1442,19 +1490,20 @@ end
14421490
"""
14431491
$(TYPEDSIGNATURES)
14441492
1445-
Get the connections to ignore for `sys` and its subsystems. The returned value is a
1446-
`Tuple` similar in structure to the `ignored_connections` field. Each system (variable)
1447-
in the first (second) element of the tuple is also passed through `as_hierarchy`.
1493+
Get the analysis points to ignore for `sys` and its subsystems. The returned value is a
1494+
`Tuple` similar in structure to the `ignored_connections` field.
14481495
"""
14491496
function ignored_connections(sys::AbstractSystem)
1450-
has_ignored_connections(sys) || return (HierarchySystemT[], HierarchyVariableT[])
1497+
has_ignored_connections(sys) ||
1498+
return (HierarchyAnalysisPointT[], HierarchyAnalysisPointT[])
14511499

14521500
ics = get_ignored_connections(sys)
14531501
if ics === nothing
1454-
ics = (HierarchySystemT[], HierarchyVariableT[])
1502+
ics = (HierarchyAnalysisPointT[], HierarchyAnalysisPointT[])
14551503
end
14561504
# turn into hierarchies
1457-
ics = (map(as_hierarchy, ics[1]), map(as_hierarchy, ics[2]))
1505+
ics = (map(analysis_point_common_hierarchy, ics[1]),
1506+
map(analysis_point_common_hierarchy, ics[2]))
14581507
systems = get_systems(sys)
14591508
# for each subsystem, get its ignored connections, add the name of the subsystem
14601509
# to the hierarchy and concatenate corresponding buffers of the result
@@ -1463,7 +1512,8 @@ function ignored_connections(sys::AbstractSystem)
14631512
(map(Base.Fix2(push!, nameof(subsys)), sub_ics[1]),
14641513
map(Base.Fix2(push!, nameof(subsys)), sub_ics[2]))
14651514
end
1466-
return (Vector{HierarchySystemT}(result[1]), Vector{HierarchyVariableT}(result[2]))
1515+
return (Vector{HierarchyAnalysisPointT}(result[1]),
1516+
Vector{HierarchyAnalysisPointT}(result[2]))
14671517
end
14681518

14691519
"""

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)