DiffractionVizzard · Open-source browser-based simulation suite
Source CodeDocumentation
Launch 2D Simulation → ← Electromagnetic Waves
Module 02 · Electromagnetic Waves · 2D Waves

2D Electromagnetic Waves

Solve the 2D scalar Helmholtz equation in the browser using finite-difference methods. Visualise how waves scatter, diffract, and interfere around obstacles with arbitrary geometry.

Launch 2D Simulation → ← Electromagnetic Waves
2D Helmholtz wave scattering illustration

The Helmholtz Equation

Time-harmonic electromagnetic fields at angular frequency ω satisfy the Helmholtz equation, a second-order elliptic PDE that governs the spatial distribution of the wave amplitude u:

∇²u + k²u = 0, k = ω/c

Here k is the wavenumber and c is the wave speed in the medium. In two dimensions this equation describes transverse-electric or transverse-magnetic propagation in a cross-sectional plane, making it directly applicable to optical waveguides, acoustic ducts, and microwave cavities.

Scattering and Boundary Conditions

When a plane wave uinc = eikx encounters a rigid or absorbing obstacle, the total field u = uinc + usc must satisfy Dirichlet or Neumann boundary conditions on the scatterer surface. Away from the obstacle the scattered field usc must satisfy the Sommerfeld radiation condition:

lim r→∞ √r (∂u_sc/∂r − ik u_sc) = 0

This ensures energy radiates outward and the domain can be truncated with a perfectly matched layer (PML) — a gradually absorbing sponge region that eliminates spurious reflections from the computational boundary.

In the Simulation

The simulator discretises the 2D domain with a uniform grid and assembles the sparse linear system arising from 5-point finite differences. An obstacle can be drawn interactively by clicking and dragging on the canvas. Adjustable parameters include:

Wavenumber k (controlling wavelength and diffraction regime) · Incident angle (rotating the plane-wave direction) · PML thickness (controlling boundary absorption) · Colour map: real part, imaginary part, magnitude, or phase.
The system is solved entirely in the browser via a compiled WebAssembly module — no server required.

Observe how longer wavelengths diffract around small obstacles while shorter wavelengths cast sharp geometric shadows. Resonant cavities, channel waveguides, and gratings all emerge naturally from simple geometric configurations.