Re:5 Steps to N-Body Simulation
by hermitcrab on Tuesday May 13, 2025 @05:59AM
(#43971298)
I have run into the problem where a constant time step can suddenly result in bodies getting flung out of the simulation because they go very close.
Your solution sounds interesting, but isn't it only practical when you have a small number of bodies?
Yes, the author uses a globally-adaptive time stepper, which is only efficient for very small N. There are adaptive time step methods that are local, and those are used for large systems.
If you see bodies flung out after close passes, three solutions are available: reduce the time step, use a higher order time integrator, and (the most common method) add regularization. Regularization (often called "softening") removes the singularity by adding a constant to the squared distance. So 1 over zero becomes one over a small-ish and finite number.
Re:5 Steps to N-Body Simulation
by hermitcrab on Tuesday May 13, 2025 @02:33PM
(#43976141)
>Regularization (often called "softening") removes the singularity by adding a constant to the squared distance. So 1 over zero becomes one over a small-ish and finite number.
IIRC that is what I did in the end. It is fudge, but it works.
It is a fudge if you really are trying to simulate true point masses. Mathematically, it's solving for the force between fuzzy blobs of mass.
You are never simulating pure anything. All computational models are wrong. Some are useful
Re:5 Steps to N-Body Simulation
by HelloNurse on Wednesday May 14, 2025 @03:38AM
(#43981914)
The suggested method of trying two time steps and comparing the accelerations does about twice as many calculations per simulation step, which don't require twice the time thanks to coherent memory access: a reasonable price to pay to ensure that every time step is small enough.
Optimistic fixed time steps are just going to work well almost always and almost everywhere, accumulating errors behind your back at every episode of close approach.
Naturally, this difference becomes big when two objects are close together, since the acceleration will induce a large change of velocity, and a lower time step is needed to keep the error under control.