Skip to content

Instantly share code, notes, and snippets.

@helgee
Created February 27, 2018 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgee/b4641b92015d043148a12d7ae97d0730 to your computer and use it in GitHub Desktop.
Save helgee/b4641b92015d043148a12d7ae97d0730 to your computer and use it in GitHub Desktop.
Multiple ContinuousCallbacks
using OrdinaryDiffEq
using PyPlot
mu = 398600.4418
function affect!(integrator)
println("I am affecting at t=$(integrator.t)")
end
function apocenter_condition(u, t, integrator)
-(u[1:3] ⋅ u[4:6])
end
function pericenter_condition(u, t, integrator)
u[1:3] ⋅ u[4:6]
end
apo_cb = ContinuousCallback(apocenter_condition, affect!, nothing);
peri_cb = ContinuousCallback(pericenter_condition, affect!, nothing);
cbs = CallbackSet(apo_cb, peri_cb);
function newton!(du, u, p, t)
r = norm(u[1:3])
du[1:3] = u[4:6]
du[4:6] = -mu * u[1:3] / r^3
end
r = [
6068279.27,
-1692843.94,
-2516619.18,
]/1000
v = [
-660.415582,
5495.938726,
-5303.093233,
]/1000
y0 = [r; v]
prob = ODEProblem(newton!, y0, (0, 5562.095583019713), callback=cbs)
res = solve(prob, Vern9())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment