Heat Equation — 2D Diffusion Example

Your browser does not support the HTML5 canvas tag.
0.00 s
0.00 ms

Heat diffusion example

This example demonstrates a simple explicit finite-difference simulation of the 2D heat equation (diffusion). The simulation stores a temperature field on a lower-resolution grid for performance; the canvas displays the field upscaled.

Initial condition

The temperature is initially zero everywhere except a centered hot box (set to 100). You can restart the simulation with the Restart button.

Model (continuous)

The heat equation solved is \[ \frac{\partial T}{\partial t} = D \nabla^2 T, \] where \(D\) is the diffusivity.

Numerical method

Space is discretized on a uniform Cartesian grid with spacing \(\Delta x\) (we assume \(\Delta x = \Delta y\) here). Let \(T_{i,j}^n\) denote the temperature at grid cell \((i,j)\) at time step \(n\). The continuous PDE is \[ \frac{\partial T}{\partial t} = D \nabla^2 T, \] which we discretize using a 5-point central difference for the Laplacian and forward-Euler in time (explicit): \[ \nabla^2 T\big|_{i,j} \approx \frac{T_{i+1,j} + T_{i-1,j} + T_{i,j+1} + T_{i,j-1} - 4T_{i,j}}{\Delta x^2}. \] The time-stepping update is then \[ T_{i,j}^{n+1} = T_{i,j}^n + \Delta t \; D \; \frac{T_{i+1,j}^n + T_{i-1,j}^n + T_{i,j+1}^n + T_{i,j-1}^n - 4T_{i,j}^n}{\Delta x^2}. \]

Note on stability

Because the integrator is explicit, the time step must be small enough to satisfy the CFL-like condition for stability roughly: \(\Delta t \le \frac{\Delta x^2}{4D}\). If you increase \(D\) or \(\Delta t\) you may see the simulation blow up or become noisy.