@@ -141,6 +141,10 @@ struct ODESystem <: AbstractODESystem
141141    """  
142142    gui_metadata:: Union{Nothing, GUIMetadata} 
143143    """ 
144+     A boolean indicating if the given `ODESystem` represents a system of DDEs. 
145+     """  
146+     is_dde:: Bool 
147+     """ 
144148    Cache for intermediate tearing state. 
145149    """  
146150    tearing_state:: Any 
@@ -178,7 +182,7 @@ struct ODESystem <: AbstractODESystem
178182            torn_matching, initializesystem, initialization_eqs, schedule,
179183            connector_type, preface, cevents,
180184            devents, parameter_dependencies,
181-             metadata =  nothing , gui_metadata =  nothing ,
185+             metadata =  nothing , gui_metadata =  nothing , is_dde  =   false , 
182186            tearing_state =  nothing ,
183187            substitutions =  nothing , complete =  false , index_cache =  nothing ,
184188            discrete_subsystems =  nothing , solved_unknowns =  nothing ,
@@ -198,7 +202,7 @@ struct ODESystem <: AbstractODESystem
198202            ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, torn_matching,
199203            initializesystem, initialization_eqs, schedule, connector_type, preface,
200204            cevents, devents, parameter_dependencies, metadata,
201-             gui_metadata, tearing_state, substitutions, complete, index_cache,
205+             gui_metadata, is_dde,  tearing_state, substitutions, complete, index_cache,
202206            discrete_subsystems, solved_unknowns, split_idxs, parent)
203207    end 
204208end 
@@ -223,7 +227,8 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
223227        parameter_dependencies =  Equation[],
224228        checks =  true ,
225229        metadata =  nothing ,
226-         gui_metadata =  nothing )
230+         gui_metadata =  nothing ,
231+         is_dde =  nothing )
227232    name ===  nothing  && 
228233        throw (ArgumentError (" The `name` keyword must be provided. Please consider using the `@named` macro" 
229234    @assert  all (control ->  any (isequal .(control, ps)), controls) " All controls must also be parameters." 
@@ -266,12 +271,25 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
266271    disc_callbacks =  SymbolicDiscreteCallbacks (discrete_events)
267272    parameter_dependencies, ps′ =  process_parameter_dependencies (
268273        parameter_dependencies, ps′)
274+     if  is_dde ===  nothing 
275+         is_dde =  any (ModelingToolkit. is_dde, systems)
276+         if  ! is_dde
277+             vs =  Set ()
278+             for  eq in  deqs
279+                 vars! (vs, eq)
280+                 is_dde =  any (vs) do  sym
281+                     isdelay (unwrap (sym), iv′)
282+                 end 
283+                 is_dde &&  break 
284+             end 
285+         end 
286+     end 
269287    ODESystem (Threads. atomic_add! (SYSTEM_COUNT, UInt (1 )),
270288        deqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
271289        ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, nothing , initializesystem,
272290        initialization_eqs, schedule, connector_type, preface, cont_callbacks,
273291        disc_callbacks, parameter_dependencies,
274-         metadata, gui_metadata, checks =  checks)
292+         metadata, gui_metadata, is_dde,  checks =  checks)
275293end 
276294
277295function  ODESystem (eqs, iv; kwargs... )
0 commit comments