Skip to content

Commit a6ced9a

Browse files
refactor: use SCC information calculated during mtkcompile in SCCNonlinearProblem
1 parent bea3914 commit a6ced9a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/problems/sccnonlinearproblem.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,32 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::System, op; eval_expression = f
8080
end
8181

8282
ts = get_tearing_state(sys)
83-
var_eq_matching, var_sccs = StructuralTransformations.algebraic_variables_scc(ts)
83+
sched = get_schedule(sys)
84+
if sched === nothing
85+
@warn "System is simplified but does not have a schedule. This should not happen."
86+
var_eq_matching, var_sccs = StructuralTransformations.algebraic_variables_scc(ts)
87+
condensed_graph = MatchedCondensationGraph(
88+
DiCMOBiGraph{true}(complete(ts.structure.graph),
89+
complete(var_eq_matching)),
90+
var_sccs)
91+
toporder = topological_sort_by_dfs(condensed_graph)
92+
var_sccs = var_sccs[toporder]
93+
eq_sccs = map(Base.Fix1(getindex, var_eq_matching), var_sccs)
94+
else
95+
var_sccs = sched.var_sccs
96+
# Equations are already in the order of SCCs
97+
eq_sccs = length.(var_sccs)
98+
cumsum!(eq_sccs, eq_sccs)
99+
eq_sccs = map(enumerate(eq_sccs)) do (i, lasti)
100+
i == 1 ? (1:lasti) : ((eq_sccs[i - 1] + 1):lasti)
101+
end
102+
end
84103

85104
if length(var_sccs) == 1
86105
return NonlinearProblem{iip}(
87106
sys, op; eval_expression, eval_module, kwargs...)
88107
end
89108

90-
condensed_graph = MatchedCondensationGraph(
91-
DiCMOBiGraph{true}(complete(ts.structure.graph),
92-
complete(var_eq_matching)),
93-
var_sccs)
94-
toporder = topological_sort_by_dfs(condensed_graph)
95-
var_sccs = var_sccs[toporder]
96-
eq_sccs = map(Base.Fix1(getindex, var_eq_matching), var_sccs)
97-
98109
dvs = unknowns(sys)
99110
ps = parameters(sys)
100111
eqs = equations(sys)

0 commit comments

Comments
 (0)