FEM1D is a Python program which applies the finite element method (FEM) to a 1D linear two point boundary value problem (BVP), using piecewise linear basis functions.
The BVP to be solved is:
-u'' = x * ( x + 3 ) * exp ( x ) over the interval 0 < x < 1 u(0) = 0.0 u(1) = 0.0
The exact solution is:
u(x) = x * ( 1 - x ) * exp ( x )
A version of the finite element method is used. Six equally spaced nodes are defined, from 0.0 to 1.0, dividing the interval into 5 elements. At node I, we associate a "hat" function, or piecewise linear basis function, PSI(I)(X), which has the value 1 at that node, is 0 at all other nodes.
We look for an approximate solution to our problem of the form
UH(X) = sum ( 1 <= I <= 6 ) C(I) * PSI(I,X)so that now the problem becomes the determination of the unknown coefficients C.
We take the original BVP, multiply by test function PSI(J,X), integrate over the region, and apply integration by parts, to obtain a linear system of the form
A * C = FWe modify the first and last rows of the linear system to enforce the boundary conditions, then solve to determine the values of C.
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
FEM1D is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a Python version.
FEM1D_BVP_LINEAR, a Python program which applies the finite element method (FEM), with piecewise linear elements, to a two point boundary value problem (BVP) in one spatial dimension, and compares the computed and exact solutions with the L2 and seminorm errors.
FD1D_HEAT_EXPLICIT, a Python library which uses the finite difference method (FDM) and explicit time stepping to solve the time dependent heat equation in 1D.
FEM1D, a data directory which contains examples of 1D FEM files, three text files that describe a 1D finite element model;
FEM1D_BVP_QUADRATIC, a Python program 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 library 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.
FEM1D solves -u''=x*(1-x)*exp(x).
FEM1D_MODEL solves -u'' + u = x. It differs from FEM1D in using a more intuitive approach to assembling the system matrix.
You can go up one level to the Python source codes.