Fundamentals / Numerical mathematics / Numerical partial differential equations

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.

From first principles

Derive a conservative update from storage in a cell

Consider the one-dimensional conservation law \(u_t+\partial_x f(u)=0\) with no distributed source. Let \(\bar u_i\) denote the average over cell \(i\) of width \(\Delta x\). The integral of \(u\) over the cell is what the discrete variable stores. Integrate first over the cell and then over one time step. Only fluxes crossing the two faces can change its inventory:

\[\Delta x(\bar u_i^{n+1}-\bar u_i^n)=-\int_{t_n}^{t_{n+1}}[f_{i+1/2}(t)-f_{i-1/2}(t)]\,dt .\]

Replace each time-averaged face flux by one numerical function \(\hat f\) of neighbouring states, using the same value from both sides. For constant positive advection speed \(a\), the state reaching a face comes from upstream. With piecewise-constant cell data and \(C=a\Delta t/\Delta x\le1\) this gives

\[\hat f_{i+1/2}=a\bar u_i^n,\]
\[\bar u_i^{n+1}=(1-C)\bar u_i^n+C\bar u_{i-1}^n .\]

The update conserves total mass on a periodic grid because every internal face cancels. Nonlinear fluxes also need a rule selecting the physically admissible interface state, especially when a jump separates two different initial cell values.

Background · Courant number
\[C=|a|\Delta t/\Delta x\]

For scalar advection this compares a transported distance with a cell width. An admissible range depends on the spatial method and time integrator jointly.

Derivation and applications

Quantify the quadratic quantity lost by an upwind update

A conservative finite-volume method for advection preserves the sum of cell contents under periodic boundary conditions. It need not preserve their contrast. Consider the constant-speed transport equation \(u_t+a u_x=0\) with \(a>0\), uniform cells of width \(\Delta x\) and periodic indexing. Exact translation preserves \(\int u^2\,dx\). The first-order upwind scheme transports a fraction \(C=a\Delta t/\Delta x\) of a cell's content across its right boundary per step:

\[u_i^{n+1}=(1-C)u_i^n+C u_{i-1}^n .\]

For \(0\le C\le1\) this is a convex combination and cannot create a value outside its two inputs. To see precisely how much variation is removed, square one update and complete a difference square:

\[[(1-C)x+Cy]^2=(1-C)x^2+Cy^2-C(1-C)(x-y)^2 .\]

Sum over all cells. Periodicity allows the shifted sum of old squared values to be relabelled. The exact discrete identity, with \(E^n=(\Delta x/2)\sum_i(u_i^n)^2\), becomes

\[E^{n+1}-E^n=-\frac{\Delta x}{2}C(1-C)\sum_i(u_i^n-u_{i-1}^n)^2 .\]

This loss vanishes for spatially constant data and for \(C=1\), when the update shifts by one complete cell. Strong cell-to-cell jumps dissipate much more of the quadratic quantity than smooth profiles sampled with the same grid. Total mass still telescopes exactly; the two balance laws diagnose different aspects of accuracy.

Worked example

Follow one step on four periodic cells

Take \(\Delta x=1\), \(C=1/2\) and initial averages \((1,1,0,0)\). The updated values are \((0.5,1,0.5,0)\). Both arrays sum to two. The quadratic energy falls from \(1.00\) to \(0.750\). There are two unit jumps at the start, and the loss formula gives \((1/2)(1/2)(1/2)(2)=0.250\), accounting for the full change.

Second application

Use an alternating pattern as an instability detector

For \((1,-1,1,-1)\) each neighbour has opposite sign, so one step multiplies the amplitude by \(1-2C\). At \(C=1/2\) all variation disappears in one step although the exact wave would keep its amplitude. At \(C=1.10\) the factor is \(-1.20\) and energy grows by \(1.44\). The sign reversal in \(C(1-C)\) therefore predicts growth at this resolved wavelength. Conservation of the zero mean still holds in both experiments and alone cannot detect the instability.

OneSimulation laboratory

Measure spatial convergence on a known field

Start from this chapter. Construct a shared flux on each interior face so neighbouring cell balances use opposite signs. Examine how resolving the source wavelength changes the computed field at fixed residual tolerance.

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

Read the model setup and preparatory problems

Store quantities over cells

Consider a passive concentration satisfying \(u_t+(au)_x=0\) with positive constant speed \(a\) on a periodic line. Let \(\bar u_i=h^{-1}\int_{x_{i-1/2}}^{x_{i+1/2}}u\,dx\) be its cell mean. Integrating the conservation law in space and time shows that every change in cell inventory comes from fluxes through its two faces. If neighbouring cells use the same face flux, summing all updates cancels every internal transfer exactly. On a periodic line the total stays fixed, even for a discontinuous concentration.

For positive speed, material reaching the right face during a short step comes from the cell to its left. Approximate the outgoing state by that cell’s mean, giving \(F_{i+1/2}=a\bar u_i\). Forward Euler in time yields

\[\bar u_i^{n+1}=(1-C)\bar u_i^n+C\bar u_{i-1}^n,\]

where \(C=a\Delta t/h\). For \(0\leq C\leq1\) this is a convex average, preserving the range of neighbouring values. At \(C=1\) the entire array shifts exactly by one cell per step. If \(a<0\), information comes from the other side of the face and the upwind direction must reverse.

Identify the source of artificial spreading

Start with one cell mean equal to one and zeros everywhere else. With \(C=1/2\), one step gives adjacent means \(1/2,1/2\). A second step gives \(1/4,1/2,1/4\), while the total remains one. Exact advection over two such steps shifts the original pulse by one cell with no change in shape. The scheme has conserved mass yet broadened the pulse. Peak height or variance therefore tests information not supplied by a global balance.

For smooth \(u\), Taylor-expand the upwind update in space and time. Replace the leading \(u_{tt}\) using the exact transport equation, \(u_{tt}=a^2u_{xx}\). The leading modified equation is

\[u_t+a u_x=[ah(1-C)/2]u_{xx}+\cdots.\]

The bracket acts as numerical diffusivity. It is positive for the monotone range and vanishes at \(C=1\). This local smooth expansion helps interpret observed spreading, but the Taylor expansion itself does not hold across a jump.

Choose a flux when speed depends on the state

For a nonlinear conservation law \(u_t+f(u)_x=0\), characteristics can intersect and create a discontinuity. Enclose a moving jump in a thin control volume. The net flux imbalance fixes its speed \(s=(f(u_R)-f(u_L))/(u_R-u_L)\). For Burgers flux \(f=u^2/2\) with left state 2 and right state 0, this gives \(s=1\). The faster characteristics on the left overtake the slower ones to form a shock. Reversing these states produces a spreading fan under the entropy condition even though the algebraic jump formula alone would still supply a speed.

A numerical face flux must be consistent when the two cells agree and must incorporate information from both sides when a nonlinear wave can travel either way. A conservative method that converges can reproduce the weak jump balance, while selection of a physically admissible solution also requires an entropy criterion. For practical assessment, monitor total inventory, motion of the front, overshoot and the number of cells over which it is smeared. The four measurements address distinct properties, and reducing one defect need not reduce all of them.

Move the control surface instead of the grid

Across a front moving with speed \(s\), flux in the front’s own frame is \(f(u)-su\). The jump relation enforces equality of this quantity on both sides. For the Burgers jump from 2 to 0 with speed one, the left flux in the moving frame is \(2-1\cdot2=0\), and the right flux is also zero. The laboratory flux differs across the front because a moving interface is sweeping conserved material through stationary space.

This distinction helps when checking a simulation by counting material in a region that tracks a front. Differentiating an integral over moving endpoints adds boundary-motion terms. In a periodic fixed window the update should conserve total amount without those extra terms. In a moving measurement window, physical transport through the window and motion of the window both influence the recorded inventory, even under a perfectly conservative scheme.

Distinguish a conservative jump from the physical weak solution

For inviscid Burgers flow \(u_t+(u^2/2)_x=0\), integrating conservation across a moving jump gives the Rankine–Hugoniot speed \(s=[f]/[u]=(u_L+u_R)/2\). It uses only balance, so a discontinuity with that speed satisfies the weak conservation equation for either orientation of its left and right states. To select the physically relevant solution one needs an entropy condition. For a compressive shock characteristic speeds enter it from both sides: \(u_L>s>u_R\). If \(u_L<u_R\), the characteristics separate and a continuous rarefaction fan fills the gap.

For example the entropy \(\eta(u)=u^2/2\) has entropy flux \(q(u)=u^3/3\), because \(q'=\eta'f'\). A jump produces distributional entropy \([q]-s[\eta]\), which must be nonpositive for a dissipative solution. At equal-magnitude opposite states the entropy jump \([\eta]\) is zero, so orientation alone changes the sign of the entropy production. A conservative scheme can preserve every cell total correctly yet converge to an inadmissible expansion shock if it fails this additional condition.

Choose the correct interface flux for two opposite Riemann data

Take \(u_L=-1,\ u_R=1\). Both endpoint fluxes equal one half, and the jump-speed formula gives zero. Holding this discontinuity fixed would conserve the cell totals. Its entropy production, however, is

\[1/3-(-1/3)=2/3>0.\]

The admissible Riemann solution is the self-similar fan: at coordinate \(\xi=x/t\), \(u=-1\) for \(\xi\le-1\), \(u=\xi\) between minus one and one, and \(u=1\) for \(\xi\ge1\). At the interface \(\xi=0\), the flux is therefore zero. Using an arithmetic average of the two endpoint fluxes would instead maintain the inadmissible jump.

For a finite-volume update with \(\Delta t/\Delta x=0.5\) and initially constant states on either side, the neighbouring left cell changes from \(-1\) to \(-1-0.5(0-0.5)=-0.75\). The right cell changes from one to \(1-0.5(0.5-0)=0.75\). Their sum remains zero. A direct integration of the fan gives the same cell averages: the disturbance occupies half of each cell and linearly brings that half from its far-state value toward zero. Thus both conservation and the local wave pattern can be verified independently.

Reverse the initial states to \(u_L=1,\ u_R=-1\). The zero-speed jump now has entropy production \(-2/3\), and both families of characteristics enter it. Its correct interface flux is one half. The same numerical update then leaves both neighbouring cell averages unchanged, exactly as required for a stationary shock. Testing both orientations is more revealing than testing a single conserved jump: they have identical endpoint flux magnitudes and the same Rankine–Hugoniot speed but different physically admissible interface states.

A further integration test shifts the interface by precisely one cell and reruns the update. On a uniform periodic grid with unchanged physical states, the new solution should be a one-cell translation of the old one. A difference between the two calculations could reveal an indexing error in the face flux even when a global conservation diagnostic remains identically zero.

Measure numerical spreading in a conservative transport step

Start with all mass in one cell. For positive velocity the explicit upwind update keeps fraction \(1-C\) and transfers fraction \(C\) to the next cell each step. Thirty updates produce a binomial distribution on an unbounded uniform grid.

Measure numerical spreading in a conservative transport step. Horizontal axis: Cell offset from initial pulse. Vertical axis: Fraction of total pulse mass. Data follow the figure.
Each profile sums to one. Its centre moves 30C cells and its variance is 30C(1−C) cells². Conservation and the correct mean travel distance can coexist with artificial broadening of a pulse that should translate without changing shape.
Read values from the plot
Fraction of total pulse mass at selected values of Cell offset from initial pulse.
Cell offset from initial pulseCourant number 0.25Courant number 0.5Courant number 0.85
00.000178589.3132e−101.9175e−25
80.159310.0054511.1933e−12
150.00193050.144465.9335e−6
223.3308e−80.0054510.042007
308.6736e−199.3132e−100.0076308

Download all 31 plotted samples (CSV)

Change parameters · Measure numerical spreading in a conservative transport step

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.

Study the full derivation

Choose the physically admissible wave in a conservative update · Spatial discretisation and field equations

A discontinuous scalar flow can satisfy integral conservation in more than one way. Derive the shock speed, use a convex entropy to distinguish a compression from an expansion and build a finite-volume flux from the resulting local solution.