This simulation runs a spatial SIR epidemic on a 150×150 grid, where each cell holds local fractions of Susceptible, Infected and Recovered population. Infection grows through the reaction terms dI/dt = β·S·I − γ·I, while a diffusion term D·∇²I lets infection spread to neighbouring cells. The grid is advanced with a forward-Euler scheme (time step 0.25) using a five-point Laplacian, producing travelling infection wavefronts of the Fisher–KPP type.
The sliders set transmission rate β, recovery rate γ, diffusivity D and simulation speed, and the basic reproduction number R₀ = β/γ updates live. Initial-condition buttons seed infection at the centre, in four foci, along an edge, or at random. This captures the spatial epidemiology that aspatial models miss: how geography, mixing and immunity shape real outbreaks of diseases such as measles, influenza or rabies fronts in wildlife.
What does this simulation actually show?
It shows a spatial epidemic spreading across a 2D grid of population. Blue cells are Susceptible, red are Infected and grey are Recovered. As the outbreak grows you see a red infection wavefront travel outward from the seed, leaving a recovered (grey) region behind it, much like a real epidemic moving through a connected population.
What is the SIR model behind it?
SIR splits a population into Susceptible, Infected and Recovered compartments. The local rules are dS/dt = −βSI, dI/dt = βSI − γI, and dR/dt = γI. Here each grid cell carries its own S, I and R fractions, and an extra diffusion term lets infection leak between neighbouring cells, turning the classic SIR model into a spatial one.
What is R₀ and why does it matter?
R₀ is the basic reproduction number, the average number of new infections caused by one infected individual in a fully susceptible population. In this model R₀ equals β/γ. If R₀ is greater than 1 the epidemic grows and a wavefront forms; if it is below 1 each case fails to replace itself and the outbreak fades out.
β (transmission, 0.05–0.80) sets how quickly contact between susceptible and infected cells produces new infections. γ (recovery, 0.01–0.30) sets how fast infected individuals recover and gain immunity. D (diffusivity, 0–0.60) controls how far infection spreads spatially each step; raising D makes a faster, smoother wavefront, while D = 0 confines infection to its starting cells.
The grid is updated with an explicit forward-Euler scheme using a fixed time step of 0.25. The diffusion term uses a standard five-point Laplacian (the cell minus the average of its four neighbours) with Neumann boundary conditions, so flux does not leave the edges. Values are clamped so that S, I and R stay between 0 and 1 for numerical stability.
When a reaction that grows a population is combined with diffusion, the result is a travelling wave of roughly constant shape and speed, first studied by Fisher and by Kolmogorov, Petrovsky and Piskunov. The infection front here behaves the same way: its speed scales with the square root of the product of diffusivity and the net growth rate, so larger D or larger R₀ both make the front advance faster.
Herd immunity is reached when enough of the population is immune that R₀ effectively drops below 1 and spread stalls. The classic threshold is 1 − 1/R₀. For example, with R₀ = 4 about 75% must be immune. In the simulation you can watch the wavefront slow and die out as the recovered (grey) fraction climbs past this level.
The four seeding options – centre, four foci, edge and random – change where and how broadly infection starts. Multiple foci or a full edge create several wavefronts that collide sooner, so the epidemic peaks faster. A single central seed gives the cleanest expanding circle, ideal for measuring wavefront speed against the parameters.
It is a faithful teaching version of spatial SIR dynamics and reproduces the right qualitative behaviour: the R₀ threshold, wave speed scaling and herd immunity. It simplifies reality by using a uniform grid, constant parameters, no births, deaths or latency, and homogeneous mixing within each cell, so it should be read as a conceptual tool rather than a calibrated forecast for any specific disease.
Spread depends on the local supply of susceptible cells. As the wavefront passes, it converts susceptibles into infected and then recovered, leaving immune ground behind. Once the infected region runs out of fresh susceptibles to invade, transmission βSI collapses, the infected fraction decays through recovery γI, and the outbreak burns out even when R₀ was large.
Spatial SIR models like this underpin how researchers study geographically structured outbreaks, from measles waves across cities to rabies fronts in fox populations and the spread of plant or crop diseases. They show why travel links, population density and immunity gaps matter, and why interventions that cut β or raise immunity can halt a wavefront before it crosses a region.