|
|
|
Gravity simulation on a desktop computer |
|
You need to keep an eye on the speed and accuracy of a Grav-Sim simulation.
Grav-Sim provides 3 different simulators:
| Simulator | Speed | Accuracy | Machine Precision | Suitable For |
|---|---|---|---|---|
| FastSim | Fast | < 7 decimal digits | float | Globular Clusters |
| GravSim | Medium | < 15 decimal digits | double | Open Clusters |
| FineSim | Slow | < 30 decimal digits | dd_real | Planetary Systems |
Pick the wrong one and FastSim will have the planet eventually wandering away from the star in a 2-body model, or FineSim will take a very long time simulating a 100,000-body model.
Grav-Sim offers a choice of time-step type:
| Type | Overall Speed | Simulation Time | |
|---|---|---|---|
| Individual* | Fast | Variable** | |
| Shared*** | Medium | Variable** | |
| Constant | Slow | Predictable | |
* - the default | |||
Constant time-steps are the simplest, but suffer from inaccuracy when bodies come close together and need shorter time-steps.
Shared time-steps provide this adaptive behaviour, whilst still keeping all bodies on the same time-steps at the same times.
Individual time-steps provide fully adaptive behaviour and do not restrict bodies to having the same time-steps at the same times.
Unless predictability of simulation time is important to you, Individual time-steps are recommended.
The Grav-Sim simulators use numerical integration techniques to work out where the bodies will be a short time in the future. The calculation is based on where they are now, how fast they’re moving and how strong the pull of gravity is due to the other bodies in the system. The process is then repeated based on the new positions, speed and gravity, moving forward in time step by step.
A choice of integration methods is available:
| Integrator | Order* | Available With | ||
|---|---|---|---|---|
| FastSim | GravSim | FineSim | ||
| Hermite-8 | 8 | No | Yes | Yes |
| Hermite-6 | 6 | Yes** | Yes** | Yes** |
| Hermite | 4 | Yes | Yes | Yes |
| Chin-Chen (or Optimised) | 4 | Yes | Yes | Yes |
| Runge-Kutta-4 (or 4n) | 4 | Yes | Yes | Yes |
| Runge-Kutta-3 | 3 | Yes | Yes | Yes |
| Leap-Frog | 2 | Yes | Yes | Yes |
| Runge-Kutta-2n (or 2n_fsal) | 2 | Yes | Yes | Yes |
| Proto-Hermite | 2 | Yes | Yes | Yes |
| Forward-Plus*** | 1 | Yes | Yes | Yes |
| Forward-Euler*** | 1 | Yes | Yes | Yes |
| Multi-Step**** | 2 | No | No | No |
* - the order of error reduction with increasing number of steps | ||||
Grav-Sim provides a variety of ways to organise the gravity calculations, depending on whether speed or accuracy is the priority:
| Accelerator | Order* | Accuracy | Speed | Interactor | Space Divider |
|---|---|---|---|---|---|
| Brute-Force | O(n2) | Exact | Slow | N/A | N/A |
| Barnes-Hut | O(n log(n)) | Approximate | Medium | Direct | Octree |
| Stadel | O(n log(n)) | Approximate | Medium | Direct | KDTree |
| Ridler** | O(n log(n)) | Approximate | Medium | Direct | Hilbert |
| Dehnen | O(n) | V. Approximate | Fast | Pairwise | Octree |
| Dehnen-Stadel*** | O(n) | V. Approximate | Fast | Pairwise | KDTree |
| Dehnen-Ridler*** | O(n) | V. Approximate | Fast | Pairwise | Hilbert |
* - the order of simulation time with increasing number of bodies | |||||
Grav-Sim automatically judges the number of steps to use depending on the integrator and the model (and also the local conditions in the model if Variable time-steps are used).
Level 1 uses the fewest number of steps to produce a reliable result. You can increase the number of steps by going to level 2, 3 etc. Each successive level uses a factor of sqrt(2) times more than the previous one:
| Level | Approximate Steps Per Orbit | |||
|---|---|---|---|---|
| Hermite-8 | Hermite-6 | Hermite | Leap-Frog | |
| 1* | 148 | 193 | 250 | 500 |
| 2 | 209 | 273 | 354 | 707 |
| 3 | 296 | 386 | 500 | 1000 |
| 4 | 418 | 546 | 707 | 1414 |
| 5 | 592 | 772 | 1000 | 2000 |
| 6 | 836 | 1092 | 1414 | 2828 |
* - the default, all integrators have been tuned to achieve a similar level of accuracy at level 1 | ||||
There is little point in using anything other than level 1 with FastSim because calculations are only accurate to 7 decimal places anyway.
The higher-order integrators (e.g. Hermite-8) need fewer steps to achieve a given level of accuracy, at the cost of more computation time per step. However, from level 2 upwards they improve in accuracy at a higher rate compared to the lower-order integrators (e.g. Leap-Frog).
Grav-Sim provides some simple statistics as part of its logging:
| Statistic | Definition | Comments |
|---|---|---|
| Simulated Time | Parameter | |
| Kinetic Energy | Calculated | |
| Potential Energy | Calculated | |
| Total Energy | KE + PE | Watch for errors |
| Total Mass | Constant | |
| Centre of Mass | Constant | Watch for errors |
| Drift Velocity | Constant | Watch for errors |
| Maximum Distance | Calculated from origin | Watch for ejections |
| Half-Mass Distance | Calculated | Watch for core collapse |
| Root-Mean-Square Distance | Calculated | |
| Maximum Speed | Calculated | Watch for ejections |
| Half-Mass Speed | Calculated | Watch for core cooling |
| Root-Mean-Square Speed | Calculated | |
| Crossing Time | RMS Distance / RMS Speed | Useful as simulation time |
| Minimum Collision Time | Calculated | Scale for Constant time-steps |
| Root-Mean-Square Collision Time | Calculated | Watch for errors |
| Closest Approach So Far | Calculated | Watch for near misses |
All stats are produced both at the beginning and the end of a run so you can make a comparison.
The time and energy stats are also reported during a run, at a defined number of log points.
The Total Energy stat in particular is a sensitive measure of accumulated errors leading to non-physical results.
The high accuracy of the Brute-Force accelerator benefits from shorter time-steps but takes longer to compute.
You can see the effect of using shorter time-steps in the following orbit plots from the 2-body model. The simulations were performed with GravSim using the Leap-Frog integrator and Constant time-steps. Each simulation ran for a duration of 200 orbits, with every 20th orbit drawn on the graph.
The orbits should be perfect ellipses, each one overlapping the last. The deviation gives an indication of the overall accuracy.
500 Steps Per Orbit |
707 Steps Per Orbit |
1000 Steps Per Orbit |
Grav-Sim has been written to take advantage of the capabilities of modern multi-core CPUs. It uses OpenMP to divide up the work amongst the available processors, leading to improved performance compared to serial execution. The following specific (time-consuming) parts of the code support parallel processing:
Up to 92% scaling efficiency can be achieved on a dual-core CPU for Brute-Force with Shared or Constant time-steps.
The Pairwise interactor is a clear candidate for future parallisation. The Octree, KDTree and Hilbert tree codes could also be parellelised during tree construction.
The execution mode can be controlled at run time with the command-line switch: -cpu serial or: -cpu parallel.