fem2d_heat, a C++ code which applies the finite element method (FEM) to solve a form of the time-dependent heat equation over an arbitrary triangulated region.
The computational region is initially unknown by the program. The user specifies it by preparing a file containing the coordinates of the nodes, and a file containing the indices of nodes that make up triangles that form a triangulation of the region.
Normally, the user does not type in this information by hand, but has a program fill in the nodes, and perhaps another program that constructs the triangulation. However, in the simplest case, the user might construct a very crude triangulation by hand, and have TRIANGULATION_REFINE refine it to something more reasonable.
For the following ridiculously small example:
10-11-12 |\ |\ | \ | \ 6 7 8 9 | \| \ 1-2--3--4-5the node file would be:
0.0 0.0 1.0 0.0 2.0 0.0 3.0 0.0 4.0 0.0 0.0 1.0 1.0 1.0 2.0 1.0 3.0 1.0 0.0 2.0 1.0 2.0 2.0 2.0and the triangle file would be
1 3 10 2 7 6 3 5 12 4 9 8 12 10 3 11 7 8
The program is set up to handle the time dependent heat equation with a right hand side function, and nonhomogeneous Dirichlet boundary conditions. The state variable U(T,X,Y) is then constrained by:
Ut - ( Uxx + Uyy ) + K(x,y,t) * U = F(x,y,t) in the region U = G(x,y,t) on the boundary U = H(x,y,t) at initial time TINIT.
To specify the right hand side function F(x,y,t), the linear coefficient K(x,y,t), the boundary condition function G(x,y,t), and the initial condition H(x,y,t), the user has to supply a file, perhaps called myprog.C, containing several functions:
The program is also able to write out a file containing the solution value at every node. This file may be used to create contour plots of the solution.
g++ fem2d_heat.cpp myprog.cppwhere prefix is the common file prefix:
mv a.out fem2d_heat
fem2d_heat prefix
The computer code and data files described and made available on this web page are distributed under the MIT license
fem2d_heat is available in a C++ version and a FORTRAN90 version and a MATLAB version.
FD2D_HEAT_STEADY, a C++ code which uses the finite difference method (FDM) to solve the steady (time independent) heat equation in 2D.
FEM1D_HEAT_STEADY, a C++ code which uses the finite element method to solve the steady (time independent) heat equation in 1D.
STOCHASTIC_HEAT2D, a C++ code which implements a finite difference method (FDM) for the steady (time independent) 2D heat equation, with a stochastic heat diffusivity coefficient, using gnuplot to illustrate the results.