-
-
Notifications
You must be signed in to change notification settings - Fork 239
Closed
Description
Hello, I am trying to retrieve the derivatives and save them to elsewhere and find a problem. Consider the following naive example:
using DifferentialEquations
function foo(du, u, p, t)
du.x[1] .= u.x[1] / 10
du.x[2] .= u.x[2] / 100
du.x[3] .= u.x[3] / 1000
end
u0 = ArrayPartition(rand(2, 3), rand(5), rand(3, 2))
tspan = (0.0, 1000.0)
prob = ODEProblem(foo, u0, tspan)
cb1 = FunctionCallingCallback((u, t, integrator) -> integrator.fsallast)
cb2 = FunctionCallingCallback((u, t, integrator) -> integrator.cache.tmp)
cb3 = FunctionCallingCallback((u, t, integrator) -> get_du(integrator))
solve(prob, Tsit5(); callback=cb1) # ERROR: UndefRefError: access to undefined reference
solve(prob, Tsit5(); callback=cb2) # OK
solve(prob, Tsit5(); callback=cb3) # ERROR: UndefRefError: access to undefined referenceAccessing field fsallast of integrator would trigger this error. However, the following seems works without a glitch:
integrator = init(prob, Tsit5())
for i = 1: 100
step!(integrator)
x = get_du(integrator)
y = integrator.cache.tmp
@show x.x[1][1, 1], y.x[1][1, 1]
end # seems no errorBut the derivatives are different (which one should I use?). How do I reliably retrieve the derivatives in such case? I am all on the latest Julia and packages.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels