Discrete callback is saving both before and after the callback even when save_positions = (false,true)
.
For example:
function dynamics(u,p,t)
du = [2.0,3.0,1.0]
return du
end
prob = ODEProblem(dynamics, [0.0,0.0,0.0], (0,10))
cond_true(u,t,integrator) = true
affect!(integrator) = (integrator.u[1] = integrator.t)
cb = DiscreteCallback(cond_true, affect!, save_positions = (false, true))
testsol = solve(prob, Tsit5(); callback=cb)
plot(testsol)
Here, u[1] should have been equal to u[3]. I am seeing two saves at each time point.
If I manually scan for sol.t[i]==sol.t[i+1]
, I could separate out the saves after callback but is there some better way to do this?
My understanding is that solver is saving each successful step and then checking callback conditions, and then saving that. Is it possible to somehow tell the solver to update (not append) the solution if the new time point is equal to previous time point?
PS: I made this post in a thread about similar discussion without realizing it was a very old discussion. Sorry about that.