N-Body Simulation using symplectic integrators

Click For Summary
SUMMARY

The discussion focuses on the N-Body Simulation algorithm implemented in Python, specifically the function advance(dt, n, bodies=SYSTEM, pairs=PAIRS). Key variables include mag, which represents the gravitational influence based on the distance between bodies, and b1m and b2m, which are the adjusted mass contributions affecting the velocities of the bodies. The user seeks clarification on these variables and requests a formulaic representation of the algorithm's mechanics.

PREREQUISITES
  • Understanding of symplectic integrators in computational physics
  • Familiarity with Python programming, particularly data structures
  • Knowledge of gravitational physics and Newton's laws of motion
  • Basic understanding of numerical methods for simulations
NEXT STEPS
  • Study the implementation of symplectic integrators in Python
  • Explore gravitational force calculations in N-body simulations
  • Learn about the mathematical foundations of numerical simulations
  • Review performance optimization techniques for Python simulations
USEFUL FOR

Researchers in computational physics, software developers working on simulations, and students studying N-body problems in astrophysics will benefit from this discussion.

< 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}}$$
 
Got it :) Thank you!
 

Similar threads

Replies
14
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K