Created
August 14, 2023 16:38
-
-
Save hannorein/615f806cabe0493e110d326e2885b6e3 to your computer and use it in GitHub Desktop.
Garrett
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sim = rebound.Simulation() | |
sim.integrator = "ias15" | |
sim.add(m=1.) | |
sim.add(m=1e-3, a=1., r=np.sqrt(1e-3/3.)) | |
sim.add(m=5e-3, a=1.25, r=1.25*np.sqrt(5e-3/3.)) | |
sim.collision="direct" | |
sim.collision_resolve = "halt" | |
E0 = sim.energy() | |
A0 = sim.angular_momentum()[2] | |
try: | |
sim.integrate(40) | |
except rebound.Collision: | |
E_before = sim.energy() | |
A_before = sim.angular_momentum()[2] | |
sim.collision_resolve = "merge" | |
sim.step() | |
E_collision = E_before-sim.energy() | |
A_collision = A_before-sim.angular_momentum()[2] | |
sim.integrate(40) | |
print("Rel. energy error: %e"%((E0-sim.energy()-E_collision)/E0)) | |
print("Rel. angular momentum error: %e"%((A0-sim.angular_momentum()[2]-A_collision)/A0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment