# Help building an n-body simulation incorporating the speed of gravity

1. Mar 19, 2014

### nearc

I would like some introductory level references for building an n-body gravity simulation. I work for the supercomputer challenge [ http://challenge.nm.org/ ] and I build the teaching models each year we use to train teachers in computer modeling and provide as an example model for the students during the year. We have done n-body a few times in the past with all levels of the challenge, however, they were particle-particle but I would like to build a n-body that incorporates the speed of gravity and if possible uses a discretized domain. I started looking at mesh n-body simulations, but I’ve only found high level information thus far. I wonder if this is the best approach and if so how can I find some more introductory level information because eventually I would like to find a way to bring it down to our student’s level [high school]. I would like to get knee deep in the
understanding and building of this type of simulation so I imagine it will
require the use of C for power and parallelization, however, our lower level
students will be using netlogo [ http://ccl.northwestern.edu/netlogo/ ]. I would like to go as far as building a galaxy, but for our high school students a single solar system will be a
good starting point but I do want to make sure the model does account for
the speed of gravity.

2. Mar 19, 2014

### Hornbein

According to Newton's theory gravity is instantaneous. It's not true, but it works remarkably well. In order to do what you like you would have to use general relativity. It would make no noticeable difference and would complicate things a great deal. It would make for a very slow simulation. Physicists avoid using general relativity. I say stick with Newton,

3. Mar 19, 2014

This seems like a really interesting project, as I have been thinking about this (not strictly simulation, but just thinking about the n-body problem with the speed of gravitational propagation built in) for a while.

Further to Hornbein's comment, I wonder whether it would be possible to simulate using Special Relativity (SR) instead of General Relativity as a simplification. I think this would work as long as the gravitational forces and velocities involved between your particles were relatively weak/slow and excluded, for example, anomalies such as black holes or particles moving with speeds a significant fraction of the speed of light or superimposed particles exerting an infinite gravitational force on each other. However, feel free to correct me if I am wrong.

On the basis of a SR model, I guess there would be several questions to ask:

1. Will the simulation be from the reference frame of an external observer (with no mass) or one of the particles?
2. Will it be a simulation with two spatial dimensions but with an inverse square law, or 3D?
3. Will you be simulating what the external observer will be observing (and therefore what he will see once the light reaches his eye) or what is actually happening (based on an assumption of instantaneous events in SR from the reference frame of the observer)?

An excellent reference text I would recommend is the first few chapters of "Understanding Einstein's Relativity". I shall look up the author and let you know. This should be understandable by undergraduate students with a knowledge of basic calculus, and motivated high school students.

4. Mar 19, 2014

### DrStupid

And with a limited speed for gravity the results are remarkably wrong. Such a simulation is a waste of time (I know what I'm talking about).

5. Mar 19, 2014

### nearc

while it may turn out to be a hideous or impossible task to bring this down to the high school level [heck it might be too hard to get down to my level ] i would like to try. as a reference point, the milky way is 100000 yr across, so the gravitation of a star on one side will take 100000 years to affect a star on the other side. meanwhile, the galaxy is rotating at ~225 km/s so the newton calculations would be off by [ 225 * 100000 * 60 * 60 * 24 * 365 ] 7.0956e+14 km. not mention other movements [i.e. small group, great attractor, etc...]. granted objects that far away from each other have greatly reduced influence on one another

Last edited: Mar 19, 2014
6. Mar 19, 2014

### D H

Staff Emeritus
Then you did it wrong.

It's easy to get this wrong. The results are going to be remarkably wrong if all one does is tack on a finite transmission speed to Newtonian gravity.

Getting it right isn't easy. A full-blown relativistic simulation that uses Einstein's field equation is going to be very difficult to construct. A parametrized post-Newtonian formalism can make the problem tractable. This means smallish masses, largish distances, and smallish velocities. Small velocities: 100 km/s is small, perhaps even 1000 km/s. A sizable fraction of the speed of light is not small. Smallish masses: The Sun's mass is "small". The supermassive black hole at the center if the galaxy is not small. Largish distances: Mercury orbits the Sun at about 200 million Scharzchild radii. That's large. The stars that come very close to the Milky Way's supermassive central black hole: Those distances are not large.

Each of the three lead groups in modeling the solar system (JPL, the Institute of Applied Astronomy at the Russian Academy of Sciences, and the Paris Observatory) use a PPN formalism in their equations of motion. Basically, pretend the universe is still Newtonian with general relativity adding small perturbations.

For detail, see http://iau-comm4.jpl.nasa.gov/XSChap8.pdf [Broken], particularly equation 8-1.

Last edited by a moderator: May 6, 2017
7. Mar 19, 2014

### Filip Larsen

Regarding spatial discretization I believe that some n-body simulation of galaxies and similar uses sparse octree decomposition called Barnes-Hut [1] that allow O(n*log(n)) time complexity instead of O(n2) per step. However, I have no idea whether or not such a simulation can be combined with a post-Newtonian or relativistic gravity model.

[1] http://en.wikipedia.org/wiki/Barnes–Hut_simulation

8. Mar 19, 2014

### DrStupid

It is well known, that Newtons law of gravity with non-instantaneous interactions (and that's what I was talking about) give wrong results - even if you do it right. Newton himself was already aware of that.

9. Mar 20, 2014

### Chalnoth

It's really quite difficult to do this right. The problem boils down to how aberration works, which makes gravity act as if it were instantaneous up to the second derivative in objects' speeds. Steve Carlip did a good write-up of how the speed of gravity works here:
http://arxiv.org/abs/gr-qc/9909087

I'm not sure that will help you to produce a real simulation, but at least it should provide some understanding of why it isn't very easy.

10. Mar 21, 2014

Further to my previous comment, I have thought a bit more, and realised that Special Relativity might not be required for a simulation with relatively small masses and low speeds, something I think that DH has also indicated in his comment above. This will result in neglible time and space dilation and other relativistic effects. Obviously, for small masses and low speeds, you will need long time horizons in the simulation to allow time for the objects to interact.

(The book I had mentioned is actually called 'Introducing Einstein's Relativity' by (Prof.) Ray d'Inverno, incidentally, although obviously a simulation not involving relativity will make this redundant.)

I was not aware of the aberration mentioned by Chalnoth, and I had assumed that we could simply assume that gravity propagates at the speed of light.

For a simulation with gravity propagating at the speed of light, even if you are not involving Special or General relativity, I think you will still need to treat gravity as a field. Therefore, each object will have its own gravitational field with a field strength defined at each point in space.

If you are simulating from the frame of reference of an 'external' massless non-interacting observer observing the rest of the "universe" in 2D, which I think will be the simplest version, the gravitational field of a point particle which is static in relation to the observer can be portrayed as a series of concentric circles based on Newton's inverse square law. The gravitational field of a particle in relative motion will be a series of changing non-concentric circles (which cannot overlap), although I guess for low speeds, this will approximate to a series of concentric circles, which may render the simulation meaningless. The net effect on another particle will be the sum of the gravitational fields of all the other particles at the location of the other particle at a particular point in time.

I'd be interested to learn whether a simulation of this nature will come up with anything interesting, such as a precession of an elliptical orbit, for example.

11. Mar 21, 2014

### D H

Staff Emeritus
That is not what I wrote. What I wrote was that "a parametrized post-Newtonian formalism can make the problem tractable. This means smallish masses, largish distances, and smallish velocities." I wrote that assuming you want to go beyond a Newtonian simulation. A PPN / linearized gravity is one way to go beyond Newton. It won't work for modeling the merger of two black holes, but it does work quite nicely for modeling solar systems, galactic clusters, and even galaxies (but what happens in the galactic core is going to be problematic).

Look at my reference again. http://iau-comm4.jpl.nasa.gov/XSChap8.pdf [Broken]. That big mess of an equation near the bottom of page 3, equation 8-1, is what JPL uses to formulate their planetary ephemerides. The Newtonian version of that equation: $$\ddot{\vec r}_i = \sum_{j\ne i} \frac {\mu_j (\vec r_j - \vec r_i)}{r_{ij}^3}$$

You don't want to go there. It will be wrong. Simply adding a lag to Newtonian gravity gives notoriously bad results.

Simplifying things perhaps too much, some of those non-Newtonian term in that weak field PPN formalism (that equation 8-1) are lag terms, others are lead terms. For small velocities and large distances, those lag and lead terms nearly cancel. In the limit, they do cancel, leaving only the Newtonian gravity terms.

You haven't indicated how big your system is -- What is the value of "N" in your N-body simulation?

Last edited by a moderator: May 6, 2017
12. Mar 21, 2014

### Chalnoth

I think he was trying to say something slightly different, D H, that it seemed unlikely that you could deal with a finite propagation speed without modeling how the field actually propagates.

And it does turn out that there have been simulations developed precisely for modeling the gravitational field for General Relativity in great detail. I'm having a hard time finding the actual work from a cursory search, but this is a light overview:
http://worldsciencefestival.com/videos/when_black_holes_collide [Broken]

This won't help the OP, though, because I'm sure the computational requirements are just way out of bounds for more complicated systems.

Last edited by a moderator: May 6, 2017
13. Apr 3, 2014

### nearc

i would like to start with a simplified spiral galaxy. starting with a random distribution and ending with a stable spinning spiral. the number of bodies can be small, just large enough to show the intended behavior of the system not to recreate an existing galaxy.