@@ -144,12 +144,11 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = par
144144 ddvs = implicit_dae ? map (Differential (get_iv (sys)), dvs) :
145145 nothing ,
146146 isdde = false ,
147- has_difference = false ,
148147 kwargs... )
149148 if isdde
150149 eqs = delay_to_function (sys)
151150 else
152- eqs = [eq for eq in equations (sys) if ! isdifferenceeq (eq) ]
151+ eqs = [eq for eq in equations (sys)]
153152 end
154153 if ! implicit_dae
155154 check_operator_variables (eqs, Differential)
@@ -167,8 +166,7 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = par
167166 if isdde
168167 build_function (rhss, u, DDE_HISTORY_FUN, p, t; kwargs... )
169168 else
170- pre, sol_states = get_substitutions_and_solved_unknowns (sys,
171- no_postprocess = has_difference)
169+ pre, sol_states = get_substitutions_and_solved_unknowns (sys)
172170
173171 if implicit_dae
174172 build_function (rhss, ddvs, u, p, t; postprocess_fbody = pre,
@@ -226,54 +224,8 @@ function delay_to_function(expr, iv, sts, ps, h)
226224 end
227225end
228226
229- function generate_difference_cb (sys:: ODESystem , dvs = unknowns (sys), ps = parameters (sys);
230- kwargs... )
231- eqs = equations (sys)
232- check_operator_variables (eqs, Difference)
233-
234- var2eq = Dict (arguments (eq. lhs)[1 ] => eq for eq in eqs if isdifference (eq. lhs))
235-
236- u = map (x -> time_varying_as_func (value (x), sys), dvs)
237- p = map (x -> time_varying_as_func (value (x), sys), ps)
238- t = get_iv (sys)
239-
240- body = map (dvs) do v
241- eq = get (var2eq, v, nothing )
242- eq === nothing && return v
243- d = operation (eq. lhs)
244- d. update ? eq. rhs : eq. rhs + v
245- end
246-
247- pre = get_postprocess_fbody (sys)
248- cpre = get_preprocess_constants (body)
249- pre2 = x -> pre (cpre (x))
250- f_oop, f_iip = build_function (body, u, p, t; expression = Val{false },
251- postprocess_fbody = pre2, kwargs... )
252-
253- cb_affect! = let f_oop = f_oop, f_iip = f_iip
254- function cb_affect! (integ)
255- if DiffEqBase. isinplace (integ. sol. prob)
256- tmp, = DiffEqBase. get_tmp_cache (integ)
257- f_iip (tmp, integ. u, integ. p, integ. t) # aliasing `integ.u` would be bad.
258- copyto! (integ. u, tmp)
259- else
260- integ. u = f_oop (integ. u, integ. p, integ. t)
261- end
262- return nothing
263- end
264- end
265-
266- getdt (eq) = operation (eq. lhs). dt
267- deqs = values (var2eq)
268- dt = getdt (first (deqs))
269- all (dt == getdt (eq) for eq in deqs) ||
270- error (" All difference variables should have same time steps." )
271-
272- PeriodicCallback (cb_affect!, first (dt))
273- end
274-
275227function calculate_massmatrix (sys:: AbstractODESystem ; simplify = false )
276- eqs = [eq for eq in equations (sys) if ! isdifferenceeq (eq) ]
228+ eqs = [eq for eq in equations (sys)]
277229 dvs = unknowns (sys)
278230 M = zeros (length (eqs), length (eqs))
279231 unknown2idx = Dict (s => i for (i, s) in enumerate (dvs))
@@ -939,12 +891,10 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
939891 callback = nothing ,
940892 check_length = true ,
941893 kwargs... ) where {iip, specialize}
942- has_difference = any (isdifferenceeq, equations (sys))
943894 f, u0, p = process_DEProblem (ODEFunction{iip, specialize}, sys, u0map, parammap;
944895 t = tspan != = nothing ? tspan[1 ] : tspan,
945- has_difference = has_difference,
946896 check_length, kwargs... )
947- cbs = process_events (sys; callback, has_difference, kwargs... )
897+ cbs = process_events (sys; callback, kwargs... )
948898 inits = []
949899 if has_discrete_subsystems (sys) && (dss = get_discrete_subsystems (sys)) != = nothing
950900 affects, inits, clocks, svs = ModelingToolkit. generate_discrete_affect (dss... )
@@ -1009,24 +959,16 @@ end
1009959function DiffEqBase. DAEProblem {iip} (sys:: AbstractODESystem , du0map, u0map, tspan,
1010960 parammap = DiffEqBase. NullParameters ();
1011961 check_length = true , kwargs... ) where {iip}
1012- has_difference = any (isdifferenceeq, equations (sys))
1013962 f, du0, u0, p = process_DEProblem (DAEFunction{iip}, sys, u0map, parammap;
1014- implicit_dae = true , du0map = du0map,
1015- has_difference = has_difference, check_length,
963+ implicit_dae = true , du0map = du0map, check_length,
1016964 kwargs... )
1017965 diffvars = collect_differential_variables (sys)
1018966 sts = unknowns (sys)
1019967 differential_vars = map (Base. Fix2 (in, diffvars), sts)
1020968 kwargs = filter_kwargs (kwargs)
1021969
1022- if has_difference
1023- DAEProblem {iip} (f, du0, u0, tspan, p;
1024- difference_cb = generate_difference_cb (sys; kwargs... ),
1025- differential_vars = differential_vars, kwargs... )
1026- else
1027- DAEProblem {iip} (f, du0, u0, tspan, p; differential_vars = differential_vars,
1028- kwargs... )
1029- end
970+ DAEProblem {iip} (f, du0, u0, tspan, p; differential_vars = differential_vars,
971+ kwargs... )
1030972end
1031973
1032974function generate_history (sys:: AbstractODESystem , u0; kwargs... )
@@ -1042,16 +984,14 @@ function DiffEqBase.DDEProblem{iip}(sys::AbstractODESystem, u0map = [],
1042984 callback = nothing ,
1043985 check_length = true ,
1044986 kwargs... ) where {iip}
1045- has_difference = any (isdifferenceeq, equations (sys))
1046987 f, u0, p = process_DEProblem (DDEFunction{iip}, sys, u0map, parammap;
1047988 t = tspan != = nothing ? tspan[1 ] : tspan,
1048- has_difference = has_difference,
1049989 symbolic_u0 = true ,
1050990 check_length, kwargs... )
1051991 h_oop, h_iip = generate_history (sys, u0)
1052992 h = h_oop
1053993 u0 = h (p, tspan[1 ])
1054- cbs = process_events (sys; callback, has_difference, kwargs... )
994+ cbs = process_events (sys; callback, kwargs... )
1055995 inits = []
1056996 if has_discrete_subsystems (sys) && (dss = get_discrete_subsystems (sys)) != = nothing
1057997 affects, inits, clocks, svs = ModelingToolkit. generate_discrete_affect (dss... )
@@ -1102,17 +1042,15 @@ function DiffEqBase.SDDEProblem{iip}(sys::AbstractODESystem, u0map = [],
11021042 check_length = true ,
11031043 sparsenoise = nothing ,
11041044 kwargs... ) where {iip}
1105- has_difference = any (isdifferenceeq, equations (sys))
11061045 f, u0, p = process_DEProblem (SDDEFunction{iip}, sys, u0map, parammap;
11071046 t = tspan != = nothing ? tspan[1 ] : tspan,
1108- has_difference = has_difference,
11091047 symbolic_u0 = true ,
11101048 check_length, kwargs... )
11111049 h_oop, h_iip = generate_history (sys, u0)
11121050 h (out, p, t) = h_iip (out, p, t)
11131051 h (p, t) = h_oop (p, t)
11141052 u0 = h (p, tspan[1 ])
1115- cbs = process_events (sys; callback, has_difference, kwargs... )
1053+ cbs = process_events (sys; callback, kwargs... )
11161054 inits = []
11171055 if has_discrete_subsystems (sys) && (dss = get_discrete_subsystems (sys)) != = nothing
11181056 affects, inits, clocks, svs = ModelingToolkit. generate_discrete_affect (dss... )
0 commit comments