scenarioVariableTimeStepIntegrators
Overview
This script illustrates how to setup different variable time step integration methods for a basic 3-DOF orbit scenario. Both a fourth-order (RKF45) and a seventh-order (RKF78) integrators are used. For comparison, an RK4 integrator is also used.
The script is found in the folder basilisk/examples and executed by using:
python3 scenarioVariableTimeStepIntegrators.py
For more information on how to setup different integrators, see scenarioIntegrators. When the simulation completes, a plot is shown for illustrating both the true and the numerically evaluated orbit.
Illustration of Simulation Results
show_plots = True, integratorCase = {'rk4', 'rkf45', 'rkf78'}
The following figure illustrates the resulting trajectories relative to the true trajectory using a very coarse integration time step of 2 hours. The variable time step integrators still approximates the true orbit well, while the RK4 method is starting to show some visible errors, illustrating that much smaller time steps must be used with this method in this scenario.
Step Size and Tolerances
The task rate sets the largest integration step. At each task update the variable time step integrators start
with a trial step equal to the whole task period, and they can shorten the step to meet relTol and absTol,
but they never take a step longer than the task period. The tolerances therefore govern the accuracy only below
the task period, and they apply to each state in its own units, for example the position in m and the velocity
in m/s.
At the default relTol of 1e-4, the error estimate can accept long steps even where the dynamics change rapidly,
such as through the periapsis of an eccentric orbit. The function runAccuracyComparison() illustrates this by
propagating the orbit of this scenario with the RKF45 and RKF78 integrators and comparing the position with the
solution of Kepler’s equation. The cases log their states at different times, because the logging interval depends
on the task period, so the errors are compared at a common epoch: the latest time logged by every case, 156 hours
after the start, or about 0.88 orbits. It produces the following results:
Integrator |
Task period |
|
Position error |
|---|---|---|---|
RKF45 |
2 h |
1e-4, 1e-8 (default) |
3,310 km |
RKF45 |
2 h |
1e-8, 1e-12 |
1.6 km |
RKF78 |
2 h |
1e-4, 1e-8 (default) |
154 km |
RKF78 |
2 h |
1e-8, 1e-12 |
31 m |
RKF78 |
10 min |
1e-4, 1e-8 (default) |
0.01 m |
runAccuracyComparison(show_plots=True)
Most of the error is incurred during the first periapsis passage, a few hours into the run, and it then grows slowly. Either tightening the tolerances or shortening the task period reduces the error. The default tolerances may not be suitable for all orbit regimes, so the user should check the accuracy against a reference before relying on them.
Creating New Integrator Modules
New integration modules can be readily created for Basilisk. They are all stored in the folder
Basilisk/src/simulation/dynamics/Integrators/.
The integrators must be created to function on a general state vector and be independent of the particular
dynamics being integrated. Note that the default integrator is placed inside the _GeneralModulesFiles
folder within the dynamics folder.
- scenarioVariableTimeStepIntegrators.getKeplerPosition(mu, r0, v0, dt)[source]
Return the inertial position reached after propagating an initial state with Kepler’s equation.
- Parameters:
mu (double) – Gravitational parameter of the central body [m^3/s^2]
r0 (array) – Initial inertial position [m]
v0 (array) – Initial inertial velocity [m/s]
dt (double) – Propagation time [s]
- Returns:
Inertial position after
dt[m]- Return type:
array
- scenarioVariableTimeStepIntegrators.run(show_plots, integratorCase, relTol, absTol, simulationTimeStep=None)[source]
The scenarios can be run with the followings setups parameters:
- Parameters:
show_plots (bool) – Determines if the script should display plots
integratorCase (bool) –
Specify what type of integrator to use in the sim
String
Definition
’rk4’
RK4
’rkf45’
RKF45
’rkf78’
RKF78
relTol (double) – Specify the relative tolerance to use in the integration
absTol (double) – Specify the absolute tolerance to use in the integration
simulationTimeStep (int) – Optional dynamics task period in nanoseconds. Defaults to 2 hours.
- scenarioVariableTimeStepIntegrators.runAccuracyComparison(show_plots)[source]
Compare the position error of the RKF45 and RKF78 integrators against the solution of Kepler’s equation, using the default and tightened tolerances and two task periods.
- Parameters:
show_plots (bool) – Determines if the script should display plots
- Returns:
A dictionary of position errors in meters at the common evaluation epoch, a dictionary of the evaluation time used for each case in seconds, both keyed by case label, and the figure dictionary
- Return type:
tuple