Notebooks · posts/grad-shafranov-solovev
Grad-Shafranov by finite differences, against Solov'ev's closed form
A tokamak equilibrium solved on a grid and graded against an exact one. Solov'ev's solves the Grad-Shafranov equation with constant pressure gradient; the five-point solver, relaxed by SOR until the residual is below , misses it by , and on grids of spacing 0.1, 0.05 and 0.025, an observed order of 1.995 and then 1.994. Those errors are scipy's direct solve of the same equations, to .
A tokamak holds its plasma in a magnetic field shaped like nested doughnuts. In equilibrium the magnetic force balances the pressure gradient, . With the machine's rotational symmetry about its vertical axis, that balance reduces to one equation for one function, the poloidal flux , where is the distance from the axis of symmetry and the height. The surfaces are the flux surfaces: the field lines lie in them, and the pressure is constant on each. The equation is the Grad-Shafranov equation above. Its right side holds two free functions of , the pressure and .
When and are constants the equation is linear, and Solov'ev (1968) wrote down exact solutions. This post takes and (lengths in units of the major radius), for which
is exact: its flux surfaces are nested about the magnetic axis at
, and near the axis they are ellipses of elongation
. posts/refs/grad-shafranov-solovev.py checks the closed form
with sympy, then solves the same finite-difference equations directly with
scipy's sparse LU, which shares no code or method with the SOR iteration
here.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.
The discrete equation and SOR
On a grid with spacing in and in , the centered differences for , and give at each interior node
with fixed to the closed form on the edge of the box. The term makes the equation unsymmetric in ; that is the only difference from Poisson's equation.
Successive over-relaxation (SOR) sweeps the grid, solves each node's equation for with its neighbors' newest values, and moves times that far. The program takes the that is optimal for Poisson's equation on the same box, , with the Jacobi iteration's spectral radius for and intervals of equal spacing. It sweeps until the largest residual is below , so what is left is the discretization error.
Three grids
The three grids have 8, 16 and 32 intervals across and 14, 28 and 56 across , so = 0.1, 0.05 and 0.025. (The reference script also solves a fourth grid, , where the order is 1.9998; it takes too long in a browser tab.)
The error of the difference equations is second order, and here it can be written down. The closed form's term is a quadratic in each variable, so the centered differences are exact on it. On the second difference is off by and the first difference over by , so the difference operator applied to the exact misses the source by , the same constant at every node. The error therefore solves the difference equation with source and zero boundary values: it is times a fixed function, up to that function's own discretization, and each halving of divides it by 4.
The flux surfaces, and the Shafranov shift
The heatmap is the solution on the 33 by 57 grid, with the flux surfaces drawn at five values of . They are nested about the magnetic axis at , taller than wide near the axis (), and pushed toward small farther out.
On the midplane the closed form gives the crossings of a surface directly: puts them at . The surface through crosses again at , so its center is at : the magnetic axis sits outboard of the center of this surface. That offset is the Shafranov shift, and it appears whenever there is pressure: the plasma pushes itself outward, where the field is weaker. The program reads the same crossing off the 33 by 57 grid by linear interpolation along the midplane and gets 0.661489, which is the reference script's interpolation on its own solution of the same grid, and from the closed form.