This example couples General Relativity to Magnetohydrodynamics through DeepCausality's monadic composition: a curvature quantity the GR solver computes decides which algebra the MHD solver runs in.
From the root of the deep_causality project, run:
cargo run -p physics_examples --example grmhd_exampleSimulating extreme environments (Black Holes, Neutron Stars) requires coupling:
- General Relativity: Gravity and Spacetime Curvature
- Magnetohydrodynamics: Plasma and Electromagnetic Fields
The simulation adapts its mathematical foundation to the physical conditions, so it stays valid in extreme regimes.
[Step 1] GR Solver → Schwarzschild metric → Kretschmann scalar, tidal acceleration
↓
[Step 2] Coupling Layer → Select Metric (Euclidean vs Minkowski)
↓
[Step 3] MHD Solver → Lorentz force density (F = J ∧ B)
↓
[Step 4] Feedback → EM stress-energy T^tt on the Schwarzschild metric
↓
[Step 5] Stability Analysis → Confinement Status
CausalFlow::value starts the chain, .context attaches the world, one .try_step_with runs each solver stage and .map the analysis, and finish returns the final state or the error a stage short-circuited with.
The world is a Context of six Data contextoids: the central mass (10 solar masses), the plasma's orbital radius (3 r_s), the column length, the current density, the magnetic field and the tidal threshold. The first four stages read what they need from the context channel, and the curvature and stress-energy stages derive r_s and r from the mass and the orbital radius; the analysis works on the state alone. The value channel carries only the results.
All quantities are in geometric units, G = c = 1; the tidal acceleration is also reported in m/s^2.
Builds the Schwarzschild metric with generate_schwarzschild_metric. In the vacuum exterior the Ricci scalar is zero, so the curvature invariant that carries the tidal physics is the Kretschmann scalar K = 48 M^2 / r^6. The stage also computes the radial tidal acceleration across the plasma column, a = 2 M L / r^3.
Selects the Clifford metric from the tidal acceleration:
- Above the threshold (
1e-12): Minkowski(4), relativistic 4D spacetime - At or below the threshold: Euclidean(3), classical 3D space
Computes the Lorentz force density with lorentz_force as the wedge product F = J ∧ B of the current and the magnetic field, in the algebra the coupling layer selected.
Carries the observer's B into coordinates, computes the EM stress-energy with energy_momentum_tensor_em, and projects T^tt back onto the observer. The result must equal B^2 / 2; the run checks this identity and exits nonzero if it fails.
Compares the curvature the plasma sources, 8 pi rho_EM, with the curvature the hole imposes, sqrt(K):
- Negative force: reversed confinement, the force points out of the column
8 pi rho_EM > sqrt(K): magnetically dominated- Otherwise: tidally dominated
Tensors and multivectors compose monadically into one multi-physics chain. Each stage transforms the state through a pure function.