Skip to content

Commit 254201c

Browse files
fix: properly sort SCCs
1 parent 2c2daf6 commit 254201c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,17 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
606606

607607
ts = get_tearing_state(sys)
608608
var_eq_matching, var_sccs = StructuralTransformations.algebraic_variables_scc(ts)
609-
# The system is simplified, so SCCs are already in sorted order. We just need to get them and sort
610-
# according to index in unknowns(sys)
611-
sort!(var_sccs)
609+
610+
if length(var_sccs) == 1
611+
return NonlinearProblem{iip}(sys, u0map, parammap; eval_expression, eval_module, kwargs...)
612+
end
613+
614+
condensed_graph = MatchedCondensationGraph(
615+
DiCMOBiGraph{true}(complete(ts.structure.graph),
616+
complete(var_eq_matching)),
617+
var_sccs)
618+
toporder = topological_sort_by_dfs(condensed_graph)
619+
var_sccs = var_sccs[toporder]
612620
eq_sccs = map(Base.Fix1(getindex, var_eq_matching), var_sccs)
613621

614622
dvs = unknowns(sys)

0 commit comments

Comments
 (0)