This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Plasma physics

Particle motion

demoAIPlasma physicswritten with an agent#319603bba3

A gyro-orbit and the E×B drift by the Boris push

The Boris push moves a charged particle through electric and magnetic fields in almost every particle-in-cell code. In a magnetic field alone it keeps the speed to rounding and puts every position on one circle; the gyroperiod comes out 6.28449 instead of , longer by . With an electric field added, a particle started at moves at exactly that velocity forever, and any other start averages to it.

Boris gyro-orbit, dt = 0.05: the first 1.25 turns-1-0.500.5100.511.52xy
Boris positionsexact orbit, radius v/ωc=1
Gyroperiod error of the Boris push
measured(ωcΔt)2/12
10⁻⁴10⁻³10⁻²0.050.10.2time step ωcΔtT/(2π/ωc)−1
E x B drift: E = 0.1 x-hat, B = z-hat, 5 gyroperiods-4-20-10123xy
Boris trajectoryguiding center at E×B/B2
✓ 7 tests passchecked when the site was built#plasma#particle-pushers#boris#gyration#drift#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Instabilities

demoAIPlasma physicswritten with an agent#d764b8f8e6

The two-stream instability in a particle-in-cell code

Two cold electron beams passing through each other are unstable. A particle-in-cell code with 2000 particles measures the growth rate of the fastest mode as 0.35366 ; cold-beam linear theory gives . The phase-space film shows the beams rolling up into vortices of trapped electrons, which is where the growth stops.

Phase space of the two beams (press play)
v
x
21/21
32 × 48 grid · 21 frames
Amplitude of the seeded mode
PIC, 2000 particleslinear theory, eγt
10⁻⁴10⁻³10⁻²10⁻¹10⁰0510152025t (1/ωp)|E1|
✓ 9 tests passchecked when the site was built#plasma#particle-in-cell#instability#kinetic#animation#notebook
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

ladderAIPlasma physicswritten with an agent#b7c5ad40e0

The Hasegawa-Wakatani drift-wave model

The Hasegawa-Wakatani equations are the simplest model of drift-wave turbulence at the edge of a tokamak that contains the instability driving it. Five rungs build their linear theory: the drift-wave frequency, the growth rate as the eigenvalue of a 2×2 matrix (0.098684 at , as numpy's eigensolver gives), the return to the drift wave as at the predicted rates and , a zonal flow that keeps of its start as it relaxes, and the one-line change in the modified model that leaves it untouched.

One mode of Hasegawa-Wakatani, kx=0, C=1
growth rate γfrequency ωdrift wave, κky/(1+k2)
00.20.40.51.01.52.02.53.0kyrate
A zonal band, kx=0.5, C=1
classical Hasegawa-Wakataniresidual k2/(1+k2)
00.51.000.51.01.52.0tzeta(t) / zeta(0)
The same band in the two models
classicalmodifiedresidual k2/(1+k2)
00.51.000.51.01.52.0tzeta(t) / zeta(0)
  1. 1The drift wave+1 function · +3 tests
  2. 2The growth rate is an eigenvalue+3 functions · +3 tests
  3. 3Stiff coupling gives back the drift wave+2 tests
  4. 4A zonal flow relaxes to k^2 / (1 + k^2) of its start+1 function · +2 tests
  5. 5The modified model leaves the band alone+1 function · +2 tests
✓ 12 tests passon 5 rungs, each rerunning every earlier test · checked when the site was built#plasma#drift-waves#turbulence#zonal-flows#eigenvalues#ladder

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Kinetic theory

demoAIPlasma physicswritten with an agent#827ef11264

Landau damping from the root of the dispersion relation

A Langmuir wave in a collisionless plasma still decays: electrons moving near its phase velocity take energy from it. Newton's method on the kinetic dispersion relation, with the plasma dispersion function from lib/zfunc, puts the least-damped root at at (in units of ), matching a 30-digit mpmath root to . The usual small- damping formula is 1.3% off there and 59% off at .

log10|ϵ(ω)| at kλD=0.5
Imω/ωpe
Reω/ωpe
48 × 64 grid
Damping rate of the least-damped Langmuir wave
exact rootsmall-k formula
10⁻⁴10⁻³10⁻²10⁻¹0.20.30.40.50.6kλDγ/ωpe
Frequency of the least-damped Langmuir wave
exact rootBohm-Gross, 1+3k2
1.21.40.20.30.40.50.6kλDωr/ωpe
The field of a Langmuir wave at k lambda_D = 0.5, from the linearized Vlasov equation
Re E1Im E1decay at the root's rate
−1012010203040t omega_peE1
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

demoAIPlasma physicswritten with an agent#91420950b3

The bounce period of an electron trapped in a plasma wave

In the frame of a large-amplitude plasma wave, an electron near the wave's phase velocity moves like a pendulum. Released 0.1 radian from the bottom of a trough, it takes time units to bounce back, which is from the complete elliptic integral, and to six digits. Electrons with speed below at the trough stay in it; faster ones pass over the crests.

Bounce period against release angle, phi0 = 11015202500.511.522.53release angle theta0 (radians)bounce period ωBT
4K(sin2(θ0/2))velocity Verlet, dt = 0.002
Phase space of electrons in the wave frame, phi0 = 1-202-3-2-10123x (wave phase, radians)v
orbits from the troughseparatrix v=±2ωBcos(x/2)
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Equilibrium

demoAIPlasma physicswritten with an agent#ff0590fe04

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 .

Grad-Shafranov error against the Solov'ev solution
five-point difference equations, solved by SORslope 2
10⁻⁵10⁻⁴0.030.040.050.060.070.080.090.1grid spacing hmax|ψ−ψexact|
Solov'ev equilibrium on a 33 x 57 grid: poloidal flux ψ(R,Z)
Z
R
57 × 33 grid
✓ 7 tests passchecked when the site was built#plasma#mhd#tokamak#equilibrium#grad-shafranov#finite-differences#sor
ReadOpen in the workbench

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.