Skip to content

Why does remake ignore my u0? #3661

Open
@bradcarman

Description

@bradcarman

Take the following...

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq
using CairoMakie

pars = @parameters begin
    k(t)
end

vars = @variables begin
    x(t)
end

eqs = [
    D(x) ~ (k - x)
]

@mtkbuild sys = ODESystem(eqs, t, vars, pars)
prob = ODEProblem(sys, [x=>0], (0, Inf), [k => 0])
integrator = init(prob, Rodas5P())

dt=0.1
for i=1:100
    integrator.ps[sys.k] = ((i-1)*dt)^2
    step!(integrator, dt, true)
end

prob_copy = remake(prob; u0=integrator.u, p = integrator.p, tspan= (99*dt, Inf))
integrator_copy = init(prob_copy, Rodas5P(); initializealg=CheckInit())

for i=101:200
    integrator.ps[sys.k] = ((i-1)*dt)^2
    integrator_copy.ps[sys.k] = ((i-1)*dt)^2
    step!(integrator, dt, true)
    step!(integrator_copy, dt, true)
end

time = 0:dt:199*dt
time_copy = 10:dt:199*dt

fig = Figure()
ax = Axis(fig[1,1], xlabel="time [s]", ylabel="sys.x")
lines!(ax, time, integrator.sol(time; idxs=sys.x).u; label="integrator")
scatter!(ax, time_copy, integrator_copy.sol(time_copy; idxs=sys.x).u; color=:red, label="integrator_copy")
axislegend(ax; position=:lt)
fig

This gives the following...

Image

If I transfer the state u0 and the parameters p from integrator to integrator_copy, why does integrator_copy start at 0 instead of 81?

using ModelingToolkit v9.79.0

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions