fd2d_heat_steady, a Python code which solves the steady state (time independent) heat equation in a 2D rectangular region.
The physical region, and the boundary conditions, are suggested by this diagram:
U = 0, Y = 1.0 +------------------+ | | U = 10 | | U = 100 X = 0.0 | | X = 2.0 +------------------+ U = 0, Y = 0.0
The region is covered with a grid of NX by NY nodes, and an NX by NY array U is used to record the temperature. The correspondence between array indices and locations in the region is suggested by giving the indices of the four corners:
I = NY +------------------+ | | J = 1 | | J = NX | | +------------------+ I = 1
The form of the steady heat equation is
- d/dx K(x,y) du/dx - d/dy K(x,y) du/dy = F(x,y)where K(x,y) is the heat conductivity, and F(x,y) is a heat source term.
By using a simple finite difference approximation, this single equation can be replaced by NX * NY linear equations in NX * NY variables; each equation is associated with one of the nodes in the mesh. Nodes long the boundary generate boundary condition equations, while interior nodes generate equations that approximate the steady heat equation.
The linear system is sparse, and can easily be solved directly in MATLAB.
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
fd2d_heat_steady is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.
fd1d_advection_lax_wendroff, a Python code which applies the finite difference method (FDM) to solve the time-dependent advection equation ut = - c * ux in one spatial dimension, with a constant velocity, using the Lax-Wendroff method to treat the time derivative.
fd1d_heat_explicit, a Python code which uses the finite difference method (FDM) and explicit time stepping to solve the time dependent heat equation in 1D.
fd1d_heat_implicit, a Python code which uses the finite difference method (FDM) and implicit time stepping to solve the time dependent heat equation in 1D.