View source: R/continue_simulation.R
| continue_simulation | R Documentation |
Rebuilds the system from the final time step of a simulation, runs it forward, and appends the new rows with 'time' continuing from where the previous run ended. Use it to extend a run without starting over, to change the time step partway through (small steps through a close approach, large ones elsewhere), or to apply a change between segments, such as a velocity kick or an added body, by editing the tibble before continuing.
continue_simulation(sim_data, time_step, duration, G = NULL, ...)
sim_data |
A tibble output from [simulate_system()] or from a previous call to 'continue_simulation()'. |
time_step |
The time increment per step in seconds for the new segment. Need not match the previous segment's. |
duration |
Total time in seconds to simulate in the new segment. |
G |
The gravitational constant. Defaults to the value recorded by [simulate_system()], or to [gravitational_constant]. |
... |
Further arguments passed to [simulate_system()]: 'method', 'softening', and 'use_cpp'. When not supplied, 'method' and 'softening' default to the values recorded from the previous segment. |
The last row of each body in 'sim_data' is a complete state, so the restart is exact: the new segment begins from precisely where the old one stopped. The new segment's first step duplicates the old segment's last and is dropped, so 'time' is strictly increasing in the result.
Each segment is integrated independently with a fixed step. Changing the step between segments disturbs the integration by about one step's worth of error at the switch, which is usually far smaller than the error saved by using a small step only where it is needed. A comet's perihelion passage is the typical use: run with a step of days out to a few AU, a step of hours through perihelion, and days again on the way out.
A tibble with the same columns as 'sim_data' and the new time steps appended.
# A comet on a highly eccentric orbit, started at aphelion
comet <- create_system() |>
add_sun() |>
add_body_keplerian("Comet", mass = 1e14, parent = "Sun",
a = 5 * distance_earth_sun, e = 0.9, nu = 180)
# Coarse steps on the way in, fine steps through perihelion, coarse again
sim <- comet |>
simulate_system(time_step = seconds_per_day * 5,
duration = seconds_per_year * 5) |>
continue_simulation(time_step = seconds_per_hour * 2,
duration = seconds_per_year * 1.2) |>
continue_simulation(time_step = seconds_per_day * 5,
duration = seconds_per_year * 5)
range(sim$time) / seconds_per_year
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.