A1249 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A12 · Lesson 49 · Finite elements

Weak forms, hat functions and stiffness matrices

Finite differences replace derivatives with differences on a grid. The finite element method takes another route: it looks for the best approximation to the solution among simple functions, such as straight-line pieces between nodes, in the sense of the equation's energy. It handles uneven meshes, layered materials and awkward shapes naturally, which is why commercial field solvers for capacitance, magnetics and heat are almost all finite-element codes. In one dimension the whole method fits on a page, and its matrix turns out to be the nodal-analysis matrix of a resistor ladder.

  • The smooth curve is the exact solution of −u′′=1 with u(0)=u(1)=0, the parabola x(1−x)2.
  • The straight-line pieces are the finite-element solution with N elements. In this problem its values at the nodes are exactly right, and it is wrong only in between.
  • Raise N. The readout gives the largest error, at the middle of each element: 18N2. Doubling N cuts it by four.

Predict

With linear elements, the error in u falls as h2. How does the error in the slope u′ fall?

Name it

The weak form

For −(ku′)′=f on (0, L) with u=0 at the ends, multiply by any smooth test function v that is zero at the ends and integrate by parts:

∫0Lku′v′dx=∫0Lfvdxfor every such v.

This weak form asks for only one derivative of u, so piecewise-linear functions qualify. For k>0 it's also the condition for u to minimize the energy ∫(12ku′2−fu)dx.

Hat functions

Put nodes at x0=0<x1<⋯<xN=L. The hat function ϕi is 1 at node i, 0 at every other node, and straight in between. Write u≈∑iUiϕi and use each ϕj as a test function (Galerkin's method). That gives a linear system KU=F with

Kij=∫kϕi′ϕj′dx,Fj=∫fϕjdx.

The element matrices

On one element of length h with constant k, the two hats have slopes ±1/h, so the element contributes kh(1−1−11) to K. Adding the elements up (assembly) gives a tridiagonal matrix. With a uniform mesh and constant k, an interior row is kh(−1,2,−1), the same as the finite-difference matrix. A constant f gives Fj=fh.

Each element is a conductance k/h between two nodes, so K is exactly the nodal conductance matrix of a resistor ladder, and F is the current injected at each node. Layered materials just change the conductances.

Accuracy and eigenvalues

With linear elements the error is O(h2) in u and O(h) in u'. For eigenvalue problems −u′′=λu the method also needs the mass matrix Mij=∫ϕiϕjdx, with element matrix h6(2112); solving KU=λMU gives eigenvalues that are always too high, by the Rayleigh quotient argument of lesson 34.

Worked example

Solve −u′′=1 on (0, 1), with zero ends, using two elements.

Show the solution
  1. One unknown. With h = ½ there is one unknown, U1 at x = ½.
  2. Its row of K. The neighbors' values are fixed at 0, so the row is 1h(2)=4
  3. Its load. F1=∫ϕ1dx=h=12
  4. Solve. 4U1=12 giving U1=18.
  5. Compare with the exact solution. x(1−x)2 is also 18 at the midpoint: the nodal value is exact. In one dimension with constant coefficients, linear elements always get the nodal values right for this kind of problem, and the error lives entirely between the nodes.

Answer U1=18 at x = ½, the exact value.

Worked example

A wall has two layers, each 0.5 m thick, with conductivities 1 and 4 W/(m·K). One face is at 0 °C and the other at 1 °C. What is the temperature at the interface?

Show the solution
  1. Element conductances. Use one element per layer. Their conductances kh are 10.5=240.5=8
  2. Balance at the interface. The interface node's equation is the current balance 2(U−0)+8(U−1)=0 so U=810=0.8.
  3. Check with series resistances. That's exact: heat flows through two thermal resistances in series, 0.5 and 0.125 m²·K/W, so the flux is q=10.625W/m2=1.6W/m2 and it drops 1.6×0.5=0.8 °C across the first layer.
  4. Why elements handle the jump. Finite differences across a jump in k need special care; finite elements get it right automatically, because each element keeps its own k.

Answer the interface is at 0.8 °C.

Worked example

Estimate the lowest eigenvalue of −u′′=λu on (0, 1) with fixed ends using four linear elements, and compare with π².

Show the solution
  1. The discrete eigenvalue. For a uniform mesh, the discrete eigenvectors are samples of sin⁡πx, and the generalized eigenvalue works out to λh=6h2⋅1−cos⁡πh2+cos⁡πh
  2. Four elements. With h = ¼: λh=96×0.29292.7071=10.39 against π2=9.870: 5.2% high.
  3. Lumped mass. Replacing M by a diagonal "lumped" matrix with h on the diagonal gives the finite-difference value 4h2sin2⁡πh2=9.37 5.0% low.
  4. The pattern. The consistent mass matrix always errs high, as a Rayleigh quotient must, and the errors shrink as h2: with eight elements they are 1.3% each way.

Answer four elements give λh=10.39, 5.2% above π2=9.870.

Check

With 4 equal linear elements (consistent mass), what estimate of the lowest eigenvalue of −u′′=λu on (0, 1) with fixed ends do you get?

Check

A slab has two layers of equal thickness, with conductivities 1 and 4. Its faces are held at 0 and 10. With one element per layer, what is the value at the interface?

Check

A uniform mesh of linear elements has element length 0.1 and constant coefficient k = 2. What is the diagonal entry of K for an interior node?

Check

For f(x)=x on a uniform mesh with element length 0.1, what is the load Fj=∫fϕjdx at the interior node xj = 0.5?

Check

A linear-element solution is refined by splitting every element into 5.

(a)

By what factor does the largest error in u shrink?

(b)

And the largest error in u'?

Check

In circuit terms, what is the stiffness matrix of 1D linear elements for −(ku′)′=f?

Check

Solve −u′′=f on (0, L) with zero ends using two equal elements.

Step 1

What is the stiffness entry of the middle node, 2/h with h=L/2?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write fem(k, f, N) that assembles and solves the linear-element system for −(ku′)′=f on (0, 1) with zero ends, N equal elements, k(e) the coefficient on element e and f a constant. Return the interior nodal values. Set err to the largest nodal error for k = 1, f = 1, N = 8 against x(1−x)2.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why are finite-element eigenvalues always too high?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.