2D Magnetohydrodynamics (MHD) & Magnetic Reconnection at 60 FPS
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:
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;