This repository will contain a simulation of the 2D heat equation in a rectangular and circular room. The temperatures of each wall will be chosen in beforehand, and a simulation using the Finite Difference Method (FDM) will show how the temperature develops in the room over time.
The heat equation is a partial differential equation that describes how the temperature
In order to simulate a system that satisifes the heat equation, we can make use of a numerical method called the finite-difference-method (FDM for short). We recall that the definition of the derivative comes from:
For small
For the second derivative we utilize the above approximation again to get:
In the 2D case, we can discretize our spatial coordinates with increments of
Let
For which we then can solve the temperature at position
Which is precisely what is utilized in the simulation. Notice that in the code,
The heat equation can also be simulated in a circular domain using polar coordinates. The partial differential equation in polar coordinates is given by:
To approximate the solution using the FDM, the domain is discretized into a grid in polar coordinates (
The wave equation is a partial differential equation that describes how waves propagate through a medium. The 2D wave equation is similiar to the heat equation, but possesses a second order temporal dependency. The equation in 2D can be stated as:
The procedure is similiar to what we did for the heat equation, but this time the second temporal dependency results in the expression
which solving for
The expression for
The wave equation can also be simulated in a circular domain using polar coordinates. The partial differential equation in polar coordinates is given by:
What follows here is almost identical to the results given by the heat equation, we just have to consider the second order temporal derivative. The discretization results in:
Hence we update the displacement
In order to use the code in the rectangular domain, use the following image as a reference.
The BC[i] corresponds to the i:th boundary condition in correspondance to the image above. rect[i] stands for the $i:th$ coordinate where for i=0,1 is used for x-coordinates and for i=2,3 is used for the y-coordinates.
The THETA_BOUNDS[i] are used to define the polar extension of the domain whereas R_BOUNDS[i] define the radial extension.
Below is an image of the produced result from the code itself:
This is an image from the simulation where the initial conditions for the heat equation is given by u(x,y,0) = 3-x^2-y^2 in a
10x10 rectangular room with boundary conditions given by 0 degrees across all walls.