Skip to content

Commit e79dc90

Browse files
fix: properly sort SCCs
1 parent b5fc3ed commit e79dc90

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
@@ -610,9 +610,17 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
610610

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

618626
dvs = unknowns(sys)

0 commit comments

Comments
 (0)