Runge-Kutta for gravitational N-Body simulation - prediction of acceleration

In summary, the conversation discusses the implementation of a 4th order Runge-Kutta method for simulating a system of N gravitationally interacting objects. The technique involves converting the second-order equation into two first-order equations and calculating the values of k1 for each particle. The conversation also touches on the concept of using RK techniques for adjusting the time step and the limitations of these techniques in taking into account the geometry of the problem.
  • #1
rph
4
0
Runge-Kutta for gravitational N-Body simulation - "prediction" of acceleration

Hey!
I'm Raph, as you can see this is my first post, so, thus I'll start saying that it's nice to be here ;).

I've got the following question:
I'm simulating a system of N gravitationally interacting objects, and I implemented a 4th order Runge-Kutta method for the numerical integration. For example, the first two of the four slopes needed to determine the velocity are something like:
[tex]
k_{v,1} = a (t , r)
[/tex]
[tex]
k_{v,2} = a (t+0.5\Delta t , r + 0.5 \Delta t k_{v,1} )
[/tex]
where "a" denotes the acceleration, "\Delta t" is the step size and "r" the position vector.
Of course I intend "a" to be the total acceleration on the object I'm considering, calculated by summing up all the accelerations due to the other objcets.

Finding
[tex]
a ( r + 0.5 \Delta t k_{v,1} )
[/tex]
would be really easy, as I just would have to move the object with position "r".
But to find
[tex]
a (t+0.5\Delta t , r + 0.5 \Delta t k_{v,1} )
[/tex]
I have to "predict" the positions of the other objects at time "t+0.5\Delta t".

What is the most common way to do so? I could simply do an Euler-Step of 0.5 \Delta t, but then the position of the object in consideration would differ from
[tex]
r + 0.5 \Delta t k_{v,1}
[/tex]
as requested by RK4. What do I do wrong? What didn't I understand right?

(Some more pieces of information: For the restricted three-body-problem that "prediction" was trivial, as the acceleration "a" was an easy function of "t" as the positions of the other objects could be predicted independently from the third object's position.

What is confusing me most is that "he": http://spiff.rit.edu/richmond/nbody/OrbitRungeKutta4.pdf doesn't even write the time-dependence of the acceleration in his equations for the slope-calculation... )

Would be great to find some help!
Raph
 
Technology news on Phys.org
  • #2


I think you are getting confused trying to solve a second-order equation directly with R-K and trying to figure out what the "prediction" fornulas should be.

You need to convert the second-order equation to two first-order equations, and then think of the displacement and velocity as two independent variables. In your PDF reference, that is equations (7) and (8).

That means you are solving the equation "velocity = dx/dt" numerically, not treating it as an exact mathematical formula. The numerical values of the velocity and displacement will not be perfectly consistent with each other, but don't worry about that, it is just a conseqence of the fact that the numerical solution will never be the "exact" solution of the differential equation.
 
  • #3


Thank you for your reply, AlephZero!

I hope I got you right but of course, I converted the 2nd order diff. eq. into two 1st order diff eq. :-)

The part I don't understand is the following:
The acceleration a is function of the time -- as the objects of the system are in motion.
To compute
[tex]
a(t+0.5 \Delta t, r + 0.5 \Delta t k_1)
[/tex]
I thus have to do more than just shifting the object of consideration to position
[tex]
0.5 \Delta t k_1
[/tex]
but I also have to predict the other objects' positions at time
[tex]
t+0.5 \Delta t
[/tex]

How is this usually done? I think treating the problem as done in the PDF I cited would be right for static systems of masses, but not for dynamic systems.

Or I am totally confused and on the wrong track? :D
 
  • #4


You do each step of the R-K algorithm for all the particles. You don't try to do all 4 steps for the first particle, then all 4 steps for the second one, etc.

So, you start by calculating (and storing) the value of k1 for each particle.
Then you predict (and store) the position of all the particles as ##y_i + (h/2) k_{1i}##
Then you calculate all the values of k2 assuming those particle positions, and so on.

The notation above is a bit scrappy, because you actually calculate 2n values of k1 for the n particles, n for the displacements and n for the velocities. But I hope you get the idea.
 
  • #5


Excellent, thank you very much! That's actually what I implemented :D
-- but it felt kind of wrong, as in the textbooks I studied the four slopes are always given at once, and I thought there would have to be another "trick" to predicht the other object's state.
Well, thank you again!
 
  • #6


Well, you can only draw pictures of the slopes for a problem with 1 degree of freedom, and your question doesn't arise in that case.

I agree this stuff can be confusing, especially if you think too hard about what is the "right" way to do it. Really, RK is just a nice computational way of creating several terms of a Taylor series, without the need to differenate the differential equation several times to get explicit formulas for the higher derivatives.

It's a bit misleading to think of the values used in the intermediate steps as "approximate solutions" of the DE. They are just a recipe for finding the end-poiint of the step, consistent with Taylor series expansions of all the functions involved in the DE. Unlike some other methods, RK doesn't have any concept of the succesive k values "coverging" to the "best" solution.
 
  • #7


AlephZero said:
Unlike some other methods, RK doesn't have any concept of the succesive k values "coverging" to the "best" solution.
Yes and no. There are extensions to the basic RK technique such as the widely implemented adaptive Runge-Kutta-Fehlberg 4/5 that do have this concept. Basically, with a clever arrange of the Butcher tableau one gets both an RK5 and and RK4 solution that can be used to adjust the time step to what is supposedly the optimal value.
One problem with Runge Kutta techniques is also one of their strengths: They are general purpose. In the problem at hand, the technique doesn't "know" that this six dimensional first order differential equation is in fact a three dimensional second order DE that necessarily conserves energy, linear momentum, and angular momentum. RK techniques don't take into account the geometry of the problem. They can't; RK integrators are a general purpose solution to the problem of numerically solving first order differential equations of all sorts.

Techniques that do account for the geometry (geometric integrators) can fare better than will general purpose techniques. They are also inherently special purpose. (Note however than JPL does quite nicely with its planetary ephemerides using what is essentially Adams Bashforth Moulton, another family of general purpose integrators.)

One last point on this: I've found that using fourth order Adams Bashforth as a predictor and a third order Adams Moulton as a single corrector (no iteration) has about the same accuracy as RK4 for the N-body problem, but at only half the computational burden of RK4.
 
Last edited:
  • #8


Thank you again for your input. I'll try out Runga-Kutta-Fehlberg.
Can you recommend me a textbook I could look up in our library covering numerical methods applied to physical problems in general, or, if no such book exists you enjoyed reading, a textbook about methods for numerical integration?
Thx, Rph
 
  • #9


Adaptive step size Runge Kutta Fehlberg is a bear to implement. Matlab's ode45, for example, has some problems getting the step size right -- and that's code written by people who know what they're doing. There is little point to using one of the Runge Kutta Fehlberg methods without making the step size adaptive.

As far as books go, some numerical methods texts have chapters on numerical solutions of ODEs. I've got two really old ones, and can't really recommend either.There's also the Numerical Recipes family of books by Press et al. This is an okay starting point for lots of numerical programming techniques. Keep in mind that it is a starting point. The algorithms are frequently overly elementary, oftentimes out of date, sometimes flawed, and the code is essentially Fortran 77, despite the language on the cover. Despite my criticism, I still turn to my old and battered Numerical Recipes on occasion.

The chapter in Numerical Recipes on ODE initial value problems covers a couple of the Runge Kutta techniques, including standard RK4 and a full section on the RK Fehlberg techniques. The book (in my opinion) puts way too much emphasis on Bulirsch–Stoer. That technique is nowhere near as accurate, fast, or stable as the authors like to think it is. The book downplays predictor corrector methods, which are still in widespread use.

Missing from the book: Low order techniques such as Verlet and its variants (this is a big sin, IMHO), high order techniques (although those are admittedly specialized), variation of parameters, transform techniques, and no mention at all of symplectic or geometric integration (this is another sin). Do a very large N-body simulation and you have no choice but to use a low order technique. You'll still want that simulation to obey some basic laws of physics such as conservation of energy. That means you'll want something like symplectic Euler or velocity Verlet.One last point: Since geometric integration has been around for about ten years, books are starting to come out on the topic. (Use google books.) However, unless you know what manifolds are, the math will get over your head right quick.
 

1. What is the Runge-Kutta method for gravitational N-Body simulation?

The Runge-Kutta method is a numerical integration technique used to solve ordinary differential equations, such as those governing the motion of N celestial bodies under the influence of gravity. It involves breaking the problem down into smaller steps, calculating the acceleration of each body at each step, and using this information to predict their positions and velocities at the next step.

2. How does Runge-Kutta improve upon other methods for N-Body simulation?

Runge-Kutta is a more accurate method than simple Euler integration, as it takes into account the changing acceleration of the bodies at each step. It also allows for a larger time step, making it more efficient for simulating systems with a large number of bodies.

3. What factors affect the accuracy of Runge-Kutta simulations?

The accuracy of Runge-Kutta simulations can be affected by the time step size, the number of steps taken, and the order of the method. A higher order method will generally produce more accurate results, but at the cost of computational efficiency.

4. Can Runge-Kutta be used for simulations with a varying number of bodies?

Yes, Runge-Kutta can be used for simulations with a varying number of bodies. The method can be adapted to account for the changing number of bodies at each step by adjusting the equations used to calculate acceleration.

5. Are there any limitations to using Runge-Kutta for gravitational N-Body simulation?

One limitation of Runge-Kutta is that it assumes a constant gravitational field, which may not be the case in certain scenarios, such as near a black hole. It also does not take into account relativistic effects, which may be important for very massive and fast-moving bodies.

Similar threads

  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
14
Views
4K
  • Programming and Computer Science
Replies
10
Views
12K
  • Classical Physics
Replies
2
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top