204204mutable struct TearingState{T <: AbstractSystem } <: AbstractTearingState{T}
205205 """ The system of equations."""
206206 sys:: T
207+ original_eqs:: Vector{Equation}
207208 """ The set of variables of the system."""
208209 fullvars:: Vector{BasicSymbolic}
209210 structure:: SystemStructure
@@ -527,7 +528,7 @@ function TearingState(sys; quick_cancel = false, check = true, sort_eqs = true)
527528
528529 eq_to_diff = DiffGraph (nsrcs (graph))
529530
530- ts = TearingState (sys, fullvars,
531+ ts = TearingState (sys, original_eqs, fullvars,
531532 SystemStructure (complete (var_to_diff), complete (eq_to_diff),
532533 complete (graph), nothing , var_types, false ),
533534 Any[], param_derivative_map, original_eqs, Equation[])
@@ -813,6 +814,22 @@ function Base.show(io::IO, mime::MIME"text/plain", ms::MatchedSystemStructure)
813814 printstyled (io, " SelectedState" )
814815end
815816
817+ function make_eqs_zero_equals! (ts:: TearingState )
818+ neweqs = map (enumerate (get_eqs (ts. sys))) do kvp
819+ i, eq = kvp
820+ isalgeq = true
821+ for j in 𝑠neighbors (ts. structure. graph, i)
822+ isalgeq &= invview (ts. structure. var_to_diff)[j] === nothing
823+ end
824+ if isalgeq
825+ return 0 ~ eq. rhs - eq. lhs
826+ else
827+ return eq
828+ end
829+ end
830+ copyto! (get_eqs (ts. sys), neweqs)
831+ end
832+
816833function mtkcompile! (state:: TearingState ; simplify = false ,
817834 check_consistency = true , fully_determined = true , warn_initialize_determined = true ,
818835 inputs = Any[], outputs = Any[],
@@ -839,6 +856,7 @@ function mtkcompile!(state::TearingState; simplify = false,
839856 """ ))
840857 end
841858 if length (tss) > 1
859+ make_eqs_zero_equals! (tss[continuous_id])
842860 # simplify as normal
843861 sys = _mtkcompile! (tss[continuous_id]; simplify,
844862 inputs = [inputs; clocked_inputs[continuous_id]], outputs, disturbance_inputs,
0 commit comments