200k views
4 votes
I am making an n-body simulation in python. There are many different methods to numerically solve the system of differential equations governing the gravitational interactions between the n particles; the challenge of n-body simulations is to find an integration scheme which is both accurate and fast.

For the moment, I am working with n small (say n≤5
). I began with the most naive method of Euler integration, which is first order. Even with two bodies, this method can produce pretty bad errors if the bodies come very close (since then the force between them becomes very large, so their accelerations become very large). Of course, one can always reduce the time-step to get more accuracy, but at the expense of computation time.

Next I would like to implement a higher order method which has better stability properties etc like leapfrog integration or Runge-Kutta.

I expect these methods to give much better results, but the problem is I am unsure how to measure quantitatively the accuracy of my simulation. What metric should I use?

One of the issues is that I can't tell if the simulation is giving realistic results, because I haven't been using the real value of the gravitational constant G and none of the distances/times/masses in my simulation have units.

The reason why I haven't been paying attention to units is because, say if I wanted to do a scale sun-earth-moon simulation; since the sun-earth distance is about 370 times the earth-moon distance, it's not possible for everything to fit inside the display window and also be able to distinguish the earth and the moon.

The other problem is using the real value of G and real masses etc leads to computations involving big numbers. But, keeping everything else fixed, choosing lower values of G reduces the errors (because the forces are then smaller). But when I reduce G, I don't know if I'm cheating by making it unrealistically small and getting good results, or if in fact my program is very accurate and it is the higher values of G
which are unrealistic. So I have no real way of telling if the simulation is accurate.

So how can I rigorously test the accuracy of the simulation, and what can I do concerning units?

User Mhdwrk
by
8.4k points

1 Answer

5 votes

Final answer:

To measure the accuracy of your n-body simulation and overcome the issue of units, you can use a method called dimensional analysis. For more realistic and manageable simulations, rescaling the units used can be employed.

Step-by-step explanation:

To measure the accuracy of your n-body simulation and overcome the issue of units, you can use a method called dimensional analysis. This involves establishing the relationships between different physical quantities by comparing their units. For example, you can analyze how the outcome of your simulation varies with changes in the time step or the number of bodies. You can also compare your results with known analytical solutions or experimental data if available.

To make your simulation more realistic and to handle larger values, you can rescale the units used in your simulation. For example, you can scale down distances and times to fit within the display window while maintaining the same relative ratios between them. By doing this, you can still accurately represent the dynamics of the system without dealing with extremely large numbers.

User Jeruki
by
8.5k points