Fundamentals / Numerical mathematics

Numerical partial differential equations

Discretise field equations with conservation and boundary data, resolve interfaces and pressure constraints, and estimate error in a chosen output.

Prerequisites Second derivatives, boundary conditions and linear systems.

Investigate with OneSimulation Measure spatial convergence on a known field · Predict grid error from the wavelength

Read the subject in depth

Each volume develops its arguments in sequence, with worked problems and links to experiments.

How the course fits together

  1. Chapters 1–4

    Turn flux balance on a cell into neighbouring unknowns. The weak form imposes the same balance against test functions. Check whether face fluxes cancel, then add storage to predict a field evolving in time.

  2. Chapters 5–8

    Track the numerical speed of waves and verify a discretisation using a known manufactured field. Interfaces require matching flux, and a tensor coefficient makes the flux direction depend on material orientation.

  3. Chapters 9–12

    Advection, pressure constraints and widely separated mesh scales require different discretisations and solvers. End by defining the particular output whose error matters and weighting residuals accordingly.

Chapters

  1. Flux differences for an elliptic balance

    Assemble a conservative boundary-value problem from face fluxes, trace the effect of boundary conditions and establish a discrete energy identity.

  2. Weak forms and finite elements

    Derive a variational statement by integration by parts, assemble element matrices for a one-dimensional rod and explain what the Galerkin solution minimises.

  3. Finite volumes and moving fronts

    Derive an upwind transport update by conservation, interpret the Courant number as a fraction of cell contents and determine what conservation says about front speed.

  4. Time-dependent diffusion

    Derive the diffusion time-step restriction from two independent arguments and compare explicit and implicit decay of spatial modes.

  5. Wave speeds and numerical dispersion

    Derive the leapfrog dispersion relation, use the Courant condition to distinguish boundedness from accurate travel time and initialise a standing-wave calculation consistently.

  6. Verification, refinement and local error

    Use a manufactured solution to verify an implementation, estimate observed convergence and identify when adaptivity is needed for the physical quantity of interest.

  7. Interfaces, contact resistance and Robin data

    Derive a face flux that transports the same heat through two different materials and through a convective boundary.

  8. Anisotropic diffusion and mesh alignment

    Relate a diffusion tensor to principal directions and test whether a face-flux approximation can represent a rotated material.

  9. Cell Péclet number and monotonicity

    Derive the sign restriction for centred transport, identify a numerical boundary layer and quantify the diffusion introduced by upwinding.

  10. Incompressibility and discrete pressure modes

    Derive the velocity–pressure block system and use a periodic mesh to detect a pressure pattern that exerts no discrete force.

  11. Multigrid and coarse-grid correction

    Combine smoothing with a coarse residual equation and compute which components a two-grid correction can remove exactly.

  12. Adjoints and errors in a chosen output

    Weight equation residuals by the response of a chosen observation and distinguish algebraic error from mesh error.

Further chapters and interactive tutorials

  1. Pure flux boundaries, compatibility and the missing constant

    If a steady diffusion equation prescribes only fluxes, a solver can return a singular-matrix warning for two different physical reasons. Derive the mass balance and the nullspace separately, then decide when choosing a reference value resolves the problem.

  2. Building a local residual estimator and refining where it matters

    A finite-element solution can satisfy the assembled equations to machine precision while still missing curvature between nodes. Integrate the residual of the computed field by parts on each element and use the resulting cell and interface terms to decide where to spend the next degrees of freedom.

  3. What a periodic grid does to a decaying Fourier mode

    A periodic diffusion solver predicts the shape of a sampled wave while its amplitude decays too slowly. Fourier analysis separates spatial differentiation error, an unresolved physical mode and errors caused by the time integrator.

  4. Why two finite-element wave solvers propagate the same mode at different speeds

    Build the element mass matrix by integrating shape functions and track the effect of diagonal lumping on the wave spectrum.

  5. Moving a cell average without inventing or losing material

    Derive a conservative transport step from cell overlap and measure how a monotone scheme spreads a pulse despite conserving its total mass exactly.

  6. When diffusion destabilises a uniform state

    Two scalar signals on a ring respond locally to each other and exchange signal with their neighbours. A single well-mixed cell returns to its reference state after a small disturbance. Can coupled cells amplify a spatial pattern? Derive a condition for this surprising outcome and test how faithfully a finite grid represents its wavelength.

Computational notebooks

Run the Python calculations in your browser and compare the figures with the derivations.

Problem sheets

Sheets 1–6 accompany the first twelve chapters. The final projects bring several methods together. Attempt each stage before opening its worked solution.

  1. Flux balances and virtual workFor chapters 1 and 2

    Choose the correct conductance at an interface, test pure-flux compatibility and assemble a rod with unequal stiffnesses.

  2. Fronts and diffusive modesFor chapters 3 and 4

    Track conservation on a periodic mesh, distinguish shocks from expanding fans and choose a time step for an explicit diffusion solver.

  3. Wave resolution and verificationFor chapters 5 and 6

    Prescribe the first time level of a vibrating string, measure a convergence order and decide what a residual reveals under grid refinement.

  4. Material interfaces and anisotropyFor chapters 7 and 8

    Recover face temperatures and fluxes, and use a linear temperature field to test a rotated conductivity tensor.

  5. Transport weights and pressure spacesFor chapters 9 and 10

    Locate the onset of a sign error and test which discrete pressure differences actually drive a velocity.

  6. Transfers and observation errorFor chapters 11 and 12

    Track which error can survive a grid transfer and compute an exact adjoint correction for a nonsymmetric system.

  7. Project · Verify a heat solver before interpreting its temperature

    A laboratory plate can be heated internally and cooled at its boundary. Check global feasibility, the spatial error between nodes and the wavelength-dependent decay of periodic modes.

  8. Resolve an outflow layer by fitting the numerical face flux

    A dilute solute moves down a channel and diffuses against its mean flow. Fixed concentrations at the ends generate a thin downstream layer. Construct the cell flux directly from the differential equation, then ask how a solver can return nearly the right total throughput while still predicting an impossible local concentration.

Final synthesis problem · Decide if another grid refinement answers the engineering question

Applied study

Discretise a boundary-value problem and separate mesh error from solver and sampling errors.

Replace a continuum balance by nodal equations

Suppose a scalar diffuses along a unit interval, with a fixed value at each end. The steady balance is \(-u''=f\) for constant unit diffusivity. At equally spaced interior nodes \(x_i=ih\), approximate the derivative at each face by the difference between its neighbouring values divided by \(h\). Subtracting the outgoing and incoming diffusive fluxes and dividing by cell width gives

\[\frac{2u_i-u_{i-1}-u_{i+1}}{h^2}=f(x_i).\]

The endpoints are known, leaving \(N-1\) interior unknowns for \(N\) intervals. Each interior flux appears once with each sign in neighbouring balances. Summing balances therefore leaves the net boundary flux and the total source. With variable diffusivity \(D\), multiply each face gradient by its face value of \(D\) before taking the difference.

Find the error made by a single stencil

Insert the exact values \(u(x_i-h)\) and \(u(x_i+h)\), expand both in Taylor series and add them. Odd terms cancel. The central second difference satisfies \(\delta_{xx}u=u''+h^2u^{(4)}/12+O(h^4)\) for sufficiently smooth \(u\). This local consistency calculation predicts the scale of the defect when the exact solution is inserted in the discrete equations.

Write the discrete problem \(A_hu_h=f_h\) and define \(\tau_h=A_hu_\star-f_h\) using exact nodal values \(u_\star\). Then \(A_h(u_\star-u_h)=\tau_h\). A stability bound on \(A_h^{-1}\), uniform in mesh size in the chosen norm, turns second-order consistency into second-order solution error. A tight iterative solve reduces the residual of \(A_hu_h=f_h\), but leaves \(\tau_h\) in place.

Use an exact sine mode to predict the discrete amplitude

Prescribe \(u(0)=u(1)=0\) and \(f(x)=\pi^2\sin(\pi x)\). The exact solution is

\[u_\star=\sin(\pi x).\]

For its grid samples \(s_i=\sin(\pi ih)\), the sine addition formula yields

\[A_hs=\lambda_hs,\]

with \(\lambda_h=4\sin^2(\pi h/2)/h^2\). The right-hand side is \(\pi^2s\), so the discrete solution has the same nodal shape and amplitude \(\pi^2/\lambda_h\).

With four intervals, \(\lambda_h=64\sin^2(\pi/8)=9.3726\) and the numerical midspan value is 1.0530. The exact value is 1. The sign makes sense: the discrete stiffness of this mode is below \(\pi^2\), so the same load produces a larger amplitude. Expansion gives \(\pi^2/\lambda_h=1+\pi^2h^2/12+O(h^4)\), predicting a fourfold error reduction on refinement.

Problem class

Test a polynomial before trusting the mesh

Keep the homogeneous end values and choose \(u_\star=x(1-x)\). Derive \(f\), then predict the nodal error for any uniform mesh in exact arithmetic. Would this make a good test for measuring convergence order?

Show the calculation

Since \(u_\star''=-2\), use \(f=2\). The centred second difference of any quadratic equals its exact second derivative. The nodal vector therefore solves the discrete equations exactly. It is a useful stencil consistency check, but its zero leading error prevents a meaningful order measurement from a ratio of errors.

Manufacture a source for variable diffusion

On the unit square let \(D(x)=1+x\), \(u_\star=\sin(ax)\sin(ay)\), and \(a=m\pi\) for positive integer \(m\), using metre coordinates. What forcing makes \(-\nabla\cdot(D\nabla u)+2u=f\) hold with zero boundary values?

Show the calculation

Apply the product rule,

\[-\nabla\cdot(D\nabla u)=-D\Delta u-D'(x)u_x.\]

Here \(\Delta u_\star=-2a^2u_\star\) and \(D'=1\). Thus \(f=[2(1+x)a^2+2]u_\star-a\cos(ax)\sin(ay)\). Each boundary has a zero sine factor. Omitting \(D'u_x\) would produce a continuous modelling error that persists even when the mesh is refined.

OneSimulation laboratory

Measure spatial convergence on a known field

Compare recorded OneSimulation runs on this page. To test your own inputs, download the Python model and run the model in an activated OneSimulation environment.

The script solves the steady equation \(-\nabla\!\cdot[(1+x)\nabla u]+2u=f\) on the unit square by conservative flux differences and Jacobi-preconditioned CG. Set \(u=\sin(m\pi x)\sin(m\pi y)\) and obtain the source by substitution. The boundary values are zero on all four sides. Compare the maximum error at grid nodes with the solver’s relative residual. Refine both axes together, then raise the sine mode on the same 48-cell mesh to see how wavelength affects the error. Download the Python experiment · OneSimulation reaction–diffusion refinement study.

python partial-differential-equations.py
python partial-differential-equations.py --cells 48
python partial-differential-equations.py --cells 96
python partial-differential-equations.py --cells 48 --mode 2
Independent solves for the dimensionless scalar field on a unit square.
Cells per axis, modeInterior unknownsMax. nodal errorRelative residual
24, 15291.33345 × 10⁻³9.79 × 10⁻¹¹
48, 12,2093.33763 × 10⁻⁴7.14 × 10⁻¹¹
96, 19,0258.34283 × 10⁻⁵4.21 × 10⁻¹¹
48, 22,2091.41546 × 10⁻³8.89 × 10⁻¹¹
The first three runs approximately quarter the nodal error with each grid refinement. Changing the wavelength on the same 48-cell grid increases the error even at a small algebraic residual.
The first three runs approximately quarter the nodal error with each grid refinement. Changing the wavelength on the same 48-cell grid increases the error even at a small algebraic residual.

At mode one the error falls by factors close to four while the number of interior unknowns roughly quadruples. On the same 48-cell mesh, mode two has half as many intervals per wavelength and a larger error. Both modes have small algebraic residuals. Mesh convergence is a property of the resolved field and its discretisation.

Change parameters · Change the laboratory inputs

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Problem sheet 3 · Predict the error before making a finer grid

Advanced study across the subject

Each sequence connects the course to detailed chapters in neighbouring subjects. The complete course PDF includes their derivations, examples and exercises.

  1. Boundary data, uniqueness and singular sources

    Derive the continuous problem before assembling a discrete row. Test what happens to uniqueness, source flux and interface voltage under a change of boundary data.

  2. Heat, momentum and wave transport

    Test the same spatial method on diffusion, a propagating pulse and an elastic mode. Compare dissipation, dispersion and boundary residuals on a common footing.

Discretise Gauss’s law across a spatially varying dielectric and compare the calculated field, voltage and stored energy with an integral solution.

Measure the capacitance of a continuously graded dielectric

Further reading

Compare specific topics with the university sources