Skip to content

Commit 122af53

Browse files
Fix for differential_vars update (#278)
* Fix for differential_vars update * bump versions * Update Project.toml
1 parent 3e9c423 commit 122af53

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
matrix:
2121
version:
2222
- '1'
23-
- '1.6'
2423
os:
2524
- ubuntu-latest
2625
arch:

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
1818
SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a"
1919

2020
[compat]
21-
ArrayInterface = "6, 7"
21+
ArrayInterface = "7"
2222
DataStructures = "0.18"
2323
DiffEqBase = "6.122"
24-
OrdinaryDiffEq = "6.49.1"
24+
OrdinaryDiffEq = "6.63"
2525
RecursiveArrayTools = "2, 3"
2626
Reexport = "0.2, 1.0"
2727
SciMLBase = "1.90, 2"
2828
SimpleNonlinearSolve = "0.1, 1"
2929
SimpleUnPack = "1"
30-
julia = "1.6"
30+
julia = "1.9"

src/integrators/type.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mutable struct HistoryODEIntegrator{algType, IIP, uType, tType, tdirType, ksEltype, SolType,
2-
CacheType} <:
2+
CacheType, DV} <:
33
AbstractODEIntegrator{algType, IIP, uType, tType}
44
sol::SolType
55
u::uType
@@ -14,6 +14,7 @@ mutable struct HistoryODEIntegrator{algType, IIP, uType, tType, tdirType, ksElty
1414
saveiter::Int
1515
saveiter_dense::Int
1616
cache::CacheType
17+
differential_vars::DV
1718
end
1819

1920
function (integrator::HistoryODEIntegrator)(t, deriv::Type = Val{0}; idxs = nothing)
@@ -31,7 +32,7 @@ mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUn
3132
ksEltype, SolType, F, CacheType, IType, FP, O, dAbsType,
3233
dRelType, H,
3334
tstopsType, discType, FSALType, EventErrorType,
34-
CallbackCacheType} <:
35+
CallbackCacheType, DV} <:
3536
AbstractDDEIntegrator{algType, IIP, uType, tType}
3637
sol::SolType
3738
u::uType
@@ -89,6 +90,7 @@ mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUn
8990
opts::O
9091
stats::DDEStats
9192
history::H
93+
differential_vars::DV
9294
integrator::IType
9395
fsalfirst::FSALType
9496
fsallast::FSALType
@@ -97,7 +99,7 @@ mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUn
9799
function DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUnits,
98100
tdirType, ksEltype, SolType, F, CacheType, IType, FP,
99101
O, dAbsType, dRelType, H, tstopsType, discType,
100-
FSALType, EventErrorType, CallbackCacheType}(sol, u, k, t, dt, f,
102+
FSALType, EventErrorType, CallbackCacheType, DV}(sol, u, k, t, dt, f,
101103
p, uprev, uprev2,
102104
tprev, prev_idx,
103105
prev2_idx,
@@ -133,15 +135,16 @@ mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUn
133135
u_modified, isdae,
134136
opts, stats,
135137
history,
138+
differential_vars,
136139
integrator) where
137140
{algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, tdirType, ksEltype,
138141
SolType, F,
139142
CacheType, IType, FP, O, dAbsType, dRelType, H, tstopsType, discType,
140-
FSALType, EventErrorType, CallbackCacheType}
143+
FSALType, EventErrorType, CallbackCacheType, DV}
141144
new{algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, tdirType, ksEltype,
142145
SolType, F,
143146
CacheType, IType, FP, O, dAbsType, dRelType, H, tstopsType, discType, FSALType,
144-
EventErrorType, CallbackCacheType}(sol, u, k, t, dt, f, p, uprev, uprev2, tprev,
147+
EventErrorType, CallbackCacheType, DV}(sol, u, k, t, dt, f, p, uprev, uprev2, tprev,
145148
prev_idx, prev2_idx, fpsolver,
146149
order_discontinuity_t0,
147150
tracked_discontinuities,
@@ -159,7 +162,7 @@ mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUn
159162
vector_event_last_time,
160163
last_event_error, accept_step, isout,
161164
reeval_fsal, u_modified, isdae, opts,
162-
stats, history, integrator)
165+
stats, history, differential_vars, integrator)
163166
end
164167
end
165168

src/solve.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem,
128128
# get rate prototype
129129
rate_prototype = rate_prototype_of(u0, tspan)
130130

131-
# create a history function
132-
history = build_history_function(prob, alg, rate_prototype, reltol_internal;
133-
dt = dt, dtmin = dtmin, calck = false,
134-
adaptive = adaptive, internalnorm = internalnorm)
135-
f_with_history = ODEFunctionWrapper(f, history)
136-
137131
# get states (possibly different from the ODE integrator!)
138132
u, uprev, uprev2 = u_uprev_uprev2(u0, alg;
139133
alias_u0 = alias_u0,
@@ -143,6 +137,16 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem,
143137
uEltypeNoUnits = recursive_unitless_eltype(u)
144138
uBottomEltypeNoUnits = recursive_unitless_bottom_eltype(u)
145139

140+
# get the differential vs algebraic variables
141+
differential_vars = prob isa DAEProblem ? prob.differential_vars : OrdinaryDiffEq.get_differential_vars(f, u)
142+
143+
# create a history function
144+
history = build_history_function(prob, alg, rate_prototype, reltol_internal,
145+
differential_vars;
146+
dt = dt, dtmin = dtmin, calck = false,
147+
adaptive = adaptive, internalnorm = internalnorm)
148+
f_with_history = ODEFunctionWrapper(f, history)
149+
146150
# initialize output arrays of the solution
147151
k = typeof(rate_prototype)[]
148152
ts, timeseries, ks = solution_arrays(u, tspan, rate_prototype;
@@ -166,14 +170,14 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem,
166170
# create solution
167171
if iscomposite(alg)
168172
id = OrdinaryDiffEq.CompositeInterpolationData(f_with_history, timeseries, ts, ks,
169-
Int[], dense, cache)
173+
Int[], dense, cache, differential_vars)
170174
sol = DiffEqBase.build_solution(prob, alg.alg, ts, timeseries;
171175
dense = dense, k = ks, interp = id,
172176
alg_choice = id.alg_choice, calculate_error = false,
173177
stats = stats)
174178
else
175179
id = OrdinaryDiffEq.InterpolationData(f_with_history, timeseries, ts, ks, dense,
176-
cache)
180+
cache, differential_vars)
177181
sol = DiffEqBase.build_solution(prob, alg.alg, ts, timeseries;
178182
dense = dense, k = ks, interp = id,
179183
calculate_error = false, stats = stats)
@@ -406,7 +410,8 @@ end
406410
typeof(tstops_propagated),
407411
typeof(d_discontinuities_propagated),
408412
OrdinaryDiffEq.fsal_typeof(alg.alg, rate_prototype),
409-
typeof(last_event_error), typeof(callback_cache)}(sol, u, k,
413+
typeof(last_event_error), typeof(callback_cache),
414+
typeof(differential_vars)}(sol, u, k,
410415
t0,
411416
tType(dt),
412417
f_with_history,
@@ -457,6 +462,7 @@ end
457462
opts,
458463
stats,
459464
history,
465+
differential_vars,
460466
ode_integrator)
461467

462468
# initialize DDE integrator

src/utils.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function Base.sizehint!(sol::DESolution, alg, tspan, tstops, saveat;
256256
nothing
257257
end
258258

259-
function build_history_function(prob, alg, rate_prototype, reltol;
259+
function build_history_function(prob, alg, rate_prototype, reltol, differential_vars;
260260
dt, dtmin, adaptive, calck, internalnorm)
261261
@unpack f, u0, tspan, p = prob
262262

@@ -303,15 +303,17 @@ function build_history_function(prob, alg, rate_prototype, reltol;
303303
ode_alg_choice = Int[]
304304
ode_id = OrdinaryDiffEq.CompositeInterpolationData(ode_f, ode_timeseries, ode_ts,
305305
ode_ks,
306-
ode_alg_choice, true, ode_cache) # dense = true
306+
ode_alg_choice, true, ode_cache,
307+
differential_vars) # dense = true
307308
ode_sol = DiffEqBase.build_solution(ode_prob, alg.alg, ode_ts, ode_timeseries;
308309
dense = true, k = ode_ks, interp = ode_id,
309310
alg_choice = ode_alg_choice,
310311
calculate_error = false,
311312
stats = DiffEqBase.Stats(0))
312313
else
313314
ode_id = OrdinaryDiffEq.InterpolationData(ode_f, ode_timeseries, ode_ts, ode_ks,
314-
true, ode_cache) # dense = true
315+
true, ode_cache,
316+
differential_vars) # dense = true
315317
ode_sol = DiffEqBase.build_solution(ode_prob, alg.alg, ode_ts, ode_timeseries;
316318
dense = true, k = ode_ks, interp = ode_id,
317319
calculate_error = false,
@@ -327,15 +329,17 @@ function build_history_function(prob, alg, rate_prototype, reltol;
327329
tdirType = typeof(sign(zero(tType)))
328330
ode_integrator = HistoryODEIntegrator{typeof(alg.alg), isinplace(prob), typeof(prob.u0),
329331
tType, tdirType, typeof(ode_k),
330-
typeof(ode_sol), typeof(ode_cache)}(ode_sol,
332+
typeof(ode_sol), typeof(ode_cache),
333+
typeof(differential_vars)}(ode_sol,
331334
ode_u, ode_k,
332335
t0,
333336
zero(tType),
334337
ode_uprev,
335338
t0, alg.alg,
336339
zero(tType),
337340
tdir, 1, 1,
338-
ode_cache)
341+
ode_cache,
342+
differential_vars)
339343

340344
# combine the user-provided history function and the ODE integrator with dense solution
341345
# to a joint dense history of the DDE

test/interface/dependent_delays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535

3636
@test sol3.errors[:l∞] < 3.0e-6
3737
@test sol3.errors[:final] < 1.4e-7
38-
@test sol3.errors[:l2] < 8.4e-7
38+
@test sol3.errors[:l2] < 9.6e-7
3939

4040
sol4 = solve(prob2, alg; abstol = 1e-13, reltol = 1e-13)
4141

0 commit comments

Comments
 (0)