Coordinates, signs and units¶
Coordinate conventions¶
All positions are Cartesian, in meters, float64. Source and target
dataclasses store coordinates as a strict (N, 3) table — a bare (3,)
array is rejected, not silently promoted to a one-row table. Only the public
observable functions accept an array-like (3,) single target and promote
it to (1, 3); the dataclasses themselves never do this promotion. See
Arrays, dtypes and axes for the general shape and dtype rules.
Separation vector and sign conventions¶
The separation vector used throughout the kernels is Δ = r'_source − r_target
(source minus target), and r = |Δ| with Plummer-softened
r_eff² = r² + ε² for softening ε ≥ 0. The three kernel sign conventions
that follow from this choice are:
- Potential:
K_Φ = −1/r_eff(scalar) — negative for a positive mass, as expected of an attractive potential well. - Acceleration:
K_a = Δ/r_eff³(vector) — points from the observation point back towards the source. - Gravity gradient:
K_T = 3ΔΔ/r_eff⁵ − I/r_eff³(tensor), where the differentiation is with respect to the observation (target) coordinate, not the source coordinate.
"""The three kernel sign conventions, pinned at one exact fixed point.
Source: 1 kg at the origin. Observation point: (1, 0, 0) m. Softening: zero.
At r = 1 m every geometric factor is exactly 0, +-1 or +-2 in IEEE-754 double
precision, so each check below is an exact equality and fails on a sign error
of any magnitude -- which a default-tolerance comparison would not, because
NumPy's default atol of 1e-8 is larger than the entire quantity being tested.
"""
import numpy as np
from gragra import (
G_SI,
PointMass,
point_acceleration,
point_gravity_gradient,
point_potential,
)
source = PointMass(mass_kg=1.0, position_m=[0.0, 0.0, 0.0])
target = [[1.0, 0.0, 0.0]]
# K_Phi = -1 / r_eff, so the potential of a positive mass is negative.
potential_j_kg = point_potential(source, target)
assert potential_j_kg.shape == (1,)
assert potential_j_kg[0] == -G_SI
# K_a = Delta / r_eff**3 with Delta = r_source - r_target, so the acceleration
# points from the observation point towards the source: along -x here.
acceleration_m_s2 = point_acceleration(source, target)
assert acceleration_m_s2[0, 0] == -G_SI
assert (acceleration_m_s2[0, 1:] == 0.0).all()
# K_T = 3 Delta Delta / r_eff**5 - I / r_eff**3, differentiated with respect
# to the *observation* coordinate. On the separation axis it is diag(2, -1, -1)
# and the tensor axes are the two trailing ones.
gradient_s2 = point_gravity_gradient(source, target, softening_m=0.0)
assert gradient_s2.shape == (1, 3, 3)
assert (gradient_s2[0] == G_SI * np.diag([2.0, -1.0, -1.0])).all()
# With zero softening the tensor is trace-free exactly, not approximately.
assert np.trace(gradient_s2[0]) == 0.0
Units¶
SI throughout: meters for length, kilograms for mass, seconds for time (where time appears at all — see What gragra computes for why it usually doesn't). Potential is in J/kg, acceleration in m/s², gravity gradient in s⁻². Angular quantities (wavenumber, phase) are in radians and rad/m, never degrees or cycles.
The gravitational constant¶
G_SI is the CODATA gravitational constant, 6.67430 × 10⁻¹¹ m³ kg⁻¹ s⁻².
It is a fixed literal, not a fitted or configurable value — there is no way
to run gragra with a different value of G.
G_SI¶
Status & verification
| Status | Stable |
| Source | CODATA recommended value, 6.67430e-11, hard-coded in gragra.constants and re-exported as gragra.G_SI. Not applicable — a physical constant has no oracle to verify it against beyond the value itself |