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