fem2d_bvp_linear, a Python code which applies the finite element method, with piecewise bilinear elements, to a 2D boundary value problem over a rectangle.

The boundary value problem (BVP) that is to be solved has the form:

        - d/dx ( a(x,y) * du/dx ) - d/dy ( a(x,y) * du/dy ) + c(x,y) * u(x,y) = f(x,y)
This equation holds in the interior of some rectangle R. The functions a(x,y), c(x,y), and f(x,y) are given.

Zero boundary conditions are imposed on the boundary of R.

To compute a finite element approximation, the X and Y extents of R are gridded with NX and NY equally spaced values, respectively. This defines NX*NY nodes, and divides R into (NX-1)*(NY-1) rectangular elements. At the K-th node, (X(I),Y(J)), a piecewise bilinear basis function PHI(K)(X,Y) is defined. The solution will be represented as a linear combination of these basis functions. An integral form of the BVP is written, in which the differential equation is multiplied by each basis function, and integration by parts is used to simplify the integrand.


The computer code and data files described and made available on this web page are distributed under the MIT license


fem2d_bvp_linear is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and codes:

fem1d, a Python code which applies the finite element method (FEM) to a 1D linear two point boundary value problem (BVP).

fem1d_bvp_quadratic, a Python code which applies the finite element method (FEM), with piecewise quadratic elements, to a two point boundary value problem (BVP) in one spatial dimension.

fem1d_classes, a Python code which defines classes useful for solving a boundary value problem (BVP) of the form u''+2u'+u=f in 1 spatial dimension, using the finite element method (FEM), by Mike Sussman.

Source Code:

Last revised on 15 October 2014.