🚦 LWR Traffic Flow

v_max 30 m/s
ρ_max 120 veh/km
Initial ρ 40 veh/km
Sim speed

Wave speed c
Flow Q
Time0 s
ρ=0 ρ_max

About this simulation

This simulation solves the Lighthill-Whitham-Richards (LWR) continuum traffic model on a periodic ring road: the conservation law ∂ρ/∂t + ∂F(ρ)/∂x = 0 tracks vehicle density ρ as a compressible fluid. Speed follows the Greenshields relation v(ρ) = v_max·(1 − ρ/ρ_max), giving a parabolic flow-density fundamental diagram, and each cell interface is updated with a Godunov finite-volume scheme using a supply-demand flux G = min(D(ρ_L), S(ρ_R)). The result is a real-time space-time (Hovmöller) diagram showing kinematic waves and shockwaves emerging spontaneously from noise or an injected incident.

🔬 What it shows

A 1 km ring road discretised into 200 cells, coloured by density from free-flow (blue) to jammed (red). The Hovmöller panel stacks each time-step's density profile so diagonal stripes reveal whether waves drift forward (low density) or backward (high density) relative to traffic, while a small fundamental-diagram plot tracks the current operating point on the ρ–Q curve.

🎮 How to use

Drag v_max (10–60 m/s) to set free-flow speed, ρ_max (40–200 veh/km) to set jam density, and Initial ρ (5–110 veh/km) to seed the starting traffic state. Sim speed (0.25×–8×) scales playback rate. Pause/Reset control the run, and Add Incident injects a localised density spike near one-third of the road to trigger a visible backward-propagating shockwave.

💡 Did you know?

The stop-and-go "phantom traffic jams" you hit on a clear motorway with no crash or junction are a real prediction of this model: once density crosses the critical value ρ_max/2, the wave speed turns negative and any small braking perturbation grows into a jam that crawls backward through the traffic even as every driver keeps inching forward.

Frequently asked questions

What does the LWR model actually simulate?

It treats traffic as a continuous fluid rather than individual cars, governed by the conservation law ∂ρ/∂t + ∂F(ρ)/∂x = 0, where ρ is vehicle density and F(ρ) = ρ·v(ρ) is the flux (flow rate). This macroscopic view, developed by Lighthill, Whitham and Richards in the 1950s, predicts congestion patterns without tracking every vehicle.

What is the Greenshields relation used here?

Greenshields' 1935 formula sets speed as v(ρ) = v_max·(1 − ρ/ρ_max), linearly decreasing from free-flow speed at zero density to zero at jam density. Multiplying by ρ gives a parabolic flux curve peaking at ρ_max/2, which is exactly the fundamental-diagram plot shown in the simulation's corner panel.

Why do traffic jams move backward?

The kinematic wave speed is c = dF/dρ = v_max·(1 − 2ρ/ρ_max). Below half the jam density this is positive (waves drift forward with traffic); above it, c turns negative, so a density disturbance propagates upstream against the direction cars are travelling — visible as backward-leaning stripes in the Hovmöller diagram.

How does the Godunov scheme keep the simulation stable?

Each cell boundary flux is computed as G = min(D(ρ_L), S(ρ_R)), the smaller of the left cell's demand and the right cell's supply, which correctly resolves shocks and rarefactions without oscillation. The time step is automatically capped by the CFL condition (Δt ≈ 0.45·Δx/v_max) so the scheme never advances faster than information can physically travel between cells.

What happens when I click Add Incident?

It injects a density spike into a short segment about one-third of the way around the ring, mimicking a lane closure or crash. Downstream of the spike density drops (a rarefaction fan), while upstream a sharp shockwave forms and crawls backward — the same Rankine-Hugoniot shock behaviour that causes real motorway tailbacks to appear well before the actual obstruction.