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|
* - 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:
|Chin-Chen (or Optimised)||4||Yes||Yes||Yes|
|Runge-Kutta-4 (or 4n)||4||Yes||Yes||Yes|
|Runge-Kutta-2n (or 2n_fsal)||2||Yes||Yes||Yes|
* - 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:
* - 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|
* - 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:
|Total Energy||KE + PE||Watch for errors|
|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|
|Maximum Speed||Calculated||Watch for ejections|
|Half-Mass Speed||Calculated||Watch for core cooling|
|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.