N-Body Simulation using symplectic integrators

10
0

Summary:

Need help on algorithm clarification

Main Question or Discussion Point

Hi,
I hope I am in the right section of the forum. I was trying to understand the following algorithm:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-python3-1.html
and particulary this part:
Python:
def advance(dt, n, bodies=SYSTEM, pairs=PAIRS):

    for i in range(n):
        for (([x1, y1, z1], v1, m1),
             ([x2, y2, z2], v2, m2)) in pairs:
            dx = x1 - x2
            dy = y1 - y2
            dz = z1 - z2
            mag = dt * ((dx * dx + dy * dy + dz * dz) ** (-1.5))
            b1m = m1 * mag
            b2m = m2 * mag
            v1[0] -= dx * b2m
            v1[1] -= dy * b2m
            v1[2] -= dz * b2m
            v2[0] += dx * b1m
            v2[1] += dy * b1m
            v2[2] += dz * b1m
        for (r, [vx, vy, vz], m) in bodies:
            r[0] += dt * vx
            r[1] += dt * vy
            r[2] += dt * vz
What are the mag and b1m variables? would be very thankful for any explanations or resources that derives this algorithm.
 

Answers and Replies

Ibix
Science Advisor
Insights Author
5,492
3,946
Can you write it out as a formula? It may be better to go straight to the change in ##v_x##.

Hint: $$\cos\theta=\frac{\Delta x}{\sqrt{\Delta x^2+\Delta y^2+\Delta z^2}}$$
 
10
0
Got it :) Thank you!!
 

Related Threads for: N-Body Simulation using symplectic integrators

Replies
2
Views
560
Replies
8
Views
566
Replies
4
Views
326
Replies
4
Views
1K
  • Last Post
Replies
1
Views
634
Replies
0
Views
1K
Replies
4
Views
4K
Top