Physics Plasma Physics MHD Magnetic Reconnection WebGL

2D Magnetohydrodynamics (MHD) & Magnetic Reconnection at 60 FPS


Color = Out-of-plane current J_z = -∇²A_z · White contours = magnetic field lines · Click to pinch the sheet
Real-time 2D resistive MHD reconnection: opposite-polarity magnetic fields pinch across the Harris current sheet, snap at X-points, and sling plasma jets into glowing magnetic islands (plasmoids).

If you fuse our Navier–Stokes fluid solver with Maxwell's equations, you get Magnetohydrodynamics (MHD) – the physics of electrically conducting plasma that powers solar flares, tokamak disruptions, and relativistic accretion disks. In ideal MHD ($\eta = 0$), Alfvén's theorem freezes magnetic field lines permanently into the fluid. Add even a tiny electrical resistivity $\eta \gt 0$ inside a thin current sheet, and field lines can break and reconnect – violently converting stored magnetic tension $B^2/(2\mu_0)$ into kinetic Alfvén jets.


1. Exact $\nabla\cdot\mathbf{B} = 0$ via the Magnetic Flux Function $A_z$

The biggest numerical headache in 3D MHD is preserving the solenoidal constraint $\nabla\cdot\mathbf{B} = 0$ (no magnetic monopoles). In 2D incompressible MHD, introducing the scalar out-of-plane vector potential $A_z(x,y,t)$ satisfies $\nabla\cdot\mathbf{B} = 0$ identically to machine precision:

2D Incompressible Resistive MHD & Sweet–Parker Reconnection Rate
$$\mathbf{B} = \nabla \times (A_z \hat{\mathbf{z}}) = \left(\frac{\partial A_z}{\partial y},\, -\frac{\partial A_z}{\partial x}\right), \qquad J_z = -\nabla^2 A_z$$ $$\frac{\partial A_z}{\partial t} + \mathbf{u}\cdot\nabla A_z = \eta \nabla^2 A_z, \qquad \frac{\partial \omega}{\partial t} + \mathbf{u}\cdot\nabla\omega = \mathbf{B}\cdot\nabla J_z + \nu\nabla^2\omega$$ $$\frac{v_{\text{in}}}{v_A} \sim S^{-1/2}, \qquad S = \frac{L v_A}{\eta} \;\;(\text{Lundquist number})$$

At high Lundquist numbers ($S \gt 10^4$), the elongated Sweet–Parker current sheet itself becomes tearing-unstable and shatters into a chain of self-similar magnetic islands (plasmoids), driving fast reconnection independent of $\eta$.

💻 GLSL: 2D Resistive MHD Streamfunction–Vorticity & Magnetic Flux UpdateGLSL / MHD Kernel
// 2D Resistive MHD in Streamfunction-Vorticity (psi, omega) & Magnetic Flux (A_z) form
// B = (dA/dy, -dA/dx),  u = (dpsi/dy, -dpsi/dx),  J_z = -laplacian(A_z)
// Induction equation:  dA/dt + u · grad(A) = eta * laplacian(A)
// Vorticity equation:  domega/dt + u · grad(omega) = B · grad(J_z) + nu * laplacian(omega)
float lorentzTorque = (Bx * dJz_dx + By * dJz_dy);
omegaNext = omega - dt * (ux * dOm_dx + uy * dOm_dy) + dt * lorentzTorque + dt * nu * lapOmega;
AzNext    = Az    - dt * (ux * dAz_dx + uy * dAz_dy) + dt * eta * lapAz;
Why Field-Line Contours Are Free: Because $\mathbf{B}\cdot\nabla A_z = (\partial_y A_z)(\partial_x A_z) - (\partial_x A_z)(\partial_y A_z) \equiv 0$, every level set $A_z(x,y) = \text{const}$ is an exact magnetic field line! Plotting isolines of $A_z$ over the current density heatmap $J_z = -\nabla^2 A_z$ immediately exposes every X-point (reconnection site) and O-point (magnetic island).