pwl_product_integral, a C++ code which calculates the exact value of the integral of the product of two piecewise linear functions F(X) and G(X).
The piecewise linear function F(X) is defined by
The piecewise linear function G(X) is defined similarly, and there is no requirement that G(X) uses the same nodes as F(X), or the same number of nodes.
The task, then, is to determine the value of
Integral ( A <= X <= B ) F(X) * G(X) dxThis value can be determined exactly, by breaking the interval ot integration into subintervals over which F(X) and G(X) are simple linear functions.
In finite element programs over 1-dimensional geometries, integrals like this may occur when assembling the stiffness matrix, but these integrals are generally treated using quadrature.
A more appropriate use for this function occurs when coarsening a finite element solution, or constructing a piecewise linear least squares finite element approximant to data that is regarded as a piecewise linear function.
In case 1, we treat the original finite element solution as the function F(X), and in case 2, we treat the data as a finite element function whose mesh is implicit in the X coordinates of the given data.
Our G_X is, in case 1, the coarse mesh and in case 2 the given mesh. To determine the finite element coefficient U(I) on this mesh, we must integrate our data function F(X) against the I-th basis function, which in this case is simply the I-th "hat function. So to use our formula for G(X), we set G_V(1:G_NUM) to 0, except that G_V(I) = 1, and compute
U(I) = Integral ( G_X(I-1) <= X <= G_X(I+1) ) F(X) * G(X) dxDoing this for I from 1 to G_NUM allows us to compute the coefficients of the coarsened solution (case 1) or the least squares approximant to the piecewise linear function representing the data F.
The computer code and data files described and made available on this web page are distributed under the MIT license
pwl_product_integral is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.
FEM, a data directory which contains a description and examples of files that describe a finite element model.
FEM1D, a C++ code which applies the finite element method to a 1D linear two point boundary value problem.
FEM1D_ADAPTIVE, a C++ code which applies the finite element method to a 1D linear two point boundary value problem using adaptive refinement to improve the solution.
FEM1D_NONLINEAR, a C++ code which applies the finite element method to a 1D nonlinear two point boundary value problem.
FEM1D_PMETHOD, a C++ code which applies the p-method version of the finite element method to a linear two point boundary value problem in a 1D region.
FEM1D_PROJECT, a C++ code which projects data into a finite element space, including the least squares approximation of data, or the projection of a finite element solution from one mesh to another.
FEM1D_SAMPLE, a C++ code which samples a scalar or vector finite element function of one variable, defined by FEM files, returning interpolated values at the sample points.