Skip to content

Commit f765513

Browse files
Fix for ODE sumtype default solver as new default
Fixes #329
1 parent c32cf6f commit f765513

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/integrators/interface.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,33 @@ function OrdinaryDiffEqCore.perform_step!(integrator::DDEIntegrator)
138138
nothing
139139
end
140140

141+
# DefaultCache sumtype does lazy initializations of sub-caches
142+
# Need to overload this function so that the history function has initialized caches
143+
# https://github.com/SciML/DelayDiffEq.jl/issues/329
144+
function OrdinaryDiffEqCore.perform_step!(integrator::DDEIntegrator, cache::OrdinaryDiffEqCore.DefaultCache, repeat_step = false)
145+
algs = integrator.alg.algs
146+
OrdinaryDiffEqCore.init_ith_default_cache(cache, algs, cache.current)
147+
if cache.current == 1
148+
integrator.history.integrator.cache.cache1 = cache.cache1
149+
OrdinaryDiffEqCore.perform_step!(integrator, @inbounds(cache.cache1), repeat_step)
150+
elseif cache.current == 2
151+
integrator.history.integrator.cache.cache2 = cache.cache2
152+
OrdinaryDiffEqCore.perform_step!(integrator, @inbounds(cache.cache2), repeat_step)
153+
elseif cache.current == 3
154+
integrator.history.integrator.cache.cache3 = cache.cache3
155+
OrdinaryDiffEqCore.perform_step!(integrator, @inbounds(cache.cache3), repeat_step)
156+
elseif cache.current == 4
157+
integrator.history.integrator.cache.cache4 = cache.cache4
158+
OrdinaryDiffEqCore.perform_step!(integrator, @inbounds(cache.cache4), repeat_step)
159+
elseif cache.current == 5
160+
integrator.history.integrator.cache.cache5 = cache.cache5
161+
OrdinaryDiffEqCore.perform_step!(integrator, @inbounds(cache.cache5), repeat_step)
162+
elseif cache.current == 6
163+
integrator.history.integrator.cache.cache6 = cache.cache6
164+
OrdinaryDiffEqCore.perform_step!(integrator, @inbounds(cache.cache6), repeat_step)
165+
end
166+
end
167+
141168
# initialize the integrator
142169
function DiffEqBase.initialize!(integrator::DDEIntegrator)
143170
ode_integrator = integrator.integrator

test/interface/default.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using DelayDiffEq, Test
2+
function delay_lotka_volterra(du, u, h, p, t)
3+
# Model parameters.
4+
α, β, γ, δ = p
5+
# Current state.
6+
x, y = u
7+
# Evaluate differential equations
8+
du[1] = α * h(p, t - 1; idxs=1) - β * x * y
9+
du[2] = -γ * y + δ * x * y
10+
return nothing
11+
end
12+
p = (1.5, 1.0, 3.0, 1.0)
13+
u0 = [1.0; 1.0]
14+
tspan = (0.0, 10.0)
15+
h(p, t; idxs::Int) = 1.0
16+
prob_dde = DDEProblem(delay_lotka_volterra, u0, h, tspan, p);
17+
alg = MethodOfSteps(DefaultODEAlgorithm())
18+
sol_dde = solve(prob_dde, alg)
19+
sol_dde2 = solve(prob_dde)
20+
21+
@test sol_dde == sol_dde2

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ if GROUP == "All" || GROUP == "Interface"
3939
@time @safetestset "Mass matrix Tests" begin
4040
include("interface/mass_matrix.jl")
4141
end
42+
@time @safetestset "Default Solver Tests" begin
43+
include("interface/default.jl")
44+
end
4245
@time @safetestset "Parameterized Function Tests" begin
4346
include("interface/parameters.jl")
4447
end

0 commit comments

Comments
 (0)