Working Through the N-Body Problem in Universe Sandbox ²
What is the n-body problem?
The n-body problem can be defined as “the problem of predicting the individual motions of a group of celestial objects interacting with each other gravitationally.” Or, in a gravitational system of n bodies (where n can be any number), where will they all be after one year?
It’s helpful to frame this in contrast to the two-body problem, which looks at the motion of just two objects interacting with each other. For example, you can look at the Earth and Moon as a two-body problem. The Earth pulls on the Moon quite a bit, keeping it in orbit, and the Moon pulls on the Earth just a little bit.
The issue here is that the Moon is not affected gravitationally by just the Earth; it is also being pulled by the Sun, and Jupiter, and every other object in space. The same is true when looking at the Sun and Earth: the Sun is not the only object pulling on Earth. So to account for all of these gravitational forces, you need to use an n-body solution.
The problem of the n-body problem in Universe Sandbox ²
In Universe Sandbox ², every object is simulated as part of an n-body problem. Unfortunately, when solving for many objects, or n objects, you can’t just jump forward in time without getting massive errors. There’s simply no way around this. Solving an n-body problem requires calculating how each object affects each other object every step of the way. Errors will still happen, but taking smaller steps reduces them.
By default, the simulations in Universe Sandbox ² try to set an accuracy which prevents orbits from falling apart due to error. This means setting a maximum error tolerance for each step and also making sure the total error doesn’t reach an upper limit.
If you crank up the time step, the simulation then has to take fewer, larger steps. This means the potential for greater error. And the greater the error, the more likely it is that an orbit, which otherwise would be stable, falls apart. Moons crash into planets, Mercury gets thrown out of the solar system — things like that.
This isn’t what most people want in their simulations. But at the same time, most people also don’t want a limit on how fast they can run their simulation. This is a problem.
An imperfect solution
So how can we get around this problem? How can we accurately simulate thousands of objects while still allowing for large steps forward in time? For example, what if you wanted to simulate our solar system on a time scale of millions of years per second so that you could see the evolution of our Sun?
One solution proposed by Thomas, our physics programmer, is to allow for a special mode within simulations running at high time steps. This mode (which of course could be toggled) would collapse the existing n-body simulation into a series of 2-body problems: Moon & Earth, Earth & Sun, Europa & Jupiter, Jupiter & Sun, etc.
Solving a 2-body problem is much easier than solving an n-body problem. Not only is it faster computationally, but there is also a relatively arbitrary difference between figuring out where the two objects will be in one year and where they’ll be in a million years — it still requires just one calculation. So if you collapse an n-body simulation into a series of two-body problems, the simulation could take one big step forward, instead of taking the small steps needed for calculating it as an n-body problem.
The results won’t be entirely accurate, as this method would effectively ignore all gravitational influences outside of the main attractor. As mentioned before, calculating Earth’s orbit by looking at how it interacts with just the Sun is not accurate, as Earth is also affected by every other body. The Sun, however, is the most significant factor by far, because it is much more massive than any other object in our solar system. The other, much smaller forces tend to have little effect overall in non-chaotic systems. So while it’s not correct, it’s close enough when simulating something relatively stable like our solar system.
This isn’t a perfect solution. But we think it could be an improvement over the current system and its limitations, which leave you with the choice of either destabilizing the orbits with massive errors, or waiting days for the simulation to advance the millions of years needed for the Sun to evolve. Neither is particularly interesting.
When is this coming to Universe Sandbox ²?
Not anytime soon.
This solution is just a proposed idea right now, and is not a high priority for us, as we already have a big list of exciting features planned. But we think it is useful to understand the complexity of accurately simulating the motions of hundreds to thousands of objects interacting gravitationally.
This is especially a challenge when attempting to do this in real-time on a home computer, which is why researchers run numerical simulations on supercomputers which take days to complete. With Universe Sandbox ², we’re exploring new territory and working through problems which haven’t been solved before. And this is a big part of why we love making it.