204
204
mutable struct TearingState{T <: AbstractSystem } <: AbstractTearingState{T}
205
205
""" The system of equations."""
206
206
sys:: T
207
+ original_eqs:: Vector{Equation}
207
208
""" The set of variables of the system."""
208
209
fullvars:: Vector{BasicSymbolic}
209
210
structure:: SystemStructure
@@ -527,7 +528,7 @@ function TearingState(sys; quick_cancel = false, check = true, sort_eqs = true)
527
528
528
529
eq_to_diff = DiffGraph (nsrcs (graph))
529
530
530
- ts = TearingState (sys, fullvars,
531
+ ts = TearingState (sys, original_eqs, fullvars,
531
532
SystemStructure (complete (var_to_diff), complete (eq_to_diff),
532
533
complete (graph), nothing , var_types, false ),
533
534
Any[], param_derivative_map, original_eqs, Equation[])
@@ -813,6 +814,22 @@ function Base.show(io::IO, mime::MIME"text/plain", ms::MatchedSystemStructure)
813
814
printstyled (io, " SelectedState" )
814
815
end
815
816
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
+
816
833
function mtkcompile! (state:: TearingState ; simplify = false ,
817
834
check_consistency = true , fully_determined = true , warn_initialize_determined = true ,
818
835
inputs = Any[], outputs = Any[],
@@ -839,6 +856,7 @@ function mtkcompile!(state::TearingState; simplify = false,
839
856
""" ))
840
857
end
841
858
if length (tss) > 1
859
+ make_eqs_zero_equals! (tss[continuous_id])
842
860
# simplify as normal
843
861
sys = _mtkcompile! (tss[continuous_id]; simplify,
844
862
inputs = [inputs; clocked_inputs[continuous_id]], outputs, disturbance_inputs,
0 commit comments