scenarioIntegratorsComparison

Overview

This scenario illustrates how different integrators compare in terms of accuracy and computational cost.

The script is found in the folder basilisk/examples and executed by using:

python3 scenarioIntegratorsComparison.py

For information on how to setup different integrators, see scenarioIntegrators and scenarioVariableTimeStepIntegrators.

Currently, Basilisk only supports explicit Runge-Kutta integrators, both of the regular and adaptive variations. Non-adaptive Runge-Kutta integrators can be controlled solely by the step size: larger step sizes means that faster computation, but less accurate results.

In contrast, adaptive Runge-Kutta methods are affected both by the step size and absolute and relative tolerance. These integrators will try to use the user-given step size, but if the error grows too large, a smaller time step is used internally for greater accuracy.

When using an adaptive integrator, the Basilisk dynamics task time step can be increased without risk of increasing the integration error. However, this also means that other modules in the task are updated less often, which might be undesirable. Additionally, spacecraft state messages will also be updated less frequently.

Finally, each integrator is associated with an order. Greater order integrators are more accurate, but more computationally expensive. The order of a method cannot be altered by users.

Comparison of integrators

Five integrators are compared in this section, two of them adaptive. These are the Euler method (order 1), Heun’s method (order 2), the Runge-Kutta 4 (order 4), the Runge-Kutta-Fehlberg 4(5) (adaptive with order 5), and the Runge-Kutta-Fehlberg 7(8) (adaptive with order 8). The adaptive integrators are used with two different absolute tolerances: 0.1 and 10.

Each integrator is used to propagate a two-body orbit around the Earth. The final position of each propagation is compared to the analytical solution, and a final position error is obtained. Moreover, the time that it takes to propagate each orbit is recorded.

../_images/scenarioIntegratorsComparison.svg

The figure above shows the results for the analysis previously described. Note that the axis are expressed in logarithmic scale.

For the fixed step integrators, one can see a clear linear trend for the error with respect to the step size. Moreover, the slope of each of these lines depends on the order of the method. Thus, reducing the size of the time steps produces exponential gains in accuracy, with this exponential improvement being stronger for methods of higher order.

Unfortunately, the computational costs also grow in an exponential fashion with the time step. However, it is interesting to note that the slope of these lines is not dependent on the method order.

Analyzing the adaptive Runge-Kutta methods is more challenging. One can distinguish two distinct behaviours. For small time steps, the methods behave similarly to fixed-step RK methods. This is because the user-provided step size is small enough to achieve the desired accuracy, and thus no “adaption” is needed. For larger time steps, however, the integrator has to take smaller internal steps to adjust to the desired accuracy, and thus we see that the position error does not depend on the user-provided time step, but instead it depends on the tolerance used.

In terms of computational cost, adaptive RK methods behave similarly to fixed-step RK methods. The main difference occurs for the larger time steps in which time adaption takes place. Here, a tighter tolerance would translate into higher computational costs. However, this is hard to see in the plot given the inherent noisiness of performance measuring.

Fixed-timestep integrators are helpful when you want your simulation runtime to be consistent as you vary simulation parameters. Since there is no adaptation, runtime will be similar even if the parameters change the stiffness of the system’s dynamic equations. Of course, this comes at the cost of accuracy, but can it be very useful for hardware-in-the-loop simulations.

One should note that adaptive RK methods are inherently slower than their fixed-step counterparts. This is because the former methods have a greater computational overhead. Adaptive methods are preferable when the simulation step size can be made large enough, or when the stiffness of the dynamic changes significantly during propagation (i.e. for very elliptical orbits). Fixed-step methods, on the other hand, should be preferred when the simulation has to run at small enough time steps (because other simulation models need updating), or when the dynamics remain similar during propagation.

To sum up, choosing an integrator has a significant impact on the accuracy and speed of your simulation. However, there is no single, perfect intergator for every problem. The most optimal alternative may only be found through testing.

class scenarioIntegratorsComparison.IntegratorData(label: str, type: type, color: int, linestyle: str = '-', absTol: Optional[float] = None)[source]

Bases: object