Skip to main content

continue_simulation

continue_simulation(
    sim_data,
    time_step,
    duration,
    G=None,
    method=None,
    softening=None,
)

Run on from a simulation’s last state and append the new rows.

Picks up the positions and velocities at the last recorded time of sim_data, integrates for a further duration, and returns the old rows followed by the new ones with the clock still running. Use it to extend a run that turned out too short, or to change the time step partway through, for example a coarse step for a long approach and a fine one for a close encounter.

Parameters

Name Type Description Default
sim_data DataFrame The output of simulate_system or an earlier continue_simulation, as a pandas or polars DataFrame. required
time_step float Time between recorded states in the new segment, in seconds. It does not have to match the step of the earlier segment. There is no default. required
duration float Length of the new segment in seconds, counted from the last recorded time of sim_data. There is no default. required
G float or None Gravitational constant in m^3 kg^-1 s^-2. The default None uses the value recorded with sim_data, or the standard value orb.gravitational_constant if none was recorded. None
method str or None The integrator: "verlet", "euler_cromer" or "euler". The default None uses the method recorded with sim_data, or "verlet" if none was recorded. None
softening float or None Softening length in meters. The default None uses the value recorded with sim_data, or 0 if none was recorded. None

Returns

Name Type Description
DataFrame The same kind of DataFrame as sim_data (pandas or polars): all the rows of sim_data, then one row per body per new time step, with columns id, mass, x, y, z, vx, vy, vz, time in SI units. The new times carry on from the last time in sim_data, and that last state is not repeated. The recorded run settings are updated to the G, softening, method and time_step used for the new segment.

Raises

Name Type Description
TypeError If sim_data is not a pandas or polars DataFrame with the columns id, mass, x, y, z, vx, vy, vz, time.
ValueError If method is not one of the three integrators, if time_step is not positive, or if duration is negative.

See Also

Notes

A polars DataFrame only carries its run settings if it is the exact DataFrame pyorbiter returned. If you have filtered or transformed a polars result since, and the run did not use the defaults, pass G, method and softening yourself.

Examples

Thirty days of the Earth around the Sun in daily steps, then thirty more.

import pyorbiter as orb

sim = orb.create_system().add_sun().add_planet("Earth", parent="Sun").simulate(
    time_step=orb.seconds_per_day, duration=30 * orb.seconds_per_day)

longer = orb.continue_simulation(sim, time_step=orb.seconds_per_day,
                                 duration=30 * orb.seconds_per_day)
longer.tail()
id mass x y z vx vy vz time
117 Earth 5.972000e+24 -1.408225e+11 4.643550e+10 0.0 -9816.385144 -28404.325293 0.0 5011200.0
118 Sun 1.989000e+30 -1.255005e+05 1.945111e+05 0.0 -0.060652 0.065380 0.0 5097600.0
119 Earth 5.972000e+24 -1.416492e+11 4.397431e+10 0.0 -9319.700160 -28563.298922 0.0 5097600.0
120 Sun 1.989000e+30 -1.308054e+05 2.001800e+05 0.0 -0.062151 0.065831 0.0 5184000.0
121 Earth 5.972000e+24 -1.424329e+11 4.149977e+10 0.0 -8820.560330 -28713.480370 0.0 5184000.0

The second segment can use a different time step. Here it switches from daily to hourly steps.

import pyorbiter as orb

sim = orb.create_system().add_sun().add_planet("Earth", parent="Sun").simulate(
    time_step=orb.seconds_per_day, duration=30 * orb.seconds_per_day)

finer = orb.continue_simulation(sim, time_step=orb.seconds_per_hour,
                                duration=orb.seconds_per_day)
finer[finer["id"] == "Earth"].tail()
id mass x y z vx vy vz time
101 Earth 5.972000e+24 -1.030431e+11 1.054792e+11 0.0 -21797.014047 -20929.750205 0.0 2664000.0
103 Earth 5.972000e+24 -1.031215e+11 1.054038e+11 0.0 -21781.649418 -20945.466472 0.0 2667600.0
105 Earth 5.972000e+24 -1.031999e+11 1.053284e+11 0.0 -21766.273395 -20961.171200 0.0 2671200.0
107 Earth 5.972000e+24 -1.032783e+11 1.052529e+11 0.0 -21750.885986 -20976.864381 0.0 2674800.0
109 Earth 5.972000e+24 -1.033565e+11 1.051774e+11 0.0 -21735.487202 -20992.546006 0.0 2678400.0