FEM2D_POISSON
Finite Element Solution of Poisson's Equation
on a Triangulated Region
FEM2D_POISSON
is a C++ program which
applies the finite element method to solve
a form of Poisson's equation over an arbitrary triangulated region.
The computational region is 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:
45
\ \
 \  \
 \  \
 \ \
123
the node file would be:
0.0 0.0
1.0 0.0
2.0 0.0
0.0 1.0
1.0 1.0
and the triangle file would be
1 2 4
5 4 2
2 3 5
The program is set up to handle the linear Poisson
equation with a right hand side function, and nonhomogeneous
Dirichlet boundary conditions. The state variable
U(X,Y) is then constrained by:
 DEL H(x,y) DEL U(x,y) + K(x,y) * U(x,y) = F(x,y) in the region
U(x,y) = G(x,y) on the boundary
To specify the right hand side function F(x,y), the linear
coefficients H(x,y) and K(x,y) and the boundary condition function G(x,y),
the user has to modify a file containing three routines,

void rhs ( int node_num, double node_xy[], double node_rhs[] )
evaluates the right hand side of function F(x,y) at a list of
nodes.

void h_coef ( int node_num, double node_xy[], double node_h[] )
evaluates the coefficient function H(x,y) at a list of nodes.

void k_coef ( int node_num, double node_xy[], double node_k[] )
evaluates the coefficient function K(x,y) at a list of nodes.

void dirichlet_condition ( int node_num, double node_xy[], double node_g[] )
evaluates the Dirichlet boundary condition G(X,Y) at a list of nodes.
To run the program, the user compiles the user routines,
links them with FEM2D_POISSON, and runs the executable.
The program writes out a file containing an Encapsulated
PostScript image of the nodes and elements, with numbers.
If there are too many nodes, the plot may be 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.
Usage:
The user must create an executable by compiling the user routines
and linking them with the main program, perhaps by commands like:
g++ c fem2d_poisson.C
g++ c user.C
g++ fem2d_poisson.o user.o
mv a.out fem2d_poisson
Assuming the executable program is called "fem2d_poisson", then
the program is executed by
fem2d_poisson prefix
where prefix is the common filename prefix, so that

prefix_nodes.txt, is a file containing the node coordinates;

prefix_elements.txt, is a file listing the 3 nodes that
make up each element;
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
FEM2D_POISSON is available in
a C++ version and
a FORTRAN90 version and
a MATLAB version.
Related Data and Programs:
FEM2D_POISSON_CG,
a C++ program which
solves Poisson's equation on a triangulated region,
using the finite element method, sparse storage, and a conjugate gradient solver.
FEM2D_POISSON_ELL,
a C++ library which
defines the geometry of an Lshaped region, as well as boundary
conditions for a given Poisson problem, and is called by FEM2D_POISSON
as part of a solution procedure.
FEM2D_POISSON_LAKE,
a C++ library which
defines the geometry of a lakeshaped region, as well as boundary
conditions for a given Poisson problem, and is called by FEM2D_POISSON
as part of a solution procedure.
FEM2D_POISSON_SPARSE,
a C++ program which
solves the steady (time independent) Poisson equation on an arbitrary
2D triangulated region using a version of GMRES for a sparse solver.
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:
List of Routines:

MAIN is the main program for FEM2D_POISSON.

ASSEMBLE_POISSON assembles the system for the Poisson equation.

BANDWIDTH determines the bandwidth of the coefficient matrix.

BASIS_ONE_T3 evaluates basis functions for a linear triangular element.

CH_CAP capitalizes a single character.

CH_EQI is true if two characters are equal, disregarding case.

CH_TO_DIGIT returns the integer value of a base 10 digit.

DGB_FA performs a LINPACKstyle PLU factorization of a DGB matrix.

DGB_MXV multiplies a DGB matrix times a vector.

DGB_PRINT_SOME prints some of a DGB matrix.

DGB_SL solves a system factored by DGB_FA.

DIRICHLET_APPLY accounts for Dirichlet boundary conditions.

FILE_COLUMN_COUNT counts the columns in the first line of a file.

FILE_ROW_COUNT counts the number of row records in a file.

I4_MAX returns the maximum of two I4's.

I4_MIN returns the smaller of two I4's.

I4_MODP returns the nonnegative remainder of integer division.

I4_WRAP forces an integer to lie between given limits by wrapping.

I4COL_COMPARE compares columns I and J of an I4COL.

I4COL_SORT_A ascending sorts the columns of an I4COL.

I4COL_SWAP swaps two columns of an I4COL.

I4MAT_DATA_READ reads data from an I4MAT file.

I4MAT_HEADER_READ reads the header from an I4MAT file.

I4MAT_TRANSPOSE_PRINT_SOME prints some of an I4MAt, transposed.

LVEC_PRINT prints a logical vector.

POINTS_PLOT plots a pointset.

QUAD_RULE sets the quadrature rule for assembly.

R8_ABS returns the absolute value of an R8.

R8_HUGE returns a "huge" R8.

R8_NINT returns the nearest integer to an R8.

R8MAT_DATA_READ reads the data from an R8MAT file.

R8MAT_HEADER_READ reads the header from an R8MAT file.

R8MAT_TRANSPOSE_PRINT_SOME prints some of an R8MAT, transposed.

R8MAT_WRITE writes an R8MAT file.

R8VEC_AMAX returns the maximum absolute value in an R8VEC.

R8VEC_PRINT_SOME prints "some" of an R8VEC.

REFERENCE_TO_PHYSICAL_T3 maps reference points to physical points.

RESIDUAL_POISSON evaluates the residual for the Poisson equation.

S_LEN_TRIM returns the length of a string to the last nonblank.

S_TO_I4 reads an I4 from a string.

S_TO_I4VEC reads an I4VEC from a string.

S_TO_R8 reads an R8 from a string.

S_TO_R8VEC reads an R8VEC from a string.

S_WORD_COUNT counts the number of "words" in a string.

SOLUTION_EVALUATE evaluates the solution at a point in a element.

SORT_HEAP_EXTERNAL externally sorts a list of items into ascending order.

TIMESTAMP prints the current YMDHMS date as a time stamp.

TRIANGLE_AREA_2D computes the area of a triangle in 2D.

TRIANGULATION_ORDER3_BOUNDARY_NODE indicates nodes on the boundary.

TRIANGULATION_ORDER3_PLOT plots a triangulation of a set of nodes.
You can go up one level to
the C++ source codes.
Last revised on 06 December 2010.