@@ -626,40 +626,45 @@ function structural_simplify!(state::TearingState, io = nothing; simplify = fals
626626 check_consistency = true , fully_determined = true , warn_initialize_determined = true ,
627627 kwargs... )
628628 if state. sys isa ODESystem
629+ # split_system returns one or two systems and the inputs for each
630+ # mod clock inference to be binary
631+ # if it's continous keep going, if not then error unless given trait impl in additional passes
629632 ci = ModelingToolkit. ClockInference (state)
630633 ci = ModelingToolkit. infer_clocks! (ci)
631634 time_domains = merge (Dict (state. fullvars .=> ci. var_domain),
632635 Dict (default_toterm .(state. fullvars) .=> ci. var_domain))
633636 tss, inputs, continuous_id, id_to_clock = ModelingToolkit. split_system (ci)
637+ if continuous_id == 0
638+ # do a trait check here - handle fully discrete system
639+ additional_passes = get (kwargs, :additional_passes , nothing )
640+ if ! isnothing (additional_passes) && any (discrete_compile_pass, additional_passes)
641+ # take the first discrete compilation pass given for now
642+ discrete_pass_idx = findfirst (discrete_compile_pass, additional_passes)
643+ discrete_compile = additional_passes[discrete_pass_idx]
644+ deleteat! (additional_passes, discrete_pass_idx)
645+ return discrete_compile (tss, inputs)
646+ else
647+ # error goes here! this is a purely discrete system
648+ throw (HybridSystemNotSupportedException (" Discrete systems without JuliaSimCompiler are currently not supported in ODESystem." ))
649+ end
650+ end
651+ # puts the ios passed in to the call into the continous system
634652 cont_io = merge_io (io, inputs[continuous_id])
653+ # simplify as normal
635654 sys, input_idxs = _structural_simplify! (tss[continuous_id], cont_io; simplify,
636655 check_consistency, fully_determined,
637656 kwargs... )
638657 if length (tss) > 1
639- if continuous_id > 0
658+ if ! isnothing (additional_passes) && any (discrete_compile_pass, additional_passes)
659+ discrete_pass_idx = findfirst (discrete_compile_pass, additional_passes)
660+ discrete_compile = additional_passes[discrete_pass_idx]
661+ deleteat! (additional_passes, discrete_pass_idx)
662+ # in the case of a hybrid system, the discrete_compile pass should take the currents of sys.discrete_subsystems
663+ # and modifies discrete_subsystems to bea tuple of the io and anything else, while adding or manipulating the rest of sys as needed
664+ sys = discrete_compile (sys, tss[2 : end ], inputs)
665+ else
640666 throw (HybridSystemNotSupportedException (" Hybrid continuous-discrete systems are currently not supported with the standard MTK compiler. This system requires JuliaSimCompiler.jl, see https://help.juliahub.com/juliasimcompiler/stable/" ))
641667 end
642- # TODO : rename it to something else
643- discrete_subsystems = Vector {ODESystem} (undef, length (tss))
644- # Note that the appended_parameters must agree with
645- # `generate_discrete_affect`!
646- appended_parameters = parameters (sys)
647- for (i, state) in enumerate (tss)
648- if i == continuous_id
649- discrete_subsystems[i] = sys
650- continue
651- end
652- dist_io = merge_io (io, inputs[i])
653- ss, = _structural_simplify! (state, dist_io; simplify, check_consistency,
654- fully_determined, kwargs... )
655- append! (appended_parameters, inputs[i], unknowns (ss))
656- discrete_subsystems[i] = ss
657- end
658- @set! sys. discrete_subsystems = discrete_subsystems, inputs, continuous_id,
659- id_to_clock
660- @set! sys. ps = appended_parameters
661- @set! sys. defaults = merge (ModelingToolkit. defaults (sys),
662- Dict (v => 0.0 for v in Iterators. flatten (inputs)))
663668 end
664669 ps = [sym isa CallWithMetadata ? sym :
665670 setmetadata (sym, VariableTimeDomain, get (time_domains, sym, Continuous ()))
0 commit comments