Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

The weak form

Our usual formulation of BVPs is called the strong form because it assumes a lot of continuity in a solution. E.g.: if the equation contains ∇2u\nabla^2 u, the solution assumes that that derivative exists!

The MWR leads to the weak form which has less requirements on the solution, amoungst other benefits. Essentially, all we have to do is multiply through by our test function vv and integrate. Something very useful happens to our divergence-of-flux terms, which are prevelant in conservation equations.

As an example, consider a time dependant heat balance (temperature = uu), using the backward Euler time marching scheme.

∂u∂t=−∇⋅J⃗u−ut−1Δt=−∇⋅J⃗u+Δt[∇⋅J⃗]=ut−1\begin{align} \frac{\partial u}{\partial t} &= -\nabla \cdot \vec{J} \\ \frac{u - u^{t-1}}{\Delta t} &= -\nabla \cdot \vec{J} \\ u + \Delta t [\nabla \cdot \vec{J}] &= u^{t-1} \end{align}

To get to the weak form, multiply through by the test funciton vv and integrate:

0=∫Ωuv−∫Ωut−1v +Δt∫Ωv∇⋅J⃗0 = \int_{\Omega} u v - \int_{\Omega} u^{t-1}v \ + \Delta t \int_{\Omega}v \nabla \cdot \vec{J}

Examining the divergence-of-flux term, we see that we can apply integration by parts followed by the Divergence Theorem:

∫Ωv∇⋅J⃗=−∫Ω∇v⋅J⃗+∫Ω∇⋅[vJ⃗]=−∫Ω∇v⋅J⃗+∫∂Ωv J⃗⋅n^=∫Ωλ∇v∇u+∫∂Ωv Jn\begin{align} \int_\Omega v \nabla \cdot \vec{J} &= -\int_\Omega \nabla v \cdot \vec{J} + \int_{\Omega} \nabla \cdot \big[v\vec{J}\big] \\ &=-\int_\Omega \nabla v \cdot \vec{J} + \int_{\partial \Omega} v \ \vec{J} \cdot \hat{n} \\ &=\int_\Omega \lambda \nabla v \nabla u + \int_{\partial \Omega} v \ J_n \end{align}

Where we have defined the outward normal boundary flux, Jn=J⃗⋅n^J_n = \vec{J} \cdot \hat{n}

The weak form is remarkable since we:

  • replaced a second derivative with the product of two first derivatives.

  • no longer require our solution to have a second derivative (it can be less smooth and satisfy the equation in an average sense which is weaker than the strong form)!

  • incorporated boundary fluxes directly into the residual calculation (through the surface integral)

  • do not require anything from λ\lambda, which means this is still valid for λ(u,x,t...)\lambda(u,x,t...), however it is now outside of the gradient!

  • We also provided an avenue for directly integrating surface phenomena into our model through the surface integral!)

Boundary conditions / terms

The term ∫∂Ωv J⃗⋅n^\int_{\partial \Omega} v \ \vec{J} \cdot \hat{n} is a boundary integral of the normal flux, J⃗n=J⃗⋅n^\vec{J}_n = \vec{J} \cdot \hat{n}.

Typically, we will have some knowledge of the boundary conditions either:

  • Neumann (flux) boundary condition in which case we have the quantity J⃗n\vec{J}_n to insert directly.

  • Insulation (zero flux) for which J⃗n=0\vec{J}_n= 0 and the term vanishes.

  • Dirichlet (value) boundary condition which we would just insert directly into the applicable unknown, e.g.: u0=0u_0 = 0 for a boundary u(0)=0u(0) = 0. In this case, there is still a flux at that boundary but it is determined by the dirichlet condition.

Some software will opt to implement Dirichlet conditions as a weak constraint which is a Lagrange multiplier formulation in which the lagrange multiple assume the value of the reaction force necesssary to affect that constraint.

Discretization

We are now in a position to discretize the weak equation ,

∫Ωuv+Δt∫Ωλ∇v∇u=∫Ωut−1v−Δt∫∂Ωv Jn\begin{align} \int_{\Omega} u v + \Delta t \int_\Omega \lambda \nabla v \nabla u &= \int_{\Omega} u^{t-1}v - \Delta t \int_{\partial \Omega} v \ J_n\\ \end{align}

into a form we are able to solve, which will (finally) give us an idea of what the shape functions are.

Small support for shape functions

The shape functions are generally designed to be non-zero only inside their element. This has the effect of limiting products, ∫ϕiϕj\int \phi_i \phi_j and ∫∇ϕi∇ϕj\int \nabla \phi_i \nabla \phi_j to be zero for almost all combination of ii and jj except for cases where the nodes ii and jj are within the same element!

Assembly

The matrix assembly stage involves transforming the weak form into a matrix equation for the unknowns, uiu_i such that the approximate solution can be assembled as uh=∑uiϕiu_h = \sum u_i \phi_i.

Consider the term, ∫Ωuv\int_{\Omega} uv, recalling uh=∑uiϕiu_h = \sum u_i \phi_i and v=∑jϕjv = \sum_j \phi_j. Since integration is a linear operator, we have,

∫Ωuv=∑iui∫Ωϕiϕj=∑iuiMij\begin{align} \int_{\Omega} uv &= \sum_i u_i \int_{\Omega} \phi_i \phi_j \\ &= \sum_i u_i M_{ij} \\ \end{align}

where MijM_{ij} is called the Mass matrix.

Similarly,

∫Ωλ∇v∇u=∑iλ(ui)ui∫Ω∇ϕi∇ϕj=∑iλ(ui)uiKij\begin{align} \int_\Omega \lambda \nabla v \nabla u &= \sum_i \lambda(u_i) u_i \int_{\Omega} \nabla \phi_i \nabla \phi_j \\ &= \sum_i \lambda(u_i) u_i K_{ij} \end{align}

which is called the stiffness matrix.

The term

∫Ωut−1v=∑iuit−1∫Ωϕiϕj=∑iuit−1Mij=bj\begin{align} \int_{\Omega} u^{t-1} v &= \sum_i u^{t-1}_i \int_{\Omega} \phi_i \phi_j \\ &= \sum_i u_i^{t-1} M_{ij} = b_j \end{align}

but can also be calculated directly since uit−1u_i^{t-1} is known.

Finally we can assemble our equation:

∫Ωuv+Δt∫Ωλ∇v∇u=∫Ωut−1v−Δt∫∂Ωv Jn∑iuiMij+ΔtλuiKij=bj−Jnju⃗hM+Δtλu⃗hK=b⃗−Jn⃗\begin{align} \int_{\Omega} u v + \Delta t \int_\Omega \lambda \nabla v \nabla u &= \int_{\Omega} u^{t-1}v - \Delta t \int_{\partial \Omega} v \ J_n\\ \sum_i u_i M_{ij} + \Delta t \lambda u_i K_{ij} &= b_j - {J_n}_j \\ \vec{u}_h M + \Delta t \lambda \vec{u}_h K &= \vec{b} - \vec{J_n} \end{align}

The elements of the matrix are can be calculated for a reference element and then simply scaled according to the transformation of the template to the mesh. The integration itself can be analytic, or Gaussian Quadrature (for which Gauss Points would be obtained on the reference element).

Summary of FEM Matricies

Weak Form Term ............Matrix Form (FEM)Description
∫Ωϕiϕj dΩ\int_\Omega \phi_i \phi_j \, d\OmegaMij\mathbf{M}_{ij} Mass matrix. Often used in time-dependent problems.
∫Ω∇ϕi⋅∇ϕj dΩ\int_\Omega \nabla \phi_i \cdot \nabla \phi_j \, d\OmegaKij\mathbf{K}_{ij} Stiffness matrix. Used in problems like Poisson or elasticity equations.
∫Ωϕif dΩ\int_\Omega \phi_i f \, d\OmegaFi\mathbf{F}_i Load vector. Represents source terms in the governing equation.
∫∂Ωϕig d∂Ω\int_{\partial \Omega} \phi_i g \, d\partial \OmegaFibc\mathbf{F}_i^{\text{bc}} Boundary load vector (from Neumann boundary conditions).

Solution

We now arrive at a matrix equation for the unknows uiu_i, which is mearly a system of equations as we’ve spoken about beforehand.

Linear PDE

If the PDE is linear, we can solve it with a linear solver which is sparse due to the small support requirement of the elements. The matrix will not in general be banded however, due to the irregular conectivity of the mesh verticies.

Example: 1D heat equation

Solve the 1D heat balance equation with λ=1\lambda = 1 for xx from 0 to 10 subject to J(0)J(0) = 1 and T(10)=0T(10) = 0. Initial condition is T(x,t=0)=0T(x,t=0) = 0.

The mass matrix is:

Mij=∫x1x2ϕi(x)ϕj(x)dxM_{ij} = \int_{x_1}^{x_2} \phi_i(x) \phi_j(x) dx

with

ϕ1(x)=x2−xx2−x1ϕ2(x)=x−x1x2−x1\begin{align} \phi_1(x) &= \frac{x_2-x}{x_2-x_1} \\ \phi_2(x) &= \frac{x-x_1}{x_2-x_1} \\ \end{align}

we (Mathematica) get:

M=[x2−x1]6[2112]M = \frac{[x_2-x_1]}{6} \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}

The stiffness matrix needs

∇ϕ1(x)=−1x2−x1∇ϕ2(x)=1x2−x1\begin{align} \nabla \phi_1(x) &= \frac{-1}{x_2-x_1} \\ \nabla \phi_2(x) &= \frac{1}{x_2-x_1} \\ \end{align}

and

Kij=λ∫x1x2∇ϕi(x)∇ϕj(x)dx=λh[1−1−11]\begin{align} K_{ij} &= \lambda \int_{x_1}^{x_2} \nabla \phi_i(x) \nabla \phi_j(x) dx\\ &= \frac{\lambda}{h} \begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix} \end{align}

These blocks belong to each element, so we have to build the full matrix by summing them. Note this implies an overlap at common verticies between elements!

<Figure size 640x480 with 1 Axes>
Loading...

Note that we built the MM and KK matricies once, outside the time loop and reuse them for each time step! Even if we had adaptive time stepping, the matrix wouldn’t change!

Nonlinear case

If the PDE is nonlinear, we simply have to use a root finder. Note that in this case we are looking for the parameters uiu_i directly - the shape functions are unaffected and therefore only the coefficients of the matrix blocks are altered. This brings up the concept of sparsity patterns which can help reduce the overhead of sparse matrix representaitons.

Since modern finite element software needs to construct the weak form, it is usually equiped with symbolic logic capabilities and therefore able to calculate the Jacobian for use in the root finding algorithm.

Example: 1D nonlinear heat equation

Repeat the above exercise with λ=1+u/10\lambda = 1 + u/10

Loading...

Hmmmm... something is funny in that code!

Loading...