@@ -217,10 +217,18 @@ function check_diff_graph(var_to_diff, fullvars)
217217end
218218=#
219219
220- function tearing_reassemble (state:: TearingState , var_eq_matching;
221- simplify = false , mm = nothing )
220+ function tearing_reassemble (state:: TearingState , var_eq_matching,
221+ full_var_eq_matching = nothing ; simplify = false , mm = nothing )
222222 @unpack fullvars, sys, structure = state
223223 @unpack solvable_graph, var_to_diff, eq_to_diff, graph = structure
224+ extra_vars = Int[]
225+ if full_var_eq_matching != = nothing
226+ for v in 𝑑vertices (state. structure. graph)
227+ eq = full_var_eq_matching[v]
228+ eq isa Int && continue
229+ push! (extra_vars, v)
230+ end
231+ end
224232
225233 neweqs = collect (equations (state))
226234 # Terminology and Definition:
@@ -532,6 +540,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching;
532540 eq_to_diff = new_eq_to_diff
533541 diff_to_var = invview (var_to_diff)
534542
543+ old_fullvars = fullvars
535544 @set! state. structure. graph = complete (graph)
536545 @set! state. structure. var_to_diff = var_to_diff
537546 @set! state. structure. eq_to_diff = eq_to_diff
@@ -543,9 +552,15 @@ function tearing_reassemble(state::TearingState, var_eq_matching;
543552
544553 sys = state. sys
545554 @set! sys. eqs = neweqs
546- @set! sys. unknowns = Any[v
547- for (i, v) in enumerate (fullvars)
548- if diff_to_var[i] === nothing && ispresent (i)]
555+ unknowns = Any[v
556+ for (i, v) in enumerate (fullvars)
557+ if diff_to_var[i] === nothing && ispresent (i)]
558+ if ! isempty (extra_vars)
559+ for v in extra_vars
560+ push! (unknowns, old_fullvars[v])
561+ end
562+ end
563+ @set! sys. unknowns = unknowns
549564 @set! sys. substitutions = Substitutions (subeqs, deps)
550565
551566 obs_sub = dummy_sub
570585function tearing (state:: TearingState ; kwargs... )
571586 state. structure. solvable_graph === nothing && find_solvables! (state; kwargs... )
572587 complete! (state. structure)
573- @unpack graph = state. structure
574- algvars = BitSet (findall (v -> isalgvar (state. structure, v), 1 : ndsts (graph)))
575- aeqs = algeqs (state. structure)
576- var_eq_matching′, = tear_graph_modia (state. structure;
577- varfilter = var -> var in algvars,
578- eqfilter = eq -> eq in aeqs)
579- var_eq_matching = Matching {Union{Unassigned, SelectedState}} (var_eq_matching′)
580- for var in 1 : ndsts (graph)
581- if isdiffvar (state. structure, var)
582- var_eq_matching[var] = SelectedState ()
583- end
584- end
585- var_eq_matching
588+ tearing_with_dummy_derivatives (state. structure, ())
586589end
587590
588591"""
@@ -594,8 +597,9 @@ instead, which calls this function internally.
594597"""
595598function tearing (sys:: AbstractSystem , state = TearingState (sys); mm = nothing ,
596599 simplify = false , kwargs... )
597- var_eq_matching = tearing (state)
598- invalidate_cache! (tearing_reassemble (state, var_eq_matching; mm, simplify))
600+ var_eq_matching, full_var_eq_matching = tearing (state)
601+ invalidate_cache! (tearing_reassemble (
602+ state, var_eq_matching, full_var_eq_matching; mm, simplify))
599603end
600604
601605"""
0 commit comments