@@ -144,12 +144,11 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = par
144
144
ddvs = implicit_dae ? map (Differential (get_iv (sys)), dvs) :
145
145
nothing ,
146
146
isdde = false ,
147
- has_difference = false ,
148
147
kwargs... )
149
148
if isdde
150
149
eqs = delay_to_function (sys)
151
150
else
152
- eqs = [eq for eq in equations (sys) if ! isdifferenceeq (eq) ]
151
+ eqs = [eq for eq in equations (sys)]
153
152
end
154
153
if ! implicit_dae
155
154
check_operator_variables (eqs, Differential)
@@ -167,8 +166,7 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = par
167
166
if isdde
168
167
build_function (rhss, u, DDE_HISTORY_FUN, p, t; kwargs... )
169
168
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)
172
170
173
171
if implicit_dae
174
172
build_function (rhss, ddvs, u, p, t; postprocess_fbody = pre,
@@ -226,54 +224,8 @@ function delay_to_function(expr, iv, sts, ps, h)
226
224
end
227
225
end
228
226
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
-
275
227
function 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)]
277
229
dvs = unknowns (sys)
278
230
M = zeros (length (eqs), length (eqs))
279
231
unknown2idx = Dict (s => i for (i, s) in enumerate (dvs))
@@ -939,12 +891,10 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
939
891
callback = nothing ,
940
892
check_length = true ,
941
893
kwargs... ) where {iip, specialize}
942
- has_difference = any (isdifferenceeq, equations (sys))
943
894
f, u0, p = process_DEProblem (ODEFunction{iip, specialize}, sys, u0map, parammap;
944
895
t = tspan != = nothing ? tspan[1 ] : tspan,
945
- has_difference = has_difference,
946
896
check_length, kwargs... )
947
- cbs = process_events (sys; callback, has_difference, kwargs... )
897
+ cbs = process_events (sys; callback, kwargs... )
948
898
inits = []
949
899
if has_discrete_subsystems (sys) && (dss = get_discrete_subsystems (sys)) != = nothing
950
900
affects, inits, clocks, svs = ModelingToolkit. generate_discrete_affect (dss... )
@@ -1009,24 +959,16 @@ end
1009
959
function DiffEqBase. DAEProblem {iip} (sys:: AbstractODESystem , du0map, u0map, tspan,
1010
960
parammap = DiffEqBase. NullParameters ();
1011
961
check_length = true , kwargs... ) where {iip}
1012
- has_difference = any (isdifferenceeq, equations (sys))
1013
962
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,
1016
964
kwargs... )
1017
965
diffvars = collect_differential_variables (sys)
1018
966
sts = unknowns (sys)
1019
967
differential_vars = map (Base. Fix2 (in, diffvars), sts)
1020
968
kwargs = filter_kwargs (kwargs)
1021
969
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... )
1030
972
end
1031
973
1032
974
function generate_history (sys:: AbstractODESystem , u0; kwargs... )
@@ -1042,16 +984,14 @@ function DiffEqBase.DDEProblem{iip}(sys::AbstractODESystem, u0map = [],
1042
984
callback = nothing ,
1043
985
check_length = true ,
1044
986
kwargs... ) where {iip}
1045
- has_difference = any (isdifferenceeq, equations (sys))
1046
987
f, u0, p = process_DEProblem (DDEFunction{iip}, sys, u0map, parammap;
1047
988
t = tspan != = nothing ? tspan[1 ] : tspan,
1048
- has_difference = has_difference,
1049
989
symbolic_u0 = true ,
1050
990
check_length, kwargs... )
1051
991
h_oop, h_iip = generate_history (sys, u0)
1052
992
h = h_oop
1053
993
u0 = h (p, tspan[1 ])
1054
- cbs = process_events (sys; callback, has_difference, kwargs... )
994
+ cbs = process_events (sys; callback, kwargs... )
1055
995
inits = []
1056
996
if has_discrete_subsystems (sys) && (dss = get_discrete_subsystems (sys)) != = nothing
1057
997
affects, inits, clocks, svs = ModelingToolkit. generate_discrete_affect (dss... )
@@ -1102,17 +1042,15 @@ function DiffEqBase.SDDEProblem{iip}(sys::AbstractODESystem, u0map = [],
1102
1042
check_length = true ,
1103
1043
sparsenoise = nothing ,
1104
1044
kwargs... ) where {iip}
1105
- has_difference = any (isdifferenceeq, equations (sys))
1106
1045
f, u0, p = process_DEProblem (SDDEFunction{iip}, sys, u0map, parammap;
1107
1046
t = tspan != = nothing ? tspan[1 ] : tspan,
1108
- has_difference = has_difference,
1109
1047
symbolic_u0 = true ,
1110
1048
check_length, kwargs... )
1111
1049
h_oop, h_iip = generate_history (sys, u0)
1112
1050
h (out, p, t) = h_iip (out, p, t)
1113
1051
h (p, t) = h_oop (p, t)
1114
1052
u0 = h (p, tspan[1 ])
1115
- cbs = process_events (sys; callback, has_difference, kwargs... )
1053
+ cbs = process_events (sys; callback, kwargs... )
1116
1054
inits = []
1117
1055
if has_discrete_subsystems (sys) && (dss = get_discrete_subsystems (sys)) != = nothing
1118
1056
affects, inits, clocks, svs = ModelingToolkit. generate_discrete_affect (dss... )
0 commit comments