Skip to content
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

Callback dosen't work when is set to "save_positions = (false, true)" #1046

Closed
yunan-l opened this issue Aug 11, 2024 · 1 comment
Closed
Labels

Comments

@yunan-l
Copy link

yunan-l commented Aug 11, 2024

Hi, I tried to set the "save_positions = (false, true)" to only save the state values after the event, but failed. It still saved the values before and after the event (“double save” ). Please see the below:

using DifferentialEquations, Plots
function f(du, u, p, t)
    du[1] = -u[1]
end
u0 = [10.0]
prob = ODEProblem(f, u0, (0.0, 10.0))

condition(u, t, integrator) = t == 4
affect!(integrator) = integrator.u[1] += 10
cb = DiscreteCallback(condition, affect!; save_positions = (false, true))

sol = solve(prob, Tsit5(), callback = cb, tstops = [4])

sol.t
22-element Vector{Float64}:
  0.0
  0.10000199992000479
  0.3420229369016172
  0.6552769527588096
  1.0310596557404956
  1.470610835625779
  1.9654372701948286
  2.510852255671655
  3.0991540633746
  3.7244761095148275
  4.0
  4.0
  4.535515171750724
  4.995616597492678
  5.575642288964066
  6.1561472937094255
  6.795295351347132
  7.451558338536082
  8.139599569463904
  8.84425844508113
  9.567790810446223
 10.0

Is this a bug?

@yunan-l yunan-l added the bug label Aug 11, 2024
@yunan-l yunan-l changed the title Callback's argument "save_positions = (true, true)" dosen't work when is set to "save_positions = (false, true)" Callback dosen't work when is set to "save_positions = (false, true)" Aug 11, 2024
@ChrisRackauckas
Copy link
Member

One is from the callback while the other is because you have the integrator set to save each step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants