@@ -554,14 +554,15 @@ function merge_io(io, inputs)
554554end
555555
556556function structural_simplify! (state:: TearingState , io = nothing ; simplify = false ,
557- check_consistency = true , kwargs... )
557+ check_consistency = true , fully_determined = true ,
558+ kwargs... )
558559 if state. sys isa ODESystem
559560 ci = ModelingToolkit. ClockInference (state)
560561 ModelingToolkit. infer_clocks! (ci)
561562 tss, inputs, continuous_id, id_to_clock = ModelingToolkit. split_system (ci)
562563 cont_io = merge_io (io, inputs[continuous_id])
563564 sys, input_idxs = _structural_simplify! (tss[continuous_id], cont_io; simplify,
564- check_consistency,
565+ check_consistency, fully_determined,
565566 kwargs... )
566567 if length (tss) > 1
567568 # TODO : rename it to something else
@@ -576,7 +577,7 @@ function structural_simplify!(state::TearingState, io = nothing; simplify = fals
576577 end
577578 dist_io = merge_io (io, inputs[i])
578579 ss, = _structural_simplify! (state, dist_io; simplify, check_consistency,
579- kwargs... )
580+ fully_determined, kwargs... )
580581 append! (appended_parameters, inputs[i], states (ss))
581582 discrete_subsystems[i] = ss
582583 end
@@ -588,14 +589,16 @@ function structural_simplify!(state::TearingState, io = nothing; simplify = fals
588589 end
589590 else
590591 sys, input_idxs = _structural_simplify! (state, io; simplify, check_consistency,
591- kwargs... )
592+ fully_determined, kwargs... )
592593 end
593594 has_io = io != = nothing
594595 return has_io ? (sys, input_idxs) : sys
595596end
596597
597598function _structural_simplify! (state:: TearingState , io; simplify = false ,
598- check_consistency = true , kwargs... )
599+ check_consistency = true , fully_determined = true ,
600+ kwargs... )
601+ check_consistency &= fully_determined
599602 has_io = io != = nothing
600603 orig_inputs = Set ()
601604 if has_io
@@ -606,7 +609,11 @@ function _structural_simplify!(state::TearingState, io; simplify = false,
606609 if check_consistency
607610 ModelingToolkit. check_consistency (state, orig_inputs)
608611 end
609- sys = ModelingToolkit. dummy_derivative (sys, state; simplify, mm)
612+ if fully_determined
613+ sys = ModelingToolkit. dummy_derivative (sys, state; simplify, mm, check_consistency)
614+ else
615+ sys = ModelingToolkit. tearing (sys, state; simplify, mm, check_consistency)
616+ end
610617 fullstates = [map (eq -> eq. lhs, observed (sys)); states (sys)]
611618 @set! sys. observed = ModelingToolkit. topsort_equations (observed (sys), fullstates)
612619 ModelingToolkit. invalidate_cache! (sys), input_idxs
0 commit comments