In most cases, you will want to integrate your simulation to a given time. This could be the time at which you want to create the next output, or a very long time into the future, if you are waiting for an exception to happen (close encounter, ejection, etc).
In those cases use this syntax:
=== "C"
c struct reb_simulation* r = reb_create_simulation(); // ... setup simulation, set timestep ... reb_integrate(r, 100.); // integrate until t=100.
If you want to integrate indefinitely, you can use
c reb_integrate(r, INFINITY);
=== "Python"
python sim = rebound.Simulation() sim.integrate(100.) # integrate until t=100.
The integrate function will integrate the simulation until it reaches exactly the time requested. In most cases the time requested will not be an exact multiple of the timestep, so the timestep will have to be reduced during the last timestep. After the requested time has been reached, the timestep will be reverted back to its original value.
There are cases where you don't want to reduce the timestep, for example in long term integrations with symplectic integrators.
In those cases, you can ask REBOUND to integrate up to a given time and overshoot the requested time by a fraction of the timestep.
This allows REBOUND to maintain a constant timestep throughout the integration.
The following code shows you how to do that.
=== "C"
c struct reb_simulation* r = reb_create_simulation(); // ... setup simulation, set timestep ... r->exact_finish_time = 0; reb_integrate(r, 100.); // integrate until t=100. or a bit further
=== "Python"
python sim = rebound.Simulation() # ... setup simulation, set timestep ... sim.integrate(100., exact_finish_time=0) # integrate until t=100. or a bit further
Rather than integrating up to a fixed time, you can also advance the simulation by a single timestep:
=== "C"
c struct reb_simulation* r = reb_create_simulation(); // ... setup simulation, set timestep ... reb_step(r);
=== "Python"
python sim = rebound.Simulation() # ... setup simulation, set timestep ... sim.step()
And finally, you can ask REBOUND to advance the simulation by a finite number of steps.
=== "C"
c struct reb_simulation* r = reb_create_simulation(); // ... setup simulation, set timestep ... reb_steps(r, 100); // 100 steps
=== "Python"
python sim = rebound.Simulation() # ... setup simulation, set timestep ... sim.steps(100) # 100 steps
Depending on the safe_mode
flag, some integrators perform optimizations which effectively leave a timestep unfinished.
You can manually 'synchronize' the simulation by calling
=== "C"
c struct reb_simulation* r = reb_create_simulation(); // ... setup simulation ... reb_synchronize(r);
=== "Python"
python sim = rebound.Simulation() # ... setup simulation ... sim.synchronize()
See the discussion on integrators for more information about the safe_mode
and synchronizing simulations.