Energy, momentum and angular momentum at every step, with relative errors.
Combines get_energy(), get_momentum() and get_angular_momentum() into one table and adds three error columns that measure how far each quantity has moved from its starting value. An isolated system conserves all three exactly, so the errors measure the integrator, not the physics. This is the quickest check that a time step is small enough and that a method suits the problem.
Parameters
Name
Type
Description
Default
sim_data
DataFrame
The output of simulate_system(): a pandas or polars DataFrame with columns id, mass, x, y, z, vx, vy, vz and time, in SI units. Use the simulation as it came out, not a frame shifted onto a body.
required
G
float
The gravitational constant in m^3 kg^-1 s^-2. The default None uses the value recorded in the run (see run_settings()), or gravitational_constant if none is recorded.
None
softening
float
The softening length in meters, which should match the one the run used. The default None uses the value recorded in the run, or 0 if none is recorded.
None
Returns
Name
Type
Description
DataFrame
The same kind of DataFrame it was given (pandas or polars), with one row per time step, sorted by time, and these columns: • time: time in seconds. • kinetic, potential, energy: energies in joules, as in get_energy(). • px, py, pz: total linear momentum in kg m/s. • Lx, Ly, Lz: total angular momentum about the origin in kg m^2/s. • energy_error: (energy - E0) / abs(E0), where E0 is the energy at the first time step. Signed and dimensionless. • momentum_error: the length of the change in the momentum vector since the first step, divided by the sum of every body’s mass * speed at the first step. Never negative, dimensionless. • angular_momentum_error: the length of the change in the angular momentum vector since the first step, divided by the length of the angular momentum vector at the first step. Never negative, dimensionless. An error column is all NaN when the quantity it is divided by is zero or not finite.
Raises
Name
Type
Description
TypeError
If sim_data is not a pandas or polars DataFrame with the columns simulate_system() produces.
for the energy, momentum and angular momentum errors in that order.
The momentum error is scaled by the sum of the individual momenta, not by \(|\mathbf{P}_0|\), because the total momentum is often zero or close to it and would make a poor yardstick.
Run this on the simulation as it came out of simulate_system(). A frame centered on a body is not inertial, and momentum and angular momentum are not conserved in it.
Examples
One year of the Earth’s orbit with the default velocity Verlet method. The error columns are at the right.