Algorithm Search⌘K

Algorithmcore

Particle-in-cell plasma simulation

Also called electrostatic particle-in-cell, electromagnetic particle-in-cell.

Moves charged macroparticles in fields computed on a grid from their deposited charge and current; the main method of kinetic plasma simulation.

Time
Θ(T (N + M)) worst
Space
Θ(M) extra
Where
M = the number of grid points; N = the number of particles; T = the number of time steps
Properties
conservativedeterministic
Origin
John M. Dawson, Charles K. Birdsall, A. Bruce Langdon, 1962

Particle-in-cell (PIC) plasma simulation solves the kinetic equations of a collisionless plasma by following a large number of charged macroparticles, each of which stands for many real electrons or ions, in fields that are computed on a grid. In each time step the code deposits the charge (and in electromagnetic codes the current) of the particles on the grid, solves the field equations on the grid, interpolates the fields back to the particles, and moves the particles with the Boris pusher or the leapfrog. The particles sample the phase space density of the Vlasov-Poisson system (or Vlasov-Maxwell system), so PIC captures kinetic effects such as Landau damping, beam instabilities and particle acceleration that fluid models miss. The graphics pages particle-in-cell, fluid-implicit-particle and affine-particle-in-cell share the name and the particle to grid transfers, but they carry fluid velocity on the particles and project it to be divergence free; the plasma method carries charge and solves for electric and magnetic fields.

In plain words

A plasma is a hot gas of charged particles, far too many to follow one by one. A PIC code follows a smaller number of heavy, highly charged stand-ins instead. Each stand-in moves like the real particles it represents.

The stand-ins never push each other directly. Instead each one leaves its charge on the nearby points of a fixed grid. The code then works out the electric field on the grid from all the charge at once, which is fast. Each stand-in reads the field at its own place from the same grid points and moves a short time forward. Then the cycle repeats. Because the grid smooths the field over a cell, close collisions between stand-ins are weak, which is what a hot, thin plasma needs.

The problem

In the electrostatic case, the input is a periodic domain of length LL with MM grid points, and NN particles with positions xpx_p, velocities vpv_p, charge qpq_p and mass mpm_p. The unknown is the phase space density f(x,v,t)f(x, v, t) of the electrons, which obeys the Vlasov-Poisson system

∂tf+v ∂xf+qmE ∂vf=0,∂xE=ρ=1−∫f dv,\partial_t f + v \, \partial_x f + \frac{q}{m} E \, \partial_v f = 0, \qquad \partial_x E = \rho = 1 - \int f \, dv,

in normalized units: ϵ0=1\epsilon_0 = 1, the electrons have q/m=−1q/m = -1, the ions are a fixed background of density 1, times are in units of 1/ωp1/\omega_p and lengths in units of vth/ωpv_{th} / \omega_p, so the Debye length λD=vth/ωp\lambda_D = v_{th} / \omega_p is the thermal speed. The particles are a sample of ff: each carries qp=−L/Nq_p = -L / N and mp=L/Nm_p = L / N, so that their mean density is 1. The output is the particle state and the grid field at each step, and from them the measured quantities, such as the field energy W=12∑jEj2ΔxW = \tfrac{1}{2} \sum_j E_j^2 \Delta x.

The algorithm

  1. ES-PIC(x[1..N], v[1..N], M, L, h, T) ▷ v given at t = 0
  2. 1ρ ← CIC-DEPOSIT(x, q_p) + 1 ▷ electrons plus ion background
  3. 2E ← GAUSS(ρ) ▷ E_{j+1/2} - E_{j-1/2} = Δx ρ_j, mean zero
  4. 3E_p ← CIC-INTERPOLATE(E, x_p) for every p
  5. 4v_p ← v_p - (h / 2)(q/m) E_p for every p ▷ start the leapfrog at t = -h/2
  6. 5for n ← 1 to T do
  7. 6v_p ← v_p + h (q/m) E_p for every p
  8. 7x_p ← (x_p + h v_p) mod L for every p
  9. 8ρ ← CIC-DEPOSIT(x, q_p) + 1
  10. 9E ← GAUSS(ρ)
  11. 10E_p ← CIC-INTERPOLATE(E, x_p) for every p
  12. 11record W_n = ½ Σ_j E_j² Δx
  13. 12return x, v, W

Lines L1 and L8 use cloud-in-cell assignment. Lines L2 and L9 solve Gauss's law with a running sum on the half points, remove the mean, and average to the grid points; this equals minus the centred difference of the potential of the 3-point Poisson equation, so the field kernel is odd. Lines L6 and L7 are the leapfrog; with a magnetic field, line L6 becomes the Boris step. In an electromagnetic code, line L8 also deposits the current, and lines L9 and L10 advance E\mathbf{E} and B\mathbf{B} with the Yee scheme instead of solving Gauss's law.

Example

Take M=4M = 4, L=4L = 4 (Δx=1\Delta x = 1) and N=4N = 4 electrons, so qp=−1q_p = -1. At x=0.5,1.5,2.5,3.5x = 0.5, 1.5, 2.5, 3.5 each grid point gets −1-1 from the electrons and +1+1 from the ions, so ρ=0\rho = 0 and E=0E = 0.

Now move the first electron to x=0x = 0. Line L1 gives ρ=(−0.5,0.5,0,0)\rho = (-0.5, 0.5, 0, 0): point 0 has an extra half electron and point 1 a missing half. Line L2 gives E=(−0.125,−0.125,0.125,0.125)E = (-0.125, -0.125, 0.125, 0.125), and line L3 gives the fields −0.125,0,0.125,0-0.125, 0, 0.125, 0 at the four electrons. The forces qpEpq_p E_p are 0.125,0,−0.125,00.125, 0, -0.125, 0: the electrons at 0 and 2.5 move toward point 1, where positive charge is in excess, and the forces sum to 0. With h=0.5h = 0.5, line L4 gives v1=−0.03125v_1 = -0.03125, line L6 gives v1=0.03125v_1 = 0.03125, and line L7 moves the first electron to x=0.015625x = 0.015625.

A measurement with this code (with lines L1 to L12 and the mode amplitude of EE recorded): with k=0.5k = 0.5, L=4πL = 4\pi, M=32M = 32, h=0.1h = 0.1, N=100 000N = 100\,000 electrons, a density perturbation of 1 percent and a quiet start (velocities from the inverse normal distribution at bit-reversed quantiles), the amplitude of the mode k=0.5k = 0.5 of EE decays at the rate 0.147, fitted over its peaks for tt from 2.5 to 18, and oscillates at about 1.42. Linear theory gives γ=−0.1534\gamma = -0.1534 and ω=1.4157\omega = 1.4157 (see the Vlasov-Poisson system).

Correctness

The full proof is in the correctness proof. It shows these facts (theorems on the scheme, in exact arithmetic):

  • The grid charge is neutral: ∑jρjΔx=0\sum_j \rho_j \Delta x = 0 at every step, because each electron deposits exactly qpq_p and Nqp=−LN q_p = -L.
  • Lines L2 and L9 return Ej=−(ϕj+1−ϕj−1)/(2Δx)E_j = -(\phi_{j+1} - \phi_{j-1}) / (2\Delta x) for the mean-free solution of −(ϕj+1−2ϕj+ϕj−1)/Δx2=ρj−ρˉ-(\phi_{j+1} - 2\phi_j + \phi_{j-1}) / \Delta x^2 = \rho_j - \bar\rho.
  • The total momentum ∑pmpvp\sum_p m_p v_p does not change in any step, including the start in line L4, because the forces sum to zero (the argument of the cloud-in-cell page).

What PIC computes is a statistical estimate of the solution of the Vlasov equation, not the solution itself. As NN grows with the grid and the step fixed, the particle density converges to the solution of the semi-discrete Vlasov equation, with a statistical error of order Nc−1/2N_c^{-1/2} for NcN_c particles per cell (a heuristic from the central limit theorem, as in Monte Carlo integration). The grid and the leapfrog add errors of order Δx2\Delta x^2 and h2h^2.

Proof: The electrostatic PIC loop keeps the grid neutral, solves the discrete Poisson equation and conserves the total momentumfull

We use the pseudocode of the page and exact arithmetic. The grid has MM points, Δx=L/M\Delta x = L / M, indices are taken mod MM, and there are NN electrons with charge qp=−L/Nq_p = -L/N, mass mp=L/Nm_p = L/N and q/m=−1q/m = -1. We use two results proved on the cloud-in-cell assignment page: (A) the CIC weights Wp,jW_{p,j} of one particle add to 1, and the deposit is ρj=∑pqpWp,j/Δx\rho_j = \sum_p q_p W_{p,j} / \Delta x while the interpolation is Ep=∑jWp,jEjE_p = \sum_j W_{p,j} E_j with the same WW; (B) if E=K∗ρE = K * \rho with an odd kernel, K−m=−KmK_{-m} = -K_m, then ∑pqpEp=0\sum_p q_p E_p = 0.

Claim 1 (neutral grid). After lines L1 and L8, ∑jρjΔx=0\sum_j \rho_j \Delta x = 0.

Proof. The background adds 11 to each of the MM points, so MΔx=LM \Delta x = L in total. By (A) the electrons add ∑pqp=N⋅(−L/N)=−L\sum_p q_p = N \cdot (-L/N) = -L. □\square

Claim 2 (the field solve). Lines L2 and L9 return Ej=−(ϕj+1−ϕj−1)/(2Δx)E_j = -(\phi_{j+1} - \phi_{j-1}) / (2\Delta x), where ϕ\phi is the unique mean-free solution of −(ϕj+1−2ϕj+ϕj−1)/Δx2=ρj−ρˉ-(\phi_{j+1} - 2\phi_j + \phi_{j-1}) / \Delta x^2 = \rho_j - \bar\rho.

Proof. The routine forms Hj=∑i≤jΔx(ρi−ρˉ)H_j = \sum_{i \le j} \Delta x (\rho_i - \bar\rho) for j=0,…,M−1j = 0, \ldots, M - 1, subtracts the mean cc of the HjH_j, and sets Ej=(Hj−c+Hj−1−c)/2E_j = (H_j - c + H_{j-1} - c)/2, where H−1H_{-1} means HM−1H_{M-1}. Since ∑i(ρi−ρˉ)=0\sum_i (\rho_i - \bar\rho) = 0, HM−1=0H_{M-1} = 0, so the index −1-1 is consistent with the periodic extension H−1=HM−1=H−1+MH_{-1} = H_{M-1} = H_{-1+M} and Hj−Hj−1=Δx(ρj−ρˉ)H_j - H_{j-1} = \Delta x(\rho_j - \bar\rho) holds for every jj mod MM. Let ϕ\phi be the mean-free solution of the 3-point equation; it exists and is unique because the periodic 3-point Laplacian has the constants as its kernel and its range is the grid functions of zero mean. Set Gj=−(ϕj+1−ϕj)/ΔxG_j = -(\phi_{j+1} - \phi_j)/\Delta x, the field at the half point j+1/2j + 1/2. Then Gj−Gj−1=−(ϕj+1−2ϕj+ϕj−1)/Δx=Δx(ρj−ρˉ)G_j - G_{j-1} = -(\phi_{j+1} - 2\phi_j + \phi_{j-1})/\Delta x = \Delta x(\rho_j - \bar\rho), and ∑jGj=0\sum_j G_j = 0 because the sum telescopes round the ring. So GG and H−cH - c have the same differences and both have mean zero, hence G=H−cG = H - c. Then Ej=(Gj+Gj−1)/2=−(ϕj+1−ϕj−1)/(2Δx)E_j = (G_j + G_{j-1})/2 = -(\phi_{j+1} - \phi_{j-1})/(2\Delta x). □\square

Claim 3 (the kernel is odd). E=K∗ρE = K * \rho for an odd kernel KK.

Proof. By Claim 2, ϕ=G′∗(ρ−ρˉ)\phi = G' * (\rho - \bar\rho), where G′G' is the Green's function of the periodic 3-point Laplacian on mean-free functions. The stencil (1,−2,1)(1, -2, 1) is symmetric under j↦−jj \mapsto -j, and the solution is unique, so G′G' is even. The centred difference is a convolution with the odd stencil c1=−1/(2Δx)c_1 = -1/(2\Delta x), c−1=1/(2Δx)c_{-1} = 1/(2\Delta x). So E=K∗(ρ−ρˉ)E = K * (\rho - \bar\rho) with K=c∗G′K = c * G' odd. An odd kernel sums to zero, so K∗ρˉ=0K * \bar\rho = 0 and E=K∗ρE = K * \rho. □\square

Claim 4 (momentum). Lines L4 and L6 leave P=∑pmpvpP = \sum_p m_p v_p unchanged, and line L7 does not change any velocity. So PP after line L12 equals PP at the start.

Proof. Line L4 changes PP by −(h/2)∑pmp(q/m)Ep=−(h/2)∑pqpEp-(h/2) \sum_p m_p (q/m) E_p = -(h/2) \sum_p q_p E_p, since mp(q/m)=qpm_p (q/m) = q_p. Line L6 changes it by h∑pqpEph \sum_p q_p E_p. In both cases EpE_p comes from a deposit and an interpolation with the same weights (lines L1 and L3, or L8 and L10) and from a field E=K∗ρE = K * \rho with an odd KK (Claim 3). By (B), ∑pqpEp=0\sum_p q_p E_p = 0. The background is a constant, which the field solve removes with the mean, so it does not change EE. ■\blacksquare

Complexity

In the real-RAM model, lines L1 and L8 cost Θ(N+M)\Theta(N + M), lines L2 and L9 cost Θ(M)\Theta(M), lines L3, L6, L7 and L10 cost Θ(N)\Theta(N), and line L11 costs Θ(M)\Theta(M). So TT steps cost Θ(T(N+M))\Theta(T (N + M)) time with Θ(M)\Theta(M) extra space beyond the particle arrays. In 2D and 3D with an FFT field solve the cost is Θ(T(N+Mlog⁡M))\Theta(T (N + M \log M)), and the particle part dominates in practice because NN is tens to hundreds of times MM.

Properties

  • Momentum conserving. With the same weights in deposit and interpolation and an odd field kernel, the total momentum is exact (Birdsall and Langdon, Part 2).
  • Energy approximately conserved. The total energy is not an exact invariant of the momentum-conserving scheme. It drifts slowly, and much faster when Δx\Delta x is large compared with λD\lambda_D, which is the finite grid instability or grid heating. Keep Δx≲λD\Delta x \lesssim \lambda_D (a rule of thumb, Birdsall and Langdon, Part 2).
  • Noisy. The field has statistical noise of relative size about Nc−1/2N_c^{-1/2}. Quiet starts reduce the initial noise, but the noise returns as particle orbits mix.
  • Time step limit. The leapfrog on a plasma oscillation is stable only for ωph<2\omega_p h < 2; for accuracy, ωph≈0.1\omega_p h \approx 0.1 to 0.2 is usual.
  • Collisionless by design. The grid smooths the force below a cell, so close collisions are much weaker than in a real plasma with the same number of particles per Debye sphere; collisions are added by a separate Monte Carlo step when needed.
  • Deterministic. With a fixed initial loading, the run has no random choices.

Variants and improvements

  • Electromagnetic PIC. The fields E\mathbf{E} and B\mathbf{B} are advanced on a staggered Yee grid, the particles with the Boris pusher. The current is deposited with charge-conserving weights, so that Gauss's law stays true without a separate correction.
  • Implicit and energy-conserving PIC. Implicit time steps allow ωph≫1\omega_p h \gg 1, and some implicit schemes conserve the total energy exactly at the cost of a nonlinear solve per step.
  • delta-f PIC. The particles carry only the deviation of ff from a known equilibrium, which cuts the noise when the deviation is small.
  • Higher order shapes. TSC and higher B-splines reduce aliasing and grid heating.
  • Monte Carlo collisions. Binary collision models between particles in the same cell add Coulomb collisions or collisions with a neutral gas.
  • Gyrokinetic PIC. For strongly magnetized plasmas, the particles follow gyrocentres, which removes the fast gyration from the time step.

When to use it

Use PIC when the physics is kinetic: when the velocity distribution is far from a Maxwellian, when wave-particle resonances matter (Landau damping, beam-plasma instabilities), or when particles are accelerated, as in laser-plasma interaction, magnetic reconnection and plasma sheaths. For a smooth ff in low dimension, a grid in phase space (a semi-Lagrangian Vlasov solver) has no statistical noise and is often more accurate per unit of cost. For large-scale behaviour close to equilibrium, a fluid model such as magnetohydrodynamics is far cheaper.

Pitfalls

  • Grid heating. With Δx\Delta x several times λD\lambda_D, a thermal plasma heats up on its own. Resolve the Debye length, or use an energy-conserving or a higher order scheme.
  • Too few particles per cell. With a few particles per cell, the noise hides small signals such as a 1 percent wave; a damping rate fitted to noise is meaningless.
  • Recurrence and beam instabilities from quiet starts. A start that loads particles in a few cold beams is quiet at first but can become unstable later, so check the result against a second loading.
  • Wrong start of the leapfrog. Without the half step back in line L4, the method is only first order and the phase of oscillations is wrong.
  • Mixing up the half steps for diagnostics. The kinetic energy must be computed from the mean of the velocities at n−1/2n - 1/2 and n+1/2n + 1/2, not from one of them.
  • Not neutral. A periodic Poisson problem needs zero net charge; forgetting the ion background makes the mean mode undefined.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

plasma_particle_in_cell.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/plasma-particle-in-cell/. The authors are listed in prov/ZFSET4.jsonl.
"""A 1D electrostatic particle-in-cell (PIC) code in the style of ES1.

Normalized units: epsilon_0 = 1, the electrons have charge -1 per unit
density and q/m = -1, and the ions are a fixed uniform background of
density 1. Then the plasma frequency is omega_p = 1 and the Debye length is
lambda_D = v_th, the thermal speed.

The domain is the periodic interval [0, L) with M grid points, dx = L / M.
N simulation particles ("macro-particles") each carry the charge q_p = -L / N
and the mass m_p = L / N, so that their mean density is 1.

Each step: deposit charge with cloud-in-cell weights, solve Gauss's law
dE/dx = rho on the grid, interpolate E to the particles with the same weights,
and push the particles with the leapfrog. Velocities live at half steps.

Cost per step: Theta(N + M) time and Theta(M) extra space.
"""

import math
from typing import Sequence


def deposit(xs: Sequence[float], qp: float, m: int, length: float, background: float = 1.0) -> list[float]:
    """Net charge density on the grid: particle charge by CIC plus the uniform ion background."""
    dx = length / m
    rho = [background] * m
    for x in xs:
        s = x / dx
        j = math.floor(s)
        w = s - j
        rho[j % m] += qp * (1 - w) / dx
        rho[(j + 1) % m] += qp * w / dx
    return rho


def gauss_field(rho: Sequence[float], length: float) -> list[float]:
    """Grid field with E_{j+1/2} - E_{j-1/2} = dx rho_j, zero mean, E_j = (E_{j-1/2} + E_{j+1/2}) / 2.

    This equals -(phi_{j+1} - phi_{j-1}) / (2 dx) for the mean-free solution of
    the 3-point Poisson equation -(phi_{j+1} - 2 phi_j + phi_{j-1}) / dx^2 = rho_j - mean(rho).
    """
    m = len(rho)
    dx = length / m
    mean = sum(rho) / m
    half, acc = [], 0.0
    for r in rho:
        acc += dx * (r - mean)
        half.append(acc)  # half[j] = E_{j+1/2} up to a constant
    shift = sum(half) / m
    half = [e - shift for e in half]
    return [(half[j] + half[j - 1]) / 2 for j in range(m)]


def interpolate(field: Sequence[float], xs: Sequence[float], length: float) -> list[float]:
    m = len(field)
    dx = length / m
    out = []
    for x in xs:
        s = x / dx
        j = math.floor(s)
        w = s - j
        out.append((1 - w) * field[j % m] + w * field[(j + 1) % m])
    return out


def field_energy(e: Sequence[float], length: float) -> float:
    return 0.5 * sum(v * v for v in e) * length / len(e)


def pic_run(
    xs: Sequence[float], vs: Sequence[float], m: int, length: float, h: float, steps: int, qm: float = -1.0
) -> tuple[list[float], list[float], list[float]]:
    """Run the PIC loop from positions x(0) and velocities v(0).

    Returns (x_steps, v_{steps-1/2}, W) where W[n] is the field energy at step n,
    n = 0, ..., steps.
    """
    n = len(xs)
    qp = -length / n  # electrons of mean density 1
    x = [p % length for p in xs]
    rho = deposit(x, qp, m, length)  # @line L1
    e = gauss_field(rho, length)  # @line L2
    ep = interpolate(e, x, length)  # @line L3
    v = [u - 0.5 * h * qm * a for u, a in zip(vs, ep)]  # @line L4
    energies = [field_energy(e, length)]
    for _ in range(steps):  # @line L5
        v = [u + h * qm * a for u, a in zip(v, ep)]  # @line L6
        x = [(p + h * u) % length for p, u in zip(x, v)]  # @line L7
        rho = deposit(x, qp, m, length)  # @line L8
        e = gauss_field(rho, length)  # @line L9
        ep = interpolate(e, x, length)  # @line L10
        energies.append(field_energy(e, length))  # @line L11
    return x, v, energies  # @line L12
test_plasma_particle_in_cell.py 76 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/plasma-particle-in-cell/. The authors are listed in prov/ZFSET4.jsonl.
import cmath
import math
import random

import pytest

from plasma_particle_in_cell import deposit, field_energy, gauss_field, interpolate, pic_run


def poisson_field_by_dft(rho, length):
    """Oracle: solve -(phi_{j+1} - 2 phi_j + phi_{j-1}) / dx^2 = rho_j - mean by a dense DFT, then E = -centred difference."""
    m = len(rho)
    dx = length / m
    rhat = [sum(rho[j] * cmath.exp(-2j * math.pi * j * k / m) for j in range(m)) for k in range(m)]
    phat = [0j] + [rhat[k] * dx * dx / (4 * math.sin(math.pi * k / m) ** 2) for k in range(1, m)]
    phi = [sum(phat[k] * cmath.exp(2j * math.pi * j * k / m) for k in range(m)).real / m for j in range(m)]
    return [-(phi[(j + 1) % m] - phi[j - 1]) / (2 * dx) for j in range(m)]


def test_page_example():
    assert deposit([0.5, 1.5, 2.5, 3.5], -1.0, 4, 4.0) == [0.0, 0.0, 0.0, 0.0]
    xs = [0.0, 1.5, 2.5, 3.5]
    rho = deposit(xs, -1.0, 4, 4.0)
    assert rho == [-0.5, 0.5, 0.0, 0.0]
    e = gauss_field(rho, 4.0)
    assert e == [-0.125, -0.125, 0.125, 0.125]
    assert interpolate(e, xs, 4.0) == [-0.125, 0.0, 0.125, 0.0]
    x, v, _ = pic_run(xs, [0.0] * 4, 4, 4.0, 0.5, 1)
    assert x == pytest.approx([0.015625, 1.5, 2.484375, 3.5], abs=1e-15)
    assert v == pytest.approx([0.03125, 0.0, -0.03125, 0.0], abs=1e-15)


def test_gauss_field_matches_poisson_oracle():
    rng = random.Random(1)
    for _ in range(40):
        m = rng.randint(1, 24)
        length = rng.uniform(0.5, 10)
        rho = [rng.uniform(-2, 2) for _ in range(m)]
        assert gauss_field(rho, length) == pytest.approx(poisson_field_by_dft(rho, length), abs=1e-9)


def test_neutral_plasma_has_zero_net_charge():
    rng = random.Random(2)
    for _ in range(50):
        m, length, n = rng.randint(2, 40), rng.uniform(1, 20), rng.randint(1, 300)
        xs = [rng.uniform(0, length) for _ in range(n)]
        rho = deposit(xs, -length / n, m, length)
        assert sum(rho) * length / m == pytest.approx(0, abs=1e-9)


def test_momentum_conserved_in_a_warm_plasma():
    rng = random.Random(3)
    length, m, n = 4 * math.pi, 32, 400
    xs = [rng.uniform(0, length) for _ in range(n)]
    vs = [rng.gauss(0, 1) for _ in range(n)]
    x, v, _ = pic_run(xs, vs, m, length, 0.1, 200)
    # the first half step changes the momentum by -(h/2) qm sum E_p = 0, so sum v is kept
    assert sum(v) == pytest.approx(sum(vs), abs=1e-10)


def test_cold_plasma_oscillates_at_the_plasma_frequency():
    length, n, m, h = 2 * math.pi, 256, 32, 0.05
    xs = [(i + 0.5) * length / n + 0.01 * math.cos((i + 0.5) * length / n) for i in range(n)]
    _, _, w = pic_run(xs, [0.0] * n, m, length, h, 400)
    # W(0) is close to the continuum field energy (1/2) delta^2 (L/2) of the displacement delta = 0.01
    assert w[0] == pytest.approx(0.5 * 0.01**2 * length / 2, rel=0.03)
    # the field energy oscillates at 2 omega_p = 2
    peaks = [i for i in range(1, len(w) - 1) if w[i] >= w[i - 1] and w[i] > w[i + 1]]
    period = (peaks[-1] - peaks[0]) * h / (len(peaks) - 1)
    assert math.pi / period == pytest.approx(1.0, abs=0.02)


def test_field_energy_formula():
    assert field_energy([1.0, -1.0, 2.0, 0.0], 2.0) == pytest.approx(0.5 * 6 * 0.5)

History

Dawson (1962) followed a large number of charged sheets in one dimension and measured Debye shielding and the Landau damping of the Fourier modes, which showed that a simulation with far fewer particles than a real plasma can reproduce its collective behaviour. Grid-based methods with charge assignment came next, and Birdsall and Fuss (1969) introduced the clouds-in-cells weighting that is now standard. Birdsall and Langdon (1985, reprinted 1991) wrote the standard text, with the programs ES1 and EM1, and Hockney and Eastwood (1981, second edition 1988) treated plasma simulation together with the other particle-mesh methods.

References

  1. Charles K. Birdsall and A. Bruce Langdon, Plasma Physics via Computer Simulation, Taylor and Francis, 2004 (reprint of the IOP edition of 1991), Part 1 (the electrostatic program ES1 and the electromagnetic program EM1) and Part 2 (the effects of the spatial grid and of the finite time step)
  2. Roger W. Hockney and James W. Eastwood, Computer Simulation Using Particles, Adam Hilger, 1988, Chapter 9 (plasma simulation)
  3. John Dawson, One-dimensional plasma model, The Physics of Fluids 5(4), 1962, 445-459, the charge sheet model and its measurements of Debye shielding and Landau damping

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example