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

Notebooks · posts/two-stream-instability-in-a-particle-code

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.

Two beams of electrons move through each other at velocities and , over a fixed background of ions that keeps the plasma neutral on average. A small ripple in density bunches both beams, the bunches make an electric field, and the field bunches them further. The ripple grows exponentially at a rate that linear theory predicts, until electrons are trapped in the wave's potential wells and the growth stops.

A particle-in-cell (PIC) code follows this with no model beyond Newton's law and Gauss's law. Each step it spreads the particles' charge onto a grid, solves for the electric field on the grid, reads the field back at each particle, and moves the particles. Units: the plasma frequency , the beam speed .

For two cold beams at , each of density , write . The dispersion relation

is the quartic , and its unstable root has

which is positive only for . The cell below computes from it.

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.

[1]lines 37–59

The particle code

The box is one wavelength of the fastest mode, , with 32 grid cells and 2000 particles, 1000 per beam. The particles start evenly spaced, a quiet start, with their positions shifted by so that only the one mode is seeded. With random positions the instability would grow out of noise in every mode at once, and the fit below would need far more particles.

  • Deposit. Each particle's charge is shared between the two nearest grid points in proportion to how close it is (cloud-in-cell). The ions add a uniform .
  • Field. Gauss's law , integrated along the grid by the trapezoid rule; the mean of is removed, since a periodic box has no net field.
  • Push. Leapfrog: velocities live at half steps, positions at whole steps, and an electron's acceleration is .
[2]lines 78–176

Running it

The cell runs 250 steps to . Every 12 steps it adds a frame to the film: a histogram of the particles in the plane. It also records the amplitude of the seeded mode at every step.

In the film the two beams are the bright lines at . They ripple, then fold over each other into vortices: electrons caught in the wave's potential wells, going round at the bounce frequency. At that point the field stops growing.

[3]lines 190–236

The growth rate

While the mode is small it grows as , so is a straight line of slope . The cell fits that line by least squares between and . Before the seed still carries the other three roots of the quartic, a decaying one and an oscillating pair, and their share falls only as . After the amplitude is above 0.1 and trapping has begun to slow the growth.

The fit gives , above theory. The test allows 1%, and here is why. Moving the window to or moves the fitted rate by up to 0.4%, so the choice of window alone is worth that much. Halving the time step, doubling the grid or quadrupling the particles moves it by at most 0.4% as well (posts/refs/two_stream_pic.py runs each case). A numpy implementation of the same algorithm gives the same rate to .

[4]lines 255–295

Saturation

The amplitude of the mode peaks at 0.568 at and then falls back: the trapped electrons now give energy back to the field as fast as they take it. From to the peak, the energy in the field grows by a factor of about . The dashed line in the figure is with the theoretical rate, drawn through the fitted amplitude at .

[5]lines 307–350