In the last essay I built a fusor — a tiny fusion device that uses raw electric voltage to pull ions into a cage and let them oscillate until some of them fuse. Cages are the basement-budget answer to fusion.
This is the other answer. The one with the billion-dollar price tag. The energy donut.
A tokamak is shaped, in essence, like a donut. Not a metaphor. A literal hollow toroidal shell wrapped in a forest of enormous superconducting electromagnets. Inside the donut you put a few grams of deuterium-tritium fuel, heat it to a hundred million degrees, and let the magnets hold it in place while the fusion happens.
I built a simulator for this one too. Same C++/raylib stack as the fusor. Same in-browser embed. Different physics — very different physics.
Let's get into it.
Why a donut?
The fusor used voltage to pull ions inward. Magnets work differently. Charged particles in a magnetic field don't fall toward the magnet — they spiral around the field line. The line is the rail; the particle is a bead with a fixed perpendicular speed, sliding along.
So if you want to hold plasma in place with magnets, you need to give the field lines somewhere to go that doesn't escape. A straight magnetic field would let particles slide right off the end. A torus solves this: the field lines wrap around the donut hole and close on themselves. A particle on a closed field line is, in principle, trapped forever.
That's the whole conceptual basis of magnetic confinement. Find a closed magnetic geometry. Put plasma on it. Watch it stay.
The donut shape — the torus — turns out to be the simplest such geometry that actually works. Everything else (stellarators, mirror machines, spheromaks) is a variation on the same theme: bend the field lines into closed loops so the plasma can't escape.
The field, or, why donuts twist
There's a complication. The toroidal field — the field running the long way around the donut — varies with radius. Specifically it's stronger on the inside of the donut and weaker on the outside (because the magnets are closer together on the inside). This variation means a charged particle drifts slowly outward across the field lines.
If that drift were the end of the story, every plasma would dribble out the outer wall in a few microseconds. Not useful.
The fix is poloidal twist. You add a second magnetic field component that runs the short way around the donut — perpendicular to the main toroidal field. The result is that every field line is now a helix — wrapping around the long way and also slowly around the short way at the same time.
The crucial thing about a helical field line is that it spends half its length on the inside of the donut and half on the outside. The radial drift, integrated around a full helix, cancels out. A particle on a helical field line stays trapped.
So a tokamak's magnetic field is two fields stacked: a strong toroidal field generated by external coils, plus a weaker poloidal field generated by the plasma current itself. (Yes — you induce a giant current in the plasma using a transformer, and that current makes the poloidal twist. The plasma is also the wire in its own magnet.)
In the sim, the slider labeled POLOIDAL Bp adjusts that twist. Watch what happens when you set it to zero.
The safety factor q
How tight should the twist be? This question has a name: the safety factor, written q.
Roughly: q counts how many times a field line goes around the long way for every one time it goes around the short way. q = 3 means a field line spirals around the donut three full toroidal turns before completing one poloidal turn.
The name "safety" is not a marketing thing. Tokamak physicists discovered very early that if q drops below about 1 anywhere in the plasma, the plasma goes unstable. A specific instability called a sawtooth kicks in, the plasma reorganises violently, and confinement breaks. So you keep q > 1 everywhere and call yourself safe.
The HUD in the sim shows the approximate q in the top-right. Crank toroidal B0 up and q goes up — tighter winding, more stable. Crank poloidal Bp down and q explodes — the plasma is just sliding around the donut without twisting, drifts dominate, particles escape.
This is the central engineering knob of every tokamak on Earth.
What the sim shows
The simulator is a test-particle picture. Each particle is independent — it moves under the prescribed magnetic field with Newton's laws (Lorentz force) using the Boris integrator (the standard symplectic scheme for magnetic-only motion). There's no plasma current self-consistency, no MHD, no kinetic instabilities. The fields are fixed, the particles dance.
What you can see clearly:
Gyration — each particle spirals tightly around its local field line. The gyroradius (how big the spiral) depends on thermal velocity and field strength — slider both.
Field-line motion — particles slide along the helical field lines, which wrap the donut.
Drifts — when poloidal Bp is small, watch particles drift outward and escape. When Bp is healthy, they stay confined.
Mixing — at moderate field strengths the particle distribution fills the entire flux surface — the helical motion plus drifts add up to a uniform donut.
The faint blue lines visible in the chamber are sampled magnetic field lines, integrated forward by RK2. They're the rails the plasma rides on.
What the sim doesn't show
The honest list:
Plasma current self-consistency — real tokamak poloidal field comes from a plasma current that responds to everything else. Here it's a knob.
MHD instabilities — real plasmas have kink modes, ballooning modes, edge-localised modes — the whole zoo of ways a confined plasma finds to escape. Test-particle pictures don't see any of this.
Heating — I just give particles thermal velocity at spawn. Real tokamaks heat with neutral beam injection, radiofrequency, and ohmic dissipation of the plasma current itself.
Fusion — zero neutrons. Same as the fusor sim.
The actual hard part — scrape-off layer, divertor heat loads, tritium breeding, neutron damage to walls — the engineering work that consumes 90% of an actual tokamak project.
This is, again, a tool for seeing magnetic confinement. Not for designing a power plant.
Donuts versus cages
The fusor sim showed how the shape of a cage decides where electrostatically-confined ions converge. This sim shows how the ratio of magnetic field components decides whether magnetically-confined ions stay or escape.
Both reduce to the same question I posed at the end of the last essay: how do you keep charged particles close together long enough that some of them fuse?
Cages answer with voltage. They're cheap, simple, leaky.
Donuts answer with magnets. They're absurdly expensive, scale to enormous size, and might one day actually give net power.
If anyone gets to net-positive fusion in our lifetime, it'll almost certainly be a donut. ITER is a donut. SPARC is a donut. The Wendelstein 7-X stellarator in Germany is a more sophisticated relative of the donut. The Chinese EAST, the Korean KSTAR, the British MAST-U — all donuts.
The fusor is a basement experiment. The energy donut is a national-laboratory experiment. Both are honest answers to the same question, at very different scales.
Play with it
Pick up the simulator above. Try these:
Set Bp to 0 (no twist) and watch the plasma fail.
Set Bp to 0.4 (strong twist) and watch the helical field lines pull everything into nice orbits.
Crank thermal velocity up to see large gyroradii — particles trace big visible loops as they slide along field lines.
Squish the donut by shrinking a. Small minor radius = tighter confinement, smaller volume, lower q.
If you build an actual stellarator in your garage, tag me. I want pictures.
— Ali