Solving the heat equation in 2D numerically with a forward in time and centered in space scheme (FTCS) and later visualizing the predicted diffusion of heat given different initial distributions and diffusivity values. The spatial domain is a square and the boundary conditions are Dirichlet type but the code can be easily adapted to any problem by just making a change in one line.
The model describing the temperature of a 2D object (or 3D which is short enough) is :
with
where
Important note : For a uniform spatial mesh, the stability condition for the heat equation requires that $\ \Delta t < \frac{\Delta x^2}{4D} $ .
Some snapshots in time of the temperature distribution (seen from above) with diffusivity coefficient