Electromagnetic waves: Maxwell's equations on a grid

A full-wave 2D solution of Maxwell's curl equations using the Yee FDTD scheme. Diffraction, interference, refraction and waveguide cut-off all emerge from the equations alone, with no ray or optics rules built in. Paint your own walls and lenses.

Electric field Ez(x, y, t)

Time-averaged intensity on the screen (dashed line in the field view)

FDTD simulationFraunhofer theory

Governing equations (TMz polarisation)

$$ \frac{\partial H_x}{\partial t} = -\frac{1}{\mu}\frac{\partial E_z}{\partial y},\qquad \frac{\partial H_y}{\partial t} = \frac{1}{\mu}\frac{\partial E_z}{\partial x},\qquad \frac{\partial E_z}{\partial t} = \frac{1}{\varepsilon}\left(\frac{\partial H_y}{\partial x}-\frac{\partial H_x}{\partial y}\right) $$

Yee's scheme (1966)

E and H live on staggered grids offset by half a cell, and are updated alternately (leapfrog) in time. This gives second-order accuracy, and the discrete fields satisfy \(\nabla\cdot\mathbf D = 0\) identically. Courant number \(S = c\Delta t/\Delta x = 0.5 < 1/\sqrt2\), so the scheme is stable. Metal (a perfect electric conductor) forces \(E_z = 0\). Open boundaries use a graded, impedance-matched absorbing layer (\(\sigma_m/\mu_0 = \sigma/\varepsilon_0\)), which absorbs more than 99.9% of outgoing energy (verified in the test suite).

The test suite also checks that a pulse travels at \(c\) to within 1%. With λ ≥ 12 cells, numerical dispersion is well below 1%.

Compare with theory

  • Double slit: bright fringes at \(d\sin\theta = m\lambda\), with intensity \(I \propto \cos^2\!\left(\frac{\pi d\sin\theta}{\lambda}\right)\mathrm{sinc}^2\!\left(\frac{\pi a\sin\theta}{\lambda}\right)\). The overlay draws the \(m\) lines, and the screen plot compares the full pattern.
  • Single slit: minima at \(a\sin\theta = m\lambda\). A narrow slit spreads the wave widely.
  • Slab: inside the dielectric the wavelength shrinks to \(\lambda/n\) with \(n=\sqrt{\varepsilon_r}\), and the reflected fraction is \(R = \left(\frac{n-1}{n+1}\right)^2\).
  • Waveguide: Ez must vanish on both plates, so the lowest mode needs \(\lambda < 2b\). Make λ longer than 2b and the wave dies out exponentially (evanescent).
  • Lens: a biconvex glass lens focuses a plane wave. The thin-lens estimate \(f = R/2(n-1)\) is marked; diffraction blurs the focal spot to about λ.

All lengths are in grid cells (Δx). The physics is scale-free: λ = 16 cells could be 16 mm microwaves or 160 nm light.