"How can I speed up the simulation?"
Added 2024-02-27 07:00:06 +0000 UTCThis is one of the most frequent questions people ask, so I thought I'll go a little more in-depth and explain how the simulation speed works, how to control it, and most importantly, why you cannot simply set the time step to an arbitrarily large value.
What is a physical simulation anyway?
Reality is complex. Planets are made of a bajillion atoms and undergo processes lasting from a fraction of a second to billions of years. To be able to simulate planets and other objects using a computer with a finite amount of memory and processing power, it's necessary to make some approximations and discretize both the space and time of the simulation.
In SpaceSim, the space is discretized by particles, elements of mass that move and interact with each other. The time is discretized by time steps. The simulation doesn't evolve smoothly, but takes discrete steps forward in time.
The simulation roughly works as follows: it calculates all forces between particles, uses the forces to modify the particle velocities, makes a small step in the direction of the velocity vector, and then calculates the forces again, etc. If the step is small enough, we get an accurate solution that looks as smooth and continuous as real behavior of physical objects.
What happens if I set the time step to a much larger value?
The time step controls two aspects of the simulation - accuracy and stability. Larger time steps reduce the accuracy of the simulation, meaning the error caused by the discretization gets larger. This is usually not an issue unless we're doing serious scientific work where the numerical error needs to be controlled.
However, that's not the only issue. For large enough time steps, the result is going to be completely wrong. Objects can pass through each other, spontaneously explode, etc. All solvers have some stability limit and cannot run the simulation with an arbitrary time step.
You can see it even in a simple simulation of the Moon orbiting Earth. When the time step is small enough, we get close to the exact simulation - elliptic trajectory. As the time step increases, the trajectory gradually gets less accurate. At some point, the errors become so large that the orbit is no longer stable and the Moon flies out into space.
Moon orbiting Earth with various time steps. Increasing the time step leads to decreased accuracy until eventually the orbit breaks completely.

That's nice, but I want to run a simulation faster
You can't. Think of it this way. Imagine you're walking down a staircase. You can try taking one step at a time, that's a safe way to do it, but it's also quite slow. If you want to walk faster, you can try taking two steps at a time, maybe even three if you're careful. Now, try taking 500 steps at a time. No matter what you do, it's never going to work.
Physical simulation is very similar. No matter what solver you choose, there is always an upper limit to the time step. Some solvers like SPH are more restrictive, other solvers like PBD or IISPH allow you to set larger time steps, but no solver can run at unlimited speed. If you ask "can you change the solver so that I can set much larger time steps?", it's similar to asking "can you change the stairs so that I can take 500 steps at a time?". I can't and it will never be possible.
I get it, so how do I know what's the maximum time step?
That's the big question. There is no "best" time step that works in all simulations, it entirely depends on the simulation parameters. Sometimes, a time step of 1ms is too large, and sometimes a time step of 100 million years is unnecessarily small.
Some general rules:
- Time step scales with the size of the objects in the simulation. When you're simulating stars, the time step can be much larger than in the simulation of small asteroids.
- Time step depends on the relative velocities of objects. Particles should never move by more than their diameter in a single time step. It's easy to see why - if the time step was larger, two particles could simply pass through each other and the collision would never be detected.
- For an optimal time step, the particles should all have equal size. Otherwise, small particles will drag the time step down and slow down the simulation.
- Dense objects require smaller time steps to properly simulate orbits and collisions.
This is why adding a tiny dense object, such as the Crab Pulsar, into the simulation causes the time step to drop significantly.
Is there no way to optimize the simulation speed?
SpaceSim has two "lightweight" particle types - rigid and massless particles. They can be used instead of the "regular" particles to significantly speed up the simulation.
Rigid objects can be created from planets, stars and shaped objects by unchecking the 'deformable' box in the object properties. This will replace the whole object with one big particle, which can repel or absorb other particles but cannot get deformed or disintegrated. This is especially useful if the object only attracts other particles gravitationally, but does not get close enough to get deformed or collide.
Massless particles are for rings, comet tails, etc. As the name suggests, they have no mass. They are still gravitationally attracted by other "real" particles and rigid objects, but they don't attract nor do they collide with other massless particles. If you make a planet rigid and add a massless ring around it, you can easily run a simulation with a million (massless) particles in real-time.
Other than changing the particle type, you can optimize the simulation by changing the object parameters using the rules above. This is often done in the simulation presets in SpaceSim, objects are sometimes larger or more massive than they should be. Although this makes the simulation less realistic, it's possible to run it with a much larger simulation speed.
Comments
but my thing is going 0s not moving time at all
riley c
2025-05-06 09:25:57 +0000 UTCpapa me want gas fragment effect
alam
2024-05-22 21:35:01 +0000 UTC