Graduate N-Body Simulation using symplectic integrators

Click For Summary
The discussion focuses on understanding the n-body simulation algorithm, particularly the variables 'mag' and 'b1m' in the advance function. 'Mag' represents the gravitational influence based on the distance between two bodies, calculated using the inverse square law, while 'b1m' scales this influence by the mass of the first body. The user seeks clarification on these variables and requests a formulaic representation of the algorithm. A hint involving the cosine of the angle between bodies is provided to aid in understanding the calculations. Overall, the conversation aims to clarify the physics behind the algorithm's implementation.
< 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!
 
Thread 'What is the pressure of trapped air inside this tube?'
As you can see from the picture, i have an uneven U-shaped tube, sealed at the short end. I fill the tube with water and i seal it. So the short side is filled with water and the long side ends up containg water and trapped air. Now the tube is sealed on both sides and i turn it in such a way that the traped air moves at the short side. Are my claims about pressure in senarios A & B correct? What is the pressure for all points in senario C? (My question is basically coming from watching...

Similar threads

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