FEM2D_HEAT_RECTANGLE
Time Dependent 2D Heat Equation
Finite Elements, Rectangular Region
FEM2D_HEAT_RECTANGLE
is a FORTRAN90 program which
solves the timedependent 2D heat equation
using the finite element method in space, and a method of
lines in time with the backward Euler approximation for the
time derivative, over a rectangular region with a uniform grid.
The computational region is a rectangle, with homogenous Dirichlet
boundary conditions applied along the boundary. The state variable
U(X,Y,T) is then constrained by:
Ut  ( Uxx + Uyy ) = F(x,y,t) in the box;
U(x,y,t) = G(x,y,t) for (x,y) on the boundary;
U(x,y,t) = H(x,y,t) for t = t_init.
The computational region is first covered with an NX by NY
rectangular array of points, creating (NX1)*(NY1) subrectangles.
Each subrectangle is divided into two triangles, creating a total
of 2*(NX1)*(NY1) geometric "elements". Because quadratic basis
functions are to be used, each triangle will be associated not only
with the three corner nodes that defined it, but with three extra
midside nodes. If we include these additional nodes, there are
now a total of (2*NX1)*(2*NY1) nodes in the region.
We now assume that, at any fixed time b, the unknown function
U(x,y,t) can be represented as a linear combination of the basis
functions associated with each node. The value of U at the boundary
nodes is obvious, so we concentrate on the NUNK interior nodes where
U(x,y,t) is unknown. For each node I, we determine a basis function
PHI(I)(x,y), and evaluate the following finite element integral:
Integral ( Ux(x,y,t) * dPHIdx(I)(x,y) + dUdy(x,y,t) * dPHIdy(I)(x,y) ) =
Integral ( F(x,y,t) * PHI(I)(x,y)
The time derivative is handled by the backward Euler approximation.
The program allows the user to supply two routines:

FUNCTION RHS ( X, Y, TIME ) returns the right hand side
F(x,y,time) of the heat equation.

SUBROUTINE EXACT_U ( NODE_NUM, NODE_XY, TIME, U_EXACT)
returns the exact solution U_EXACT evaluated at each of
the NODE_NUM points whose coordinates are stored in
NODE_XY(1:2,1:NODE_NUM), at time TIME.
There are a few variables that are easy to manipulate. In particular,
the user can change the variables NX and NY in the main program,
to change the number of nodes and elements. The variables (XL,YB)
and (XR,YT) define the location of the lower left and upper right
corners of the rectangular region, and these can also be changed
in a single place in the main program.
The program writes out a file containing an Encapsulated
PostScript image of the nodes and elements, with numbers.
Unfortunately, for values of NX and NY over 10, the plot is
too cluttered to read. For lower values, however, it is
a valuable map of what is going on in the geometry.
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.
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
FEM2D_HEAT_RECTANGLE is available in
a C++ version and
a FORTRAN90 version and
a MATLAB version.
Related Data and Programs:
FEM2D,
a data directory which
contains examples of 2D FEM files,
text files that describe a 2D finite element geometry
and associated nodal values;
FEM2D_HEAT,
a FORTRAN90 program which
uses the finite element method and the backward Euler method to solve the
2D timedependent heat equation on an arbitrary triangulated region.
FEM2D_POISSON_RECTANGLE,
a FORTRAN90 program which
solves Poisson's equation on a triangulated square, using the finite element
method.
Author:
Janet Peterson.
Reference:

Hans Rudolf Schwarz,
Finite Element Methods,
Academic Press, 1988,
ISBN: 0126330107,
LC: TA347.F5.S3313.

Gilbert Strang, George Fix,
An Analysis of the Finite Element Method,
Cambridge, 1973,
ISBN: 096140888X,
LC: TA335.S77.

Olgierd Zienkiewicz,
The Finite Element Method,
Sixth Edition,
ButterworthHeinemann, 2005,
ISBN: 0750663200,
LC: TA640.2.Z54
Source Code:
Examples and Tests:
Data files created by the program:

fem2d_heat_rectangle.txt,
the printed output from a run;

nodes.png,
a PNG image of
the 49 nodes;

nodes.txt,
a text file containing a list, for each node, of its X and Y
coordinates;

elements.png,
a PNG image of
the 32 elements;

elements.txt,
a text file containing a list, for each element, of the six
nodes that compose it;

time.txt,
a text file containing the solution times;

u0000.txt,
the solution U at time step 0;

u0001.txt,
the solution U at time step 1;

u0002.txt,
the solution U at time step 2;

u0003.txt,
the solution U at time step 3;

u0004.txt,
the solution U at time step 4;

u0005.txt,
the solution U at time step 5;

u0006.txt,
the solution U at time step 6;

u0007.txt,
the solution U at time step 7;

u0008.txt,
the solution U at time step 8;

u0009.txt,
the solution U at time step 9;

u0010.txt,
the solution U at time step 10;
The MATLAB program CONTOUR_SEQUENCE4 can make contour
plots from the sequence of solutions:

u0000.png,
the solution U at time step 0;

u0001.png,
the solution U at time step 1;

u0002.png,
the solution U at time step 2;

u0003.png,
the solution U at time step 3;

u0004.png,
the solution U at time step 4;

u0005.png,
the solution U at time step 5;

u0006.png,
the solution U at time step 6;

u0007.png,
the solution U at time step 7;

u0008.png,
the solution U at time step 8;

u0009.png,
the solution U at time step 9;

u0010.png,
the solution U at time step 10;
List of Routines:

MAIN is the main program for FEM2D_HEAT_RECTANGLE.

ADJUST_BACKWARD_EULER adjusts the system for the backward Euler term.

ADJUST_BOUNDARY modifies the linear system for boundary conditions.

AREA_SET sets the area of each element.

ASSEMBLE assembles the coefficient matrix A and right hand side F.

BANDWIDTH determines the bandwidth of the coefficient matrix.

COMPARE compares the exact and computed solution at the nodes.

DGB_FA performs a LINPACKstyle PLU factorization of an DGB matrix.

DGB_PRINT_SOME prints some of a DGB matrix.

DGB_SL solves a system factored by DGB_FA.

ELEMENT_WRITE writes the element information to a text file.

ERRORS calculates the error in the L2 norm and H1 seminorm.

EXACT_U calculates the exact solution.

FILE_NAME_INC increments a partially numeric filename.

GET_UNIT returns a free FORTRAN unit number.

GRID_T6 produces a grid of pairs of 6 node triangles.

I4VEC_PRINT_SOME prints "some" of an I4VEC.

NODE_BOUNDARY_SET assigns an unknown value index at each node.

NODES_PLOT plots a pointset.

NODES_WRITE writes the nodes to a file.

QBF evaluates the quadratic basis functions.

QUAD_A sets the quadrature rule for assembly.

QUAD_E sets up the quadrature rule for error integration.

R8VEC_PRINT_SOME prints "some" of an R8VEC.

RHS gives the righthand side of the differential equation.

SOLUTION_WRITE writes the solution to a file.

TIMESTAMP prints the current YMDHMS date as a time stamp.

TRIANGULATION_ORDER6_PLOT plots a 6node triangulation of a pointset.

XY_SET sets the XY coordinates of the nodes.
You can go up one level to
the FORTRAN90 source codes.
Last revised on 23 December 2010.