66 | Heat diffusion example
67 |
68 | This example demonstrates a simple explicit finite-difference simulation of the 2D heat equation (diffusion).
69 | The simulation stores a temperature field on a lower-resolution grid for performance; the canvas displays the field upscaled.
70 |
71 |
72 | Initial condition
73 | The temperature is initially zero everywhere except a centered hot box (set to 100). You can restart the simulation with the Restart button.
74 |
75 | Model (continuous)
76 | The heat equation solved is
77 | \[ \frac{\partial T}{\partial t} = D \nabla^2 T, \]
78 | where \(D\) is the diffusivity.
79 |
80 | Numerical method
81 | 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
82 | \[ \frac{\partial T}{\partial t} = D \nabla^2 T, \]
83 | which we discretize using a 5-point central difference for the Laplacian and forward-Euler in time (explicit):
84 |
85 | \[ \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}. \]
86 | The time-stepping update is then
87 | \[ 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}. \]
88 |
89 | Note on stability
90 | 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.
91 |
92 | |
93 |