MCPcopy Index your code
hub / github.com/RustPython/RustPython / report_energy

Function report_energy

benches/benchmarks/nbody.py:75–83  ·  view source on GitHub ↗
(bodies=SYSTEM, pairs=PAIRS, e=0.0)

Source from the content-addressed store, hash-verified

73
74
75def report_energy(bodies=SYSTEM, pairs=PAIRS, e=0.0):
76 for (((x1, y1, z1), v1, m1),
77 ((x2, y2, z2), v2, m2)) in pairs:
78 dx = x1 - x2
79 dy = y1 - y2
80 dz = z1 - z2
81 e -= (m1 * m2) / ((dx * dx + dy * dy + dz * dz) ** 0.5)
82 for (r, [vx, vy, vz], m) in bodies:
83 e += m * (vx * vx + vy * vy + vz * vz) / 2.
84
85
86def offset_momentum(ref, bodies=SYSTEM, px=0.0, py=0.0, pz=0.0):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected