@@ -820,19 +820,40 @@ function mtkcompile!(state::TearingState; simplify = false,
820
820
time_domains = merge (Dict (state. fullvars .=> ci. var_domain),
821
821
Dict (default_toterm .(state. fullvars) .=> ci. var_domain))
822
822
tss, clocked_inputs, continuous_id, id_to_clock = ModelingToolkit. split_system (ci)
823
+ if continuous_id == 0
824
+ # do a trait check here - handle fully discrete system
825
+ additional_passes = get (kwargs, :additional_passes , nothing )
826
+ if ! isnothing (additional_passes) && any (discrete_compile_pass, additional_passes)
827
+ # take the first discrete compilation pass given for now
828
+ discrete_pass_idx = findfirst (discrete_compile_pass, additional_passes)
829
+ discrete_compile = additional_passes[discrete_pass_idx]
830
+ deleteat! (additional_passes, discrete_pass_idx)
831
+ return discrete_compile (tss, clocked_inputs)
832
+ end
833
+ throw (HybridSystemNotSupportedException ("""
834
+ Discrete systems with multiple clocks are not supported with the standard \
835
+ MTK compiler.
836
+ """ ))
837
+ end
823
838
if length (tss) > 1
824
- if continuous_id == 0
825
- throw (HybridSystemNotSupportedException ("""
826
- Discrete systems with multiple clocks are not supported with the standard \
827
- MTK compiler.
828
- """ ))
829
- else
830
- throw (HybridSystemNotSupportedException ("""
831
- Hybrid continuous-discrete systems are currently not supported with \
832
- the standard MTK compiler. This system requires JuliaSimCompiler.jl, \
833
- see https://help.juliahub.com/juliasimcompiler/stable/
834
- """ ))
839
+ # simplify as normal
840
+ sys = _mtkcompile! (tss[continuous_id]; simplify,
841
+ inputs = [inputs; clocked_inputs[continuous_id]], outputs, disturbance_inputs,
842
+ check_consistency, fully_determined,
843
+ kwargs... )
844
+ if ! isnothing (additional_passes) && any (discrete_compile_pass, additional_passes)
845
+ discrete_pass_idx = findfirst (discrete_compile_pass, additional_passes)
846
+ discrete_compile = additional_passes[discrete_pass_idx]
847
+ deleteat! (additional_passes, discrete_pass_idx)
848
+ # in the case of a hybrid system, the discrete_compile pass should take the currents of sys.discrete_subsystems
849
+ # and modifies discrete_subsystems to bea tuple of the io and anything else, while adding or manipulating the rest of sys as needed
850
+ return discrete_compile (sys, tss[2 : end ], inputs)
835
851
end
852
+ throw (HybridSystemNotSupportedException ("""
853
+ Hybrid continuous-discrete systems are currently not supported with \
854
+ the standard MTK compiler. This system requires JuliaSimCompiler.jl, \
855
+ see https://help.juliahub.com/juliasimcompiler/stable/
856
+ """ ))
836
857
end
837
858
if get_is_discrete (state. sys) ||
838
859
continuous_id == 1 && any (Base. Fix2 (isoperator, Shift), state. fullvars)
0 commit comments