This project uses NumPy and finite difference numerical analysis to model the spread and dissipation of heat throughout a grid.
- 25x25 grid-based heat diffusion simulation
- Click and paint mode for adding heat
- Adjustable thermal diffusivity and brush size
- Insulated boundary
- Visual grid using Matplotlib
Heat always spreads from a higher temperature region to a lower temperature region. The speed at which heat spreads depends on the difference in temperature between the two regions. Heat transfers faster the greater the difference between the temperatures. This transfer happens until equilibrium, when heat is distributed equally. This can be modeled by using the partial differential heat equation, which solves for the rate at which heat transfers:
$\frac{\partial u}{\partial t} = \alpha (\frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2})$
A way of approximating the solutions to this equation is by using finite difference. Finite difference approximates derivatives by using the distance between certain points. The form of finite difference this code uses is called FTCS (forward-time-centered scheme). In this method, future states are approximated based on the current state, and the second derivative is approximated by using neighboring points in the x and y directions. Using this method, and by assuming that
Where
At each update of the simulation, this equation is used to see how much the temperature at a point should change. More information on the math behind this can be found in the links at the bottom of this page.
The simulation uses an insulated boundary which prevents heat from leaking out. This is done by using an additional 27x27 grid and copying the original 25x25 to its center. The values of the border cells of the larger grid are made equal to the border values of the original grid, preventing heat from flowing across the boundary.
The interface features multiple sliders and buttons, including:
Switch between click mode (Click to add heat to individual cells) and paint mode (Hold and move mouse to add heat to a wide area).
Change the size of area filled while in paint mode.
Choose how quickly the heat spreads throughout the grid. Thermal diffusivity is limited to a range that keeps the simulation stable.
How much heat to add in each cell while clicking.
Add heat in a random pattern to 35% of cells.
Download the latest release and run the executable Heat.Dissipation.exe.
or
Clone the repository and run pip install -r requirements.txt to install all required libraries.