@@ -503,7 +503,7 @@ function generate_system_equations!(state::TearingState, neweqs::Vector{Equation
503503 offset = 1
504504 findnextfn = let diff_vars_set = diff_vars_set, solved_vars_set = solved_vars_set,
505505 diff_to_var = diff_to_var, ispresent = ispresent
506- j -> ! (j in diff_vars_set || j in solved_vars_set) && diff_to_var[j] === nothing &&
506+ j -> ! (j in diff_vars_set || j in solved_vars_set || j in extra_vars ) && diff_to_var[j] === nothing &&
507507 ispresent (j)
508508 end
509509 for (i, v) in enumerate (var_ordering)
@@ -980,7 +980,7 @@ Update the system equations, unknowns, and observables after simplification.
980980function update_simplified_system! (
981981 state:: TearingState , neweqs:: Vector{Equation} , solved_eqs:: Vector{Equation} ,
982982 dummy_sub:: Dict{SymbolicT, SymbolicT} , var_sccs:: Vector{Vector{Int}} ,
983- extra_unknowns :: Vector{SymbolicT} , iv:: Union{SymbolicT, Nothing} ,
983+ iv:: Union{SymbolicT, Nothing} ,
984984 D:: Union{Differential, Shift, Nothing} ; array_hack = true )
985985 (; fullvars, structure) = state
986986 (; solvable_graph, var_to_diff, eq_to_diff, graph) = structure
@@ -1027,7 +1027,6 @@ function update_simplified_system!(
10271027 end
10281028 unknown_idxs = filter (filterer, eachindex (state. fullvars))
10291029 unknowns = state. fullvars[unknown_idxs]
1030- unknowns = [unknowns; extra_unknowns]
10311030 if StateSelection. is_only_discrete (structure)
10321031 # Algebraic variables are shifted forward by one, so we backshift them.
10331032 _unknowns = SymbolicT[]
@@ -1156,12 +1155,18 @@ function (alg::DefaultReassembleAlgorithm)(state::TearingState,
11561155 inline_linear_sccs = false
11571156 end
11581157
1159- extra_unknowns = state. fullvars[extra_eqs_vars[2 ]]
11601158 if StateSelection. is_only_discrete (state. structure)
11611159 var_sccs = add_additional_history! (
11621160 state, var_eq_matching, full_var_eq_matching, var_sccs, iv:: SymbolicT )
11631161 end
11641162
1163+ # Previously, we used to pass `state.fullvars[extra_eqs_vars[2]]` as `extra_unknowns`
1164+ # to `update_simplified_system!`. These were then appended to the list of unknowns.
1165+ # However, this is now unnecessary. `generate_system_equations!` uses a `setdiff` to
1166+ # populate `var_ordering` with all variables that should be in unknowns, including
1167+ # the extras. This is also required so that `reorder_vars!` subsets `state` correctly
1168+ # and the `singular_check` in initialization works.
1169+
11651170 # Structural simplification
11661171 if iv isa SymbolicT # Without iv we don't have derivatives
11671172 D = D:: Union{Differential, Shift}
@@ -1185,7 +1190,7 @@ function (alg::DefaultReassembleAlgorithm)(state::TearingState,
11851190 # var_eq_matching and full_var_eq_matching are now invalidated
11861191
11871192 sys = update_simplified_system! (state, neweqs, solved_eqs, dummy_sub, var_sccs,
1188- extra_unknowns, iv, D; array_hack)
1193+ iv, D; array_hack)
11891194 else
11901195 D = D:: Nothing
11911196 neweqs, solved_eqs,
@@ -1201,7 +1206,7 @@ function (alg::DefaultReassembleAlgorithm)(state::TearingState,
12011206 # var_eq_matching and full_var_eq_matching are now invalidated
12021207
12031208 sys = update_simplified_system! (state, neweqs, solved_eqs, dummy_sub, var_sccs,
1204- extra_unknowns, iv, D; array_hack)
1209+ iv, D; array_hack)
12051210 end
12061211
12071212 @set! state. sys = sys
0 commit comments