News for hackers. Stuff that matters.
Re:5 Steps to N-Body Simulation by JKCalhoun on Monday May 12, 2025 @09:36PM (#43968985)
Decades ago ... I think it was Computer Recreations column in "Scientific American" ... the strategy, since computers were less-abled then, was to advance all the bodies by some amount of time — call it a "tick" — when bodies got close, the "tick" got smaller: therefore the calculations more nuanced, precise. Further apart and you could run the solar system on generalities.
Re:5 Steps to N-Body Simulation by leumassuehtam on Monday May 12, 2025 @10:41PM (#43969261)
One way of doing that is by each time step delta perform two integrations, one which give you x_1, and another x_2, with different accuracies. The error is estimated by the difference |x_1 - x_2| and you make the error match your tolerance by adjusting the time step.

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.

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?

Re:5 Steps to N-Body Simulation by markstock on Tuesday May 13, 2025 @09:22AM (#43972658)
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.

Re:5 Steps to N-Body Simulation by markstock on Tuesday May 13, 2025 @03:20PM (#43976587)
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.
Re:5 Steps to N-Body Simulation by mkoubaa on Tuesday May 13, 2025 @04:01PM (#43977064)
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.

Re:5 Steps to N-Body Simulation by halfcat on Monday May 12, 2025 @10:13PM (#43969146)
So in this kind of simulation, as we look closer, uncertainty is reduced.

But in our simulation (reality, or whatever), uncertainty increases the closer we look.

Does that suggest we don’t live in a simulation? Or is “looking closer increases uncertainty” something that would emerge from a nested simulation?

Re:5 Steps to N-Body Simulation by quantadev on Tuesday May 13, 2025 @12:21AM (#43969629)
The reason uncertainty goes up the closer we try to observe something in physics, is because everything is ultimately waves of specific wavelengths. So if you try to "zoom in" on one of the 'humps' of a sine wave, for example you don't see anything but a line that gets straighter and straighter, which is basically a loss of information. This is what Heisenberg Principle is about. Not the "Say my Name" one, the other one. hahaha.

And yes that's a dramatic over-simplification of uncertainty principle, but it conveys the concept perfectly.

Re:5 Steps to N-Body Simulation by sampo on Tuesday May 13, 2025 @03:37AM (#43970483)
Adaptive time step RKF algorithm is explained in section 5:

https://alvinng4.github.io/grav_sim/5_steps_to_n_body_simula...

Re:5 Steps to N-Body Simulation by kbelder on Tuesday May 13, 2025 @11:27AM (#43973995)
Cut the time interval shorter and shorter, and then BAM you've independently discovered calculus.
Re:5 Steps to N-Body Simulation by mkoubaa on Tuesday May 13, 2025 @05:26PM (#43977906)
You need to invent calculus to get partial differential equations. You need invent PDEs to get approximate solutions to PDEs. You need to invent approximate solutions to PDEs to get computational methods. You need to invent computational methods to explore time integration techniques.