N-Body Simulation using symplectic integrators

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
< Ali >
Messages
10
Reaction score
0
TL;DR
Need help on algorithm clarification
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:
[CODE lang="python" highlight="9"]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[/CODE]

What are the mag and b1m variables? would be very thankful for any explanations or resources that derives this algorithm.
 
Physics news on Phys.org
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}}$$