In [1]:
import rebound
import numpy as np
sim = rebound.Simulation()
sim.add(m=1., hash="star") # Sun
sim.add(m=1.66013e-07,a=0.387098,e=0.205630, hash="planet") # Mercury-like
sim.move_to_com() # Moves to the center of momentum frame
ps = sim.particles
print("t = {0}, pomega = {1}".format(sim.t, sim.particles[1].pomega))
We add GR, and after integrating, see that the pericenter has moved:
In [2]:
import reboundx
rebx = reboundx.Extras(sim)
gr = rebx.load_force("gr")
rebx.add_force(gr)
from reboundx import constants
gr.params["c"] = constants.C
sim.integrate(10.)
print("t = {0}, pomega = {1}".format(sim.t, sim.particles[1].pomega))
Now we add some arbitrary parameters to the planet:
In [3]:
rebx.register_param('a', 'REBX_TYPE_INT')
rebx.register_param('b', 'REBX_TYPE_INT')
ps[1].params["a"] = 1
ps[1].params["b"] = 2
To save the simulation, we have to save a REBOUND binary to save the simulation, and a REBOUNDx binary to save the parameters and REBOUNDx effects:
In [4]:
sim.save("reb.bin")
rebx.save("rebx.bin")
We can now reload the simulation and the rebx instance:
In [5]:
sim2 = rebound.Simulation("reb.bin")
rebx2 = reboundx.Extras(sim2, "rebx.bin")
In [6]:
ps2 = sim2.particles
gr2 = rebx2.get_force("gr")
print("Original: {0}, Loaded: {1}".format(ps[1].params["a"], ps2[1].params["a"]))
print("Original: {0}, Loaded: {1}".format(ps[1].params["b"], ps2[1].params["b"]))
print("Original: {0}, Loaded: {1}".format(gr.params["c"], gr2.params["c"]))
We can now continue integrating as usual, and see that the pericenter continues to precess, so the GR effect has been successfully added to the loaded simulation:
In [7]:
sim2.integrate(20.)
print("t = {0}, pomega = {1}".format(sim2.t, sim2.particles[1].pomega))
In [ ]: