Skip to content

Why does remake ignore my u0? #3661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bradcarman opened this issue May 23, 2025 · 0 comments
Open

Why does remake ignore my u0? #3661

bradcarman opened this issue May 23, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@bradcarman
Copy link
Contributor

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

@bradcarman bradcarman added the bug Something isn't working label May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants