N-body RK4 solver: energy conservation and 2-body orbits

  • Level: Graduate 
  • Thread starter DivergentSpectrum
  • Start date
  • Tags Tags
    Body
2 replies · 2K views · last reply
DivergentSpectrum
Messages
149
Reaction score
15
the force field trajectory calculator worked pretty good, so i decided to step it up and solve the famous n body problem.

i used rk4 to solve it, and to verify my solution i calculate the work done on each particle and the kinetic energy of each particle at the beginning and end.
it appears to converge pretty nicely when one object is very massive compared to the other, but i notice some strange behavior otherwise. for one, i always thought a 2 body system would be two elipses sharing a focus (barycenter), but instead i get all kinds of different shapes.
also the energy diverges in more "dynamic" systems.
How does one calculate the "total conserved energy" of a system? (or analogous conserved quantities such as angular momentum) i had been just using the work energy theorem, (line integral of force equals change in kinetic energy) but I am not sure if that still holds when the force depends on the location of an object, that is also experiencing a force due to the same object.
do these pictures qualitatively look like a 2 body system?

edit: in each of these the blue particles initial velocity is 0, and the black particles initial velocity is non zero. the step size is the same, but the mass of the black particle is different. the more "chaotic" looking patterns have a larger mass set for the black particle(up to where the masses are equal)
 
Attachments
  • 3D render of a two-body orbit: a dense black spiral of closely spaced looping paths in a tilted ellipse-like shape, with a small blue particle near its lower-left edge and a green surface in the lower right. Text lists work and kinetic energy values for two particles.
    pic1.jpg
    29.6 KB · Views: 485
  • Screenshot of a 3D simulation window showing a black elliptical orbit-like path and a green tapered spike-shaped object, with blue text listing work done and kinetic energy values for two particles.
    converges.jpg
    20.3 KB · Views: 504
  • Screenshot of a 3D simulation window showing a black looping particle trajectory forming a helix-like coil around a green rod, with small blue loops along its path and text readouts of work and kinetic energy values.
    diverges.jpg
    34.9 KB · Views: 472
  • Screenshot of a 3D simulation showing a black particle and a blue particle each tracing a looping, spiral-like trajectory around a vertical blue axis, with a green and red axis at the base; text on the right lists work done and kinetic energy values for p0 and p1.
    equalmass.jpg
    19.7 KB · Views: 488
Last edited:
bluntwcrackrap said:
edit: in each of these the blue particles initial velocity is 0, and the black particles initial velocity is non zero. the step size is the same, but the mass of the black particle is different. the more "chaotic" looking patterns have a larger mass set for the black particle(up to where the masses are equal)

If the total initial momentum isn't zero, the center of mass will keep moving, and you get spirals instead of ellipses. You'll need to set [itex]v_1 = - \frac {m_2 }{m_1} v_2[/itex] with 2 bodies to get a momentum of 0.
 
  • Like
Likes   Reactions: 1 person
thanks, i had a feeling the system as a whole might be undergoing some kind of translational motion. as far as the divergences go i might just be expecting too much from a numerical method.
 
Attachments
  • Screenshot of a 3D DisplayWindow simulation showing a black ellipse and a smaller blue ellipse with red, green and blue coordinate axes, plus text listing work done, ke gained, and AM gained values.
    Untitled.jpg
    22.8 KB · Views: 463