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

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...