Skip to content

Commit

Permalink
Merge 97ba7c4 into 58e5bda
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Nov 3, 2017
2 parents 58e5bda + 97ba7c4 commit 0972ca4
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/integrator_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,73 @@ Stop further calculations of `integrator`.
function terminate!(integrator::DDEIntegrator)
integrator.opts.tstops.valtree = typeof(integrator.opts.tstops.valtree)()
end

DiffEqBase.has_reinit(integrator::DDEIntegrator) = true
function DiffEqBase.reinit!(integrator::DDEIntegrator,u0 = integrator.sol.prob.u0;
t0 = integrator.sol.prob.tspan[1], tf = integrator.sol.prob.tspan[2],
erase_sol = true, tstops = nothing, saveat = nothing)

if isinplace(integrator.sol.prob)
recursivecopy!(integrator.u,u0)
recursivecopy!(integrator.uprev,integrator.u)
else
integrator.u = u0
integrator.uprev = integrator.u
end

if OrdinaryDiffEq.alg_extrapolates(integrator.alg)
if isinplace(integrator.sol.prob)
recursivecopy!(integrator.uprev2,integrator.uprev)
else
integrator.uprev2 = integrator.uprev
end
end

integrator.t = t0
integrator.tprev = t0

# Get rid of tstops states
while !isempty(integrator.opts.tstops)
pop!(integrator.opts.tstops)
end
push!(integrator.opts.tstops,tf)
if tstops != nothing
push!(integrator.opts.tstops,tstops)
end

# Get rid of saveat states
while !isempty(integrator.opts.saveat)
pop!(integrator.opts.saveat)
end
if saveat != nothing
push!(integrator.opts.saveat,saveat)
end

if erase_sol
if integrator.opts.save_start
resize_start = 1
else
resize_start = 0
end
resize!(integrator.sol.u,resize_start)
resize!(integrator.sol.t,resize_start)
resize!(integrator.sol.k,resize_start)
if integrator.sol.u_analytic != nothing
resize!(integrator.sol.u_analytic,0)
end
if typeof(integrator.alg) <: OrdinaryDiffEq.OrdinaryDiffEqCompositeAlgorithm
resize!(integrator.sol.alg_choice,resize_start)
end
integrator.saveiter = resize_start
end
integrator.iter = 0
integrator.success_iter = 0

# full re-initialize the PI in timestepping
integrator.qold = integrator.opts.qoldinit
integrator.q11 = typeof(integrator.t)(1)

reinit!(integrator.integrator,u0;t0=t0,tf=tf,erase_sol=true,tstops=tstops,
saveat=saveat,reinit_cache = false)
initialize!(integrator)
end
16 changes: 16 additions & 0 deletions test/reinit.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DelayDiffEq, DiffEqProblemLibrary, Base.Test

alg = MethodOfSteps(BS3(); constrained=false)
prob = prob_dde_1delay_scalar_notinplace
integrator = init(prob, alg, dt= 0.01)
solve!(integrator)

u = copy(integrator.sol.u)
t = copy(integrator.sol.t)

reinit!(integrator)
integrator.dt = 0.01
solve!(integrator)

@test u == integrator.sol.u
@test t == integrator.sol.t

0 comments on commit 0972ca4

Please sign in to comment.