# N-body problem simulation and relativity

alyx_vance
Do you happen to know about any resources on the gravitational N-body problem and general relativity? Ideally some open-source implementations or pseudo code.
I'm doing a N-body simulator for my bachelor's thesis and my advisor was wondering if I could add some algorithms that take general relativity into consideration. I am not required to really understand the algorithm, just somehow implement it...

I try to understand and implement classical algorithms myself, but this seems
out of reach for me. My math and physics background is too weak.

Last edited:

zhermes
what type of N-body situations are you looking at?
Most likely the only GR you might want to consider is correcting your (presumably) instantaneous action of the gravitational force. I.e. replace it with a force conveyed at the speed of light.

espen180
Staff Emeritus
what type of N-body situations are you looking at?
Most likely the only GR you might want to consider is correcting your (presumably) instantaneous action of the gravitational force. I.e. replace it with a force conveyed at the speed of light.
Bad idea. That will inevitably lead to a much worse result than just using Newtonian gravity. What is needed is some kind of post-Newtonian methodology, preferably in a fairly simple form. IERS Technical Note 36 (see post #2) does just that.

zhermes
Bad idea. That will inevitably lead to a much worse result than just using Newtonian gravity. What is needed is some kind of post-Newtonian methodology, preferably in a fairly simple form. IERS Technical Note 36 (see post #2) does just that.
Could you elaborate a little; I implemented the above many years ago in a solar system dynamics class---it preserved accuracy as measured by energy and momentum conservation while accurately generating the precession of orbits.

Could you elaborate a little; I implemented the above many years ago in a solar system dynamics class---it preserved accuracy as measured by energy and momentum conservation while accurately generating the precession of orbits.

The thing you need to watch for, which you may have done, is that if you want to add light delay to action at a distance, you also need to add velocity (similar to EM) and acceleration dependent terms (unique to gravity). If you don't, you will get worse results than instant action at a distance. See, for example:

http://arxiv.org/abs/gr-qc/9909087

zhermes
if you want to add light delay to action at a distance, you also need to add velocity (similar to EM) and acceleration dependent terms (unique to gravity). If you don't, you will get worse results than instant action at a distance.
Hmmm, interesting. Thanks!

alyx_vance
what type of N-body situations are you looking at?
Most likely the only GR you might want to consider is correcting your (presumably) instantaneous action of the gravitational force. I.e. replace it with a force conveyed at the speed of light.
I'm mostly considering smaller systems, like the Solar system. I was wondering how much different results would the added relativity produce in some cases, like in the orbit of Mercury and such. I could also try to simulate some star cluster, although I'm not really required to do that.
How would the algorithm look like? Now it's like this (a simple euler for example):
http://pastebin.com/dhxzKMBK"

Just a quick note for now. See http://www.iers.org/nn_11216/IERS/EN/Publications/TechnicalNotes/tn36.html,
particularly chapters 10 and 11.
Thanks, I'll look at it.

Last edited by a moderator:
Staff Emeritus
How would the algorithm look like? Now it's like this (a simple euler for example):
http://pastebin.com/dhxzKMBK"
A post-Newtonian expansion such as the one in post #2 just adds some more terms to the acceleration equation. (Note: Your code is mistakenly calling that term a force; it is an acceleration, and you are using it as such.)

Your integration algorithm is the semi-implicit Euler method, aka symplectic Euler, a step above basic Euler. It conserves energy (kind of) but the errors are still immense. You could incorporate relativistic effects into your semi-implicit Euler scheme, but to what avail? The errors induced by using semi-implicit Euler are orders and orders of magnitude higher than the errors induced by ignoring relativistic effects.

For an easy next step in symplectic techniques you might want to look into the leapfrog algorithm or velocity verlet integration. Much greater accuracy is possible for solar system models by taking advantage of the fact that the planets and the central star more or less follow elliptical paths. Some approaches:
• Cowell's method. This is an old but well-used scheme. The equations of motion are specified and integrated in Cartesian space, but using an integrator a bit better than your semi-implicit Euler technique. Cowell's method uses a 12th order Gauss-Jackson integrator.
• Enke-style integrator. The idea is to model the path as a perturbation of a Keplerian orbit. Occasionally you will need to recompute the orbit because the deviation from the nominal path has become too large. An old paper: http://adsabs.harvard.edu/full/1966AJ.....71..579K
• Variation of parameters. The basic idea here is to represent state as some kind of orbital elements. With the standard Keplerian orbital elements one use the Lagrange Planetary Equations as the equations of motion. There are other choices for orbital elements, e.g. Delaunay elements leads to the Delaunay Planetary Equations. A few references:
http://lightsey.ae.utexas.edu/publications/cm1project-gaylor.pdf [Broken]
• Kustaanheimo-Stiefel transform. The KS transform turns a bound Keplerian orbit into a harmonic oscillator. A reference:
http://arxiv.org/pdf/0803.4441

Since you are doing a senior-level project you may not need to use one of these more advanced techniques, but it certainly is worthwhile to know about them.

Last edited by a moderator:
alyx_vance
Your integration algorithm is the semi-implicit Euler method, aka symplectic Euler, a step above basic Euler. It conserves energy (kind of) but the errors are still immense. You could incorporate relativistic effects into your semi-implicit Euler scheme, but to what avail? The errors induced by using semi-implicit Euler are orders and orders of magnitude higher than the errors induced by ignoring relativistic effects.

I know Euler is extremely inprecise, I'll definitely implement other algorithms. I mentioned it so you could maybe add som pseude code like "somehow_compute_gravity_force_with_lag()" into line 3, for example, so I would get the basic idea...

Thanks for the resources, I'll try to look at them. Staff Emeritus
Also note that I gave you a whole bunch of specific terms that you can google or conduct a literature search on.

jaiii
Can you send me this asimulator as PM or attachment pleasse.

Thank.

I found a program which does consider those relativistic correction terms at http://eod.github.com/JGravSim . It's very slow, but you can see the mercury doing nice moves around the sun.

EDIT: Oh, sorry. I realized too late that the thread is very very old :(

Polakm
Thank you,