Part 4 of 5

The software

Open-source Rust libraries built from first principles, with every result checked by an automated test.

Why tensors

“I admire the elegance of your method of computation; it must be nice to ride through these fields upon the horse of true mathematics while the like of us have to make our way laboriously on foot.”
Albert Einstein, in a letter to Tullio Levi-Civita, co-inventor of tensor calculus

The laws of physics do not depend on the coordinates used to describe them, so the mathematics that expresses them shouldn't either. Tensors have exactly this property: a tensor equation that holds in one coordinate system holds in all of them. For most problems this is a convenience. For Einstein's equations it is a necessity, because the geometry itself changes as the simulation runs, and no single fixed coordinate system can describe it.

Our library tensor-core implements tensors of general rank together with the operations of differential geometry: the metric and its inverse, raising and lowering indices, contraction, Christoffel symbols, covariant derivatives, and the Riemann, Ricci and Einstein tensors. It is tested against exact solutions such as the Schwarzschild black hole.

Derivatives

Every simulation is built on derivatives, and two different tools are used, each where it belongs.

Automatic differentiation for formulas

When a quantity is given by an exact formula, we use automatic differentiation. Any expression is broken into basic operations whose derivatives are known exactly, and the chain rule combines them. There is no approximation error, only floating-point rounding. The project began with our own automatic adjoint differentiation (AAD) library, which recorded expressions at run time. It now uses Enzyme, which differentiates compiled code inside the LLVM compiler: ordinary Rust functions on plain 64-bit numbers become differentiable at full compiled speed, with no run-time bookkeeping. The original AAD library remains available but is no longer developed.

Finite differences for grid fields

In a simulation, fields are known only at grid points, not as formulas, so spatial derivatives must be approximated from neighbouring values. We use 2nd- and 4th-order central stencils and check their accuracy with automated convergence tests: halving the grid spacing must reduce the error by the predicted factor.

Numerical methods

  • Grid: uniform 3D grid, with a 3-cell boundary zone on every face.
  • Spatial derivatives: 2nd- or 4th-order finite differences; Christoffel-symbol derivatives either by differencing or analytically via the chain rule.
  • Time stepping: 4th-order Runge–Kutta (method of lines), with matter recomputed at every sub-step.
  • Dissipation: 6th-order Kreiss–Oliger dissipation, which damps grid-scale noise without affecting the smooth solution.
  • Surface integrals: 4th-order interpolation from the grid onto spheres, Gauss–Legendre quadrature, and projection onto spherical harmonics.
  • Outer boundary: Sommerfeld radiative condition, so that outgoing waves leave the grid instead of reflecting (see latest findings).
  • Formulation: ADM today, as a reference; Z4c with 1+log lapse and Gamma-driver shift for production.
  • Initial data: the conformal method, solving the constraint equations as nonlinear elliptic equations.

Architecture

Three layers, each depending only on the one below:

simulation — physics of the experiment: pump protocols, the scan runner, output, checkpoints
↓ uses
solver — numerics: grids, finite differences, evolution equations, boundaries, initial data, diagnostics
↓ uses
tensor-core — mathematics: tensors, metric, curvature, automatic differentiation
ModuleResponsibility
tensor-coreTensor algebra, metric, Christoffel symbols, Riemann/Ricci/Einstein tensors, Enzyme derivatives. Kept as the reference implementation.
solver::gridGrid storage, stencils, dissipation, Runge–Kutta stepping.
solver::boundarySommerfeld radiative outer boundary for any field on the grid.
solver::sphereInterpolation onto spheres, sphere quadrature, spherical harmonics and mode projection.
solver::fluxEnergy and angular momentum carried by electromagnetic and gravitational waves through spheres.
solver::poissonConjugate-gradient Poisson solver for starting data.
solver::linearFlat-space Maxwell and linearized gravity for the Phase B baseline.
solver::z4cZ4c/BSSN evolution with matter sources and evolving gauge, with upwind stencils for the shift terms; ADM remains as reference.
solver::maxwellMaxwell's equations on the curved slice, producing the matter source terms.
solver::initial_dataConstraint-satisfying Einstein–Maxwell starting data.
solver::diagnosticsConstraint norms, Ψ4 and its modes, gravitational angular momentum, fluxes, frame dragging, energy budget.
simulationPump protocols (done: one-way wave packets, rotating ring of emitters); later the configuration-driven amplitude scans, output and restart.

Engineering rules

  • Rust and plain 64-bit arithmetic throughout.
  • No memory allocation per grid point in hot loops: flat arrays and per-thread scratch buffers, parallelised over all cores with Rayon.
  • Every fast path has a slow twin. The readable tensor implementation is kept as a test oracle, and the fast version must agree with it to 10−12.
  • Test first. A feature is done when its acceptance test passes, including the measured convergence order.
  • Store deviations from flat space where possible, to keep precision at small amplitudes.
  • MIT licensed and developed in the open.

Milestones

IDMilestoneDone when
M1Grid and operatorsStencils, dissipation, Sommerfeld boundaries, interpolation onto spheres; tests G1–G5 pass. Done
M2Linear Maxwell and linearized gravityL1, L4, L5 pass; the gauge condition drift converges to zero. Done
M3Linear diagnosticsFluxes through spheres and angular momentum; consistent starting data for electromagnetically sourced gravity; L2, L3, D1, D2 pass. Done
M4Phase B science runsLinear results for every protocol, with convergence evidence.
M5Z4c/BSSN with matter and evolving gaugeUpwind stencils for the shift terms; Z1–Z5 pass; agrees with the ADM reference on short runs.
M6Maxwell coupled to gravityE1–E3 pass.
M7Constraint-satisfying initial dataI1–I3 pass.
M8Nonlinear diagnosticsD3–D6 pass.
M9Pump protocols, runner, scansR1–R3 pass; a full scan point runs from a configuration file.
M10Phase C and D science runsX1–X3 pass; nonlinear excess reported with error bars.

Acceptance tests

Convergence tests use at least three resolutions and must show the design order to within ±0.3.

IDTestAcceptance criterion
Grid and operators
G1Derivatives of smooth fieldsOrder 2 or 4 as designed
G2Mixed second derivativesOrder 2 or 4 as designed
G3Dissipation on a grid-scale modeDamped by the predicted factor; smooth modes unaffected
G4Outgoing spherical pulse through the outer boundaryReflection below 1% at the coarsest resolution, falling with resolution
G5Interpolation onto a sphereIntegrals of spherical harmonics exact to interpolation order
Linear physics
L1Maxwell plane waveMatches the exact solution at design order
L2Oscillating electric dipoleRadiated power matches Larmor's formula within 2%
L3Rotating mass quadrupoleRadiated energy and angular momentum match the quadrupole formula within 2%
L4SuperpositionSum of two runs equals the combined run to round-off
L5Gauge conditionDrift converges to zero for conserved sources
Nonlinear evolution
Z1Flat space with tiny random noiseNo exponential growth over 1000 crossing times
Z2Standard linear-wave test problemDesign-order convergence against the exact solution
Z3Standard gauge-wave test problemStable and convergent over 100 crossing times
Z4Small-amplitude Teukolsky waveΨ4 matches the analytic solution
Z5Fast vs. reference evaluationAgree to 10−12
Electromagnetism on curved space
E1Electromagnetic wave on a flat sliceEquals the linear code to round-off
E2Divergence constraintsConverge to zero
E3Energy, momentum and stress of the fieldMatch the closed-form expressions
Initial data
I1Constraint residualConverges at design order
I2Weak-field limitMatches the Newtonian potential to second order
I3Spinning test dataMeasured angular momentum equals the input
Diagnostics
D1Energy balance (linear)Injected = stored + radiated, to truncation error
D2Angular-momentum balance (linear)Same balance for angular momentum
D3Radiation extractionTeukolsky-wave modes correct; independent of extraction radius
D4Mass of a black holeSchwarzschild data recovers its mass
D5Angular momentumSpinning data recovers its angular momentum
D6Nonlinear energy budgetBalance closes to truncation error
Runner
R1Configuration round tripParse, write and re-parse give the same configuration
R2Checkpoint and restartRestarted run bitwise identical to an uninterrupted one
R3Short end-to-end runNo invalid numbers, bounded constraints, readable output
Cross-validation (science-critical)
X1Small-amplitude limitFull code reproduces the linear code, residual proportional to ε
X2Domain independenceStorage unchanged when the box is enlarged 1.5× (guards against the mirror trap)
X3Second-order consistencyFitted quadratic coefficient matches second-order theory

Compute budget

One 2nd-order time step currently costs about 1.8 µs per grid point; the 4th-order path with evolving gauge and dissipation about 7 µs. Z4c with Maxwell is expected to cost two to four times that. A run of 128³ points for 104 steps is therefore of order 10–40 hours on a single workstation, and linear runs are about ten times cheaper. If radiation must be measured far from the sources, nested grids (mesh refinement) will be needed; that decision waits for the Phase B measurements.

Source code

All code is MIT licensed and developed in the open.