FEM2D_POISSON_SPARSE Finite Element Method applied to 2D Poisson Equation Sparse Matrix Storage

FEM2D_POISSON_SPARSE is a MATLAB program which applies the finite element method to solve a form of Poisson's equation over an arbitrary triangulated two-dimensional region.

The linear system is created and stored using MATLAB's sparse matrix storage. The system is factored and solved by MATLAB, using sparse matrix solution techniques.

The geometry is entirely external to the program. The user specifies one file of nodal coordinates, and one file that describes the elements by indexing the node coordinates.

The program makes a default assumption that all boundary conditions correspond to Dirichlet boundary conditions. The user can adjust these boundary conditions (and even specify Dirichlet constraints on any variable at any node) by setting the appropriate data in certain user routines.

At the moment, Neumann conditions, if specified, must have a zero right hand side. The machinery to integrate a nonzero Neumann condition has not been set up yet.

Usage:

fem2d_poisson_sparse ( 'prefix' )
where 'prefix' is the common input filename prefix:
• 'prefix_nodes.txt' is the name of the node file;
• 'prefix_elements.txt' is the name of the element file;

Computational 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 elements that form a triangulation of the region. For the following ridiculously small example:

```        4----5
|\   |\
| \  | \
|  \ |  \
|   \|   \
1----2----3
```
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 element 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)  inside the region;
U(x,y) = G(x,y)  on the boundary.
```

To specify the right hand side function F(x,y), the coefficient functions H(x,y) and K(x,y) and the boundary condition function G(x,y), the user has to supply routines:

• function value = rhs ( x, y ) evaluates F(x,y), and is called at quadrature points in each element.
• function value = h_coef ( x, y ) evaluates H(x,y), and is called at quadrature points in each element.
• function value = k_coef ( x, y ) evaluates K(x,y), and is called at quadrature points in each element.
• function value = dirichlet_condition ( x, y ) evaluates G(X,Y), and is called at nodes on the boundary.

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.

Languages:

FEM2D_POISSON_SPARSE is available in a C++ version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

FEM2D_POISSON, a MATLAB program which solves Poisson's equation on a triangulated region, using the finite element method and a banded solver. In order to run, it requires user-supplied routines that define problem data.

FEM2D_POISSON_SPARSE_BAFFLE, a MATLAB library which defines the geometry of a rectangle channel containing 13 hexagonal baffles, as well as boundary conditions for a given Poisson problem, and is called by fem2d_poisson_sparse as part of a solution procedure.

FEM2D_POISSON_SPARSE_ELL, a MATLAB library which defines the geometry of an L-shaped region, as well as boundary conditions for a given Poisson problem, and is called by fem2d_poisson_sparse as part of a solution procedure.

FEM2D_POISSON_SPARSE_LAKE, a MATLAB library which defines the geometry of a lake-shaped region, as well as boundary conditions for a given Poisson problem, and is called by fem2d_poisson_sparse as part of a solution procedure.

MGMRES, a MATLAB library which applies the restarted Generalized Minimum Residual (GMRES) algorithm to solve a sparse linear system, by Lili Ju.

TRIANGULATION_ORDER3_CONTOUR, a MATLAB program which makes a contour plot of scattered data, or of data defined on an order 3 triangulation. In particular, it can display contour plots of scalar data output by fem2d_poisson or fem2d_poisson_sparse.

Reference:

1. Hans Rudolf Schwarz,
Finite Element Methods,
ISBN: 0126330107,
LC: TA347.F5.S3313.
2. Gilbert Strang, George Fix,
An Analysis of the Finite Element Method,
Cambridge, 1973,
ISBN: 096140888X,
LC: TA335.S77.
3. Olgierd Zienkiewicz,
The Finite Element Method,
Sixth Edition,
Butterworth-Heinemann, 2005,
ISBN: 0750663200,
LC: TA640.2.Z54

List of Routines:

• MAIN is the main routine for FEM2D_POISSON_SPARSE.
• ASSEMBLE_POISSON_SPARSE assembles the system for the Poisson equation.
• BASIS_11_T3: one basis at one point for the T3 element.
• DIRICHLET_APPLY_SPARSE accounts for Dirichlet boundary conditions.
• I4COL_COMPARE compares columns I and J of a integer array.
• I4COL_SORT_A ascending sorts an I4COL.
• I4COL_SWAP swaps columns I and J of a integer array of column data.
• I4MAT_TRANSPOSE_PRINT_SOME prints some of an I4MAT, transposed.
• R8MAT_PRINT_SOME prints out a portion of an R8MAT.
• R8MAT_TRANSPOSE_PRINT_SOME prints some of an R8MAT, transposed.
• R8VEC_PRINT_SOME prints "some" of an R8VEC.
• REFERENCE_TO_PHYSICAL_T3 maps a reference point to a physical point.
• RESIDUAL_POISSON evaluates the residual for the Poisson equation.
• SORT_HEAP_EXTERNAL externally sorts a list of items into ascending order.
• TIMESTAMP prints the current YMDHMS date as a timestamp.
• TRIANGLE_AREA_2D computes the area of a triangle in 2D.
• TRIANGULATION_NEIGHBOR_TRIANGLES determines triangle neighbors.