N-Body Simulation

The mathematical model of a group of objects moving under the influence of gravity (for example, stars and planets moving in space) is known as an *N*-body problem. Universe Sandbox simulates this motion using an *N*-body simulation, also known as *N*-body integration, a computational method used to numerically solve the *N*-body problem. An N-body simulation takes small steps forward in time and looks at how each object affects every other object in the system. At each time step, the gravitational force acting on each object is calculated, then used to determine how each object will move during that time step. The object are moved to their new positions, and then the simulation moves on to the next time step.

The speed at which an *N*-body simulation can run on a given computer depends on:

1. The hardware of the computer
2. The number of objects in the simulation (the "*N*" in "*N*-body")
3. The size of the time step used, and
4. The type of *N*-body simulation methods that is used. Some *N*-body simulation methods are faster, but less accurate over time, than others. Universe Sandbox allows the user to switch between different *N*-body simulation methods (see Models below).

## Related Properties & Settings

### Properties

* The Mass of an object will affect its gravitational force
* Gravity affect the Motion of an object, including its Distance, Speed, Orbital Elements, etc.

### Settings

* The simulation's Simulation Speed will affect the size of the time step, and thus both the speed and the accuracy of the *N*-body simulation.
	+ By default, the maximum allowed simulation speed is automatically set by Universe Sandbox based on performance. The way this maximum simulation speed is calculated can be adjusted via the Tuning Profile and Limit Multiplier settings in the Sim Settings Menu. The object in the simulation that is primarily responsible for limiting the simulation speed is also listed in the Sim Settings Menu. Simulation speed limiting can also be turned off via the Auto Limit Simulation Speed toggle in the Sim Settings Menu.
	+ See Home > Guides > Tutorials > Basic & Advanced Simulation Speed Controls for more details

* The simulation's Gravitational Constant will affect the strength of gravity in that simulation

* The type of *N*-body integrator used by Universe Sandbox (see Models below) can be changed in the Sim Settings Menu.

* The number of substeps used at any point in the simulation is displayed in the Advanced section of the Sim Setting Menu.

* A new, experimental tree algorithm for increasing the speed of the Universe Sandbox gravity simulation can be turned on in the Advanced section of the Sim Settings Menu.

## Models

### Integrators

Universe Sandbox provides a number of different types of *N*-body integrator. Each integrator has its own strengths and weaknesses, and different integrators will work better for different simulations.

The available integrators include:

* Euler Explicit
* Euler Semi-Implicit
* Velocity Verlet
* RK2
* Forest-Ruth
* PEFRL

### Substepping

Within each time step, Universe Sandbox will use the *N*-body integrator to calculate object motions during smaller substeps, to improve the accuracy of the simulation. Universe Sandbox automatically calculates the size of these substeps to balance performance and accuracy.

## Limitations

Errors are impossible to avoid in *N*-body simulation. There must be compromises made when it comes to accuracy, as there are limitations defined by computational power. This is true even for *N*-body simulations that are run by researchers, where the integration may take days and the output is in numerical data, not detailed graphics. Universe Sandbox is subject to even more constraints than research-level gravity simulators, as it displays a graphical representation of the simulation as it runs, and it runs on consumer-grade hardware rather than research-grade supercomputers.

### Time Step

The main source of error in an *N*-body simulation is the size of the simulation time step. Smaller time steps can more accurately simulate reality (in which time is continuous, rather than made up of discrete steps), but smaller time steps negatively affect performance. Universe Sandbox addresses this trade-off in accuracy vs. performance in several ways.

First, the user can adjust the simulation speed, and thus the time step, of a simulation using the controls on the bottom bar. This allows the user to decide whether to prioritize accuracy or performance for any given simulation.

Second, the maximum allowed simulation speed is limited by Universe Sandbox (unless the user turns off this option; see Settings above).

Third, Universe Sandbox using sub-stepping to increase the accuracy of the *N*-body integrator.

### Point Masses

In reality, every particle that makes up a planet, moon, or star has mass and will exert a gravitational force on other particles. However, in an *N*-body simulation, the number of objects in the simulation will have a significant negative effect on the performance of the simulation, so simulating every individual particle is unfeasible. Instead, Universe Sandbox's gravity model simulates each object as a point mass: a single point in space with all of the object's mass condensed into that point. This means that additional models are required to simulate effects related to the 3D size and shape of objects, like fragmenting collisions or tidal heating.

### Non-Attracting Objects

Because the number of objects simulated by an *N*-body integrator is related to the performance of the integrator, Universe Sandbox improves the performance of the simulation by ignoring the gravitational effects of certain low-mass objects, such as fragments or volatiles. These non-attracting objects may still be affected by the gravity of other objects, but they do not exert a gravitational force, and therefore do not slow the *N*-body simulation.

Galaxies in Universe Sandbox use non-attracting galaxy nebublae objects to approximate the structure and motion of real galaxies. See Galaxy Structure for more details about this approximation and its limitations.

### Relativity

*N*-body simulation in Universe Sandbox is simulated according to classical mechanics. This means that it does not account for general relativity. This is largely due to computational limitations; simulating general relativity is incredibly complex and usually requires supercomputers. It is, however, often not necessary; using classical mechanics is extremely accurate for most simulations.

There are a few limitations that the Universe Sandbox team would like to address in the future by implementing effects related to relativity, such as the speed of gravity and spinning black holes. THE FONTTT