The major difference between deriving variational formulations in 2D and 3D compared to 1D is the rule for integrating by parts. A typical second-order term in a PDE may be written in dimension-independent notation as
The explicit forms in a 2D problem become
and
We shall continue with the latter operator as the form arises from just setting \(a=1\).
The general rule for integrating by parts is often referred to as Green’s first identity:
where \(\partial\Omega\) is the boundary of \(\Omega\) and \(\partial u/\partial n = \boldsymbol{n}\cdot\nabla u\) is the derivative of \(u\) in the outward normal direction, \(\boldsymbol{n}\) being an outward unit normal to \(\partial\Omega\). The integrals \(\int_\Omega (){\, \mathrm{d}x}\) are area integrals in 2D and volume integrals in 3D, while \(\int_{\partial\Omega} (){\, \mathrm{d}s}\) is a line integral in 2D and a surface integral in 3D.
Let us divide the boundary into two parts:
- \(\partial\Omega_N\), where we have Neumann conditions \(-a\frac{\partial u}{\partial n} = g\), and
- \(\partial\Omega_D\), where we have Dirichlet conditions \(u = u_0\).
The test functions \(v\) are required to vanish on \(\partial\Omega_D\).
Example. Here is a quite general, stationary, linear PDE arising in many problems:
The vector field \(\boldsymbol{v}\) and the scalar functions \(a\), \(\alpha\), \(f\), \(u_0\), and \(g\) may vary with the spatial coordinate \(\boldsymbol{x}\) and must be known.
Such a second-order PDE needs exactly one boundary condition at each point of the boundary, so \(\partial\Omega_N\cup\partial\Omega_D\) must be the complete boundary \(\partial\Omega\).
Assume that the boundary function \(u_0(\boldsymbol{x})\) is defined for all \(\boldsymbol{x}\in\Omega\). The unknown function can then be expanded as
The variational formula is obtained from Galerkin’s method, which technically implies multiplying the PDE by a test function \(v\) and integrating over \(\Omega\):
The second-order term is integrated by parts, according to
The variational form now reads
The boundary term can be developed further by noticing that \(v\neq 0\) only on \(\partial\Omega_N\),
and that on \(\partial\Omega_N\), we have the condition \(a\frac{\partial u}{\partial n}=-g\), so the term becomes
The variational form is then
Instead of using the integral signs we may use the inner product notation:
The subscript \(\,{}_N\) in \((g,v)_{N}\) is a notation for a line or surface integral over \(\partial\Omega_N\).
Inserting the \(u\) expansion results in
This is a linear system with matrix entries
and right-hand side entries
for \(i,j\in{\mathcal{I}_s}\).
In the finite element method, we usually express \(u_0\) in terms of basis functions and restrict \(i\) and \(j\) to run over the degrees of freedom that are not prescribed as Dirichlet conditions. However, we can also keep all the \(c_j\), \(j\in{\mathcal{I}_s}\), as unknowns drop the \(u_0\) in the expansion for \(u\), and incorporate all the known \(c_j\) values in the linear system. This has been explained in detail in the 1D case.
We consider an integral of the type
where the \({\varphi}_i\) functions are finite element basis functions in 2D or 3D, defined in the physical domain. Suppose we want to calculate this integral over a reference cell, denoted by \(\tilde\Omega^r\), in a coordinate system with coordinates \(\boldsymbol{X} = (X_0, X_1)\) (2D) or \(\boldsymbol{X} = (X_0, X_1, X_2)\) (3D). The mapping between a point \(\boldsymbol{X}\) in the reference coordinate system and the corresponding point \(\boldsymbol{x}\) in the physical coordinate system is given by a vector relation \(\boldsymbol{x}(\boldsymbol{X})\). The corresponding Jacobian, \(J\), of this mapping has entries
The change of variables requires \({\, \mathrm{d}x}\) to be replaced by \(\det J{\, \mathrm{d}X}\). The derivatives in the \(\nabla\) operator in the variational form are with respect to \(\boldsymbol{x}\), which we may denote by \(\nabla_{\boldsymbol{x}}\). The \({\varphi}_i(\boldsymbol{x})\) functions in the integral are replaced by local basis functions \({\tilde{\varphi}}_r(\boldsymbol{X})\) so the integral features \(\nabla_{\boldsymbol{x}}{\tilde{\varphi}}_r(\boldsymbol{X})\). We readily have \(\nabla_{\boldsymbol{X}}{\tilde{\varphi}}_r(\boldsymbol{X})\) from formulas for the basis functions in the reference cell, but the desired quantity \(\nabla_{\boldsymbol{x}}{\tilde{\varphi}}_r(\boldsymbol{X})\) requires some efforts to compute. All the details are provided below.
Let \(i=q(e,r)\) and consider two space dimensions. By the chain rule,
and
We can write these two equations as a vector equation
Identifying
we have the relation
which we can solve with respect to \(\nabla_{\boldsymbol{x}}{\varphi}_i\):
On the reference cell, \({\varphi}_i(\boldsymbol{x}) = {\tilde{\varphi}}_r(\boldsymbol{X})\), so
This means that we have the following transformation of the integral in the physical domain to its counterpart over the reference cell:
Integrals are normally computed by numerical integration rules. For multi-dimensional cells, various families of rules exist. All of them are similar to what is shown in 1D: \(\int f {\, \mathrm{d}x}\approx \sum_jw_if(\boldsymbol{x}_j)\), where \(w_j\) are weights and \(\boldsymbol{x}_j\) are corresponding points.
The file numint.py contains the functions quadrature_for_triangles(n) and quadrature_for_tetrahedra(n), which returns lists of points and weights corresponding to integration rules with n points over the reference triangle with vertices \((0,0)\), \((1,0)\), \((0,1)\), and the reference tetrahedron with vertices \((0,0,0)\), \((1,0,0)\), \((0,1,0)\), \((0,0,1)\), respectively. For example, the first two rules for integration over a triangle have 1 and 3 points:
>>> import numint
>>> x, w = numint.quadrature_for_triangles(num_points=1)
>>> x
[(0.3333333333333333, 0.3333333333333333)]
>>> w
[0.5]
>>> x, w = numint.quadrature_for_triangles(num_points=3)
>>> x
[(0.16666666666666666, 0.16666666666666666),
(0.66666666666666666, 0.16666666666666666),
(0.16666666666666666, 0.66666666666666666)]
>>> w
[0.16666666666666666, 0.16666666666666666, 0.16666666666666666]
Rules with 1, 3, 4, and 7 points over the triangle will exactly integrate polynomials of degree 1, 2, 3, and 4, respectively. In 3D, rules with 1, 4, 5, and 11 points over the tetrahedron will exactly integrate polynomials of degree 1, 2, 3, and 4, respectively.
We shall now provide some formulas for piecewise linear \({\varphi}_i\) functions and their integrals in the physical coordinate system. These formulas make it convenient to compute with P1 elements without the need to work in the reference coordinate system and deal with mappings and Jacobians. A lot of computational and algorithmic details are hidden by this approach.
Let \(\Omega^{(e)}\) be cell number \(e\), and let the three vertices have global vertex numbers \(I\), \(J\), and \(K\). The corresponding coordinates are \((x_{I},y_{I})\), \((x_{J},y_{J})\), and \((x_{K},y_{K})\). The basis function \({\varphi}_I\) over \(\Omega^{(e)}\) have the explicit formula
where
The quantity \(\Delta\) is the area of the cell.
The following formula is often convenient when computing element matrices and vectors:
(Note that the \(q\) in this formula is not to be mixed with the \(q(e,r)\) mapping of degrees of freedom.)
As an example, the element matrix entry \(\int_{\Omega^{(e)}} {\varphi}_I{\varphi}_J{\, \mathrm{d}x}\) can be computed by setting \(p=q=1\) and \(r=0\), when \(I\neq J\), yielding \(\Delta/12\), and \(p=2\) and \(q=r=0\), when \(I=J\), resulting in \(\Delta/6\). We collect these numbers in a local element matrix:
The common element matrix entry \(\int_{\Omega^{(e)}} \nabla{\varphi}_I\cdot\nabla{\varphi}_J{\, \mathrm{d}x}\), arising from a Laplace term \(\nabla^2u\), can also easily be computed by the formulas above. We have
so that the element matrix entry becomes \(\frac{1}{4}\Delta^3(\beta_I\beta_J + \gamma_I\gamma_J)\).
From an implementational point of view, one will work with local vertex numbers \(r=0,1,2\), parameterize the coefficients in the basis functions by \(r\), and look up vertex coordinates through \(q(e,r)\).
Similar formulas exist for integration of P1 elements in 3D.