From first principles
Derive a cell equation by integrating the physical balance
Consider steady one-dimensional conduction in a rod with area \(A(x)\), conductivity \(k(x)>0\) and heating per unit length \(s(x)\). Define heat current \(F\) positive to the right. Conservation in any finite interval requires that the current leaving equals the current arriving plus generation. Integrating over cell \(i\) fixes a discrete equation without yet approximating a derivative:
Each shared face must use the same current in its two adjacent cells. To close a face between constant-material regions with no intervening source, integrate Fourier’s law from one cell centre to the other. The heat current is constant on that interval, so it can be taken outside the integral. Defining the face resistance \(R_{i+1/2}\) makes the sign of the temperature drop explicit:
On a uniform homogeneous mesh this reduces to \(kA(T_i-T_{i+1})/h\). Across a material change the half-cell resistances must instead be added. Substituting face currents into the cell balances produces the matrix system. Boundary temperatures, prescribed currents or film laws determine which additional boundary equations close it.
Background · Conservative face flux
Use the same face flux with opposite orientations in neighbouring cells. Interior contributions then cancel in the global balance.
Open full-size diagram
Derivation and applications
Why a flux-only boundary requires a compatibility condition
An insulated or flux-controlled steady diffusion calculation can fail even when each individual face law is correct. Consider a one-dimensional bar of unit area, positive conductivity \(k\), and cell sources \(s_i\) per unit length. Define \(F_{i+1/2}\) as heat current positive to the right everywhere, including both boundaries. At steady state the current leaving the right face minus the current entering the left face equals the total source in that cell:
Summing over cells cancels every shared interior current. No detail of the face-gradient approximation can change the remaining global condition:
With only prescribed fluxes, the discrete gradient also cannot determine a temperature offset. For a connected linear system with positive face transmissibilities, its assembled quadratic form is a sum of squared temperature differences:
The nullspace consists precisely of constant temperatures. A compatible right-hand side gives a family of solutions; prescribe one reference temperature or a weighted mean to select a member. An incompatible right-hand side gives no steady solution. Physically, the imbalance would accumulate energy. Removing one algebraic equation or pinning a temperature without checking global balance can inadvertently create an unreported heat sink.
Worked example
Reconstruct temperatures from compatible flux data
Take three equal cells with source totals \(1,2,1\) W, left incoming current \(F_L=2\) W and right outgoing current \(F_R=6\) W. Internal face currents are successively \(3\) and \(5\) W. With both conductances equal to \(2\) W/K, the temperature drops are \(1.5\) and \(2.5\) K from left to right. For a prescribed arithmetic mean of \(300\) K the temperatures are \(301.833\), \(300.333\) and \(297.833\) K. Adding a common constant would leave every face measurement unchanged.
Second application
Diagnose an unbalanced insulated test
Seal both ends so \(F_L=F_R=0\) but retain the same sources. Their total is \(4\) W. If the combined heat capacity is \(200\) J/K, the heat-capacity-weighted mean temperature must rise at \(4/200=0.0200\) K/s. A steady solver reporting fixed temperatures under those conditions should be checked for a hidden imposed temperature or a dropped residual. The missing four watts have a direct transient interpretation.
OneSimulation laboratory
Measure spatial convergence on a known field
Start from this chapter. Start with the difference of two face fluxes. The coefficient varies in space, so leaving its derivative out changes the manufactured source. Use the supplied solve to check the refined nodal error.
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
| Cells per axis, mode | Interior unknowns | Max. nodal error | Relative residual |
|---|---|---|---|
| 24, 1 | 529 | 1.33345 × 10⁻³ | 9.79 × 10⁻¹¹ |
| 48, 1 | 2,209 | 3.33763 × 10⁻⁴ | 7.14 × 10⁻¹¹ |
| 96, 1 | 9,025 | 8.34283 × 10⁻⁵ | 4.21 × 10⁻¹¹ |
| 48, 2 | 2,209 | 1.41546 × 10⁻³ | 8.89 × 10⁻¹¹ |

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
Place fluxes where conservation uses them
Consider steady conduction on \(0<x<L\) with heat flux \(q=-k(x)T'\) and volumetric generation \(f\). Taking unit cross-sectional area, steady energy balance gives \(q'=f\). On uniform nodes separated by \(h\), integrate the balance over a control segment centred on \(x_i\):
A shared face must have the same numerical flux in both adjacent equations, otherwise summing local equations can create an artificial internal source or sink.
Use \(q_{i+1/2}=-k_{i+1/2}(T_{i+1}-T_i)/h\). Then row \(i\) of the discrete operator has diagonal \((k_{i-1/2}+k_{i+1/2})/h^2\) and off-diagonals \(-k_{i\pm1/2}/h^2\). For positive \(k\) the off-diagonals are negative and the diagonal balances them. With zero source, an unconstrained interior value is a weighted average of its neighbours. This relation explains why a source-free discrete conductor with fixed end temperatures cannot develop an interior temperature larger than both ends.
Compute the face law across an interface
For smooth \(k\) an arithmetic average of neighbouring nodal coefficients provides a second-order face approximation on a uniform grid. A sharp material interface calls for a different physical calculation. Consider two half-segments in series with constants \(k_L,k_R\) and no interface storage or contact resistance. The same flux crosses both halves. Adding their temperature drops gives \(T_L-T_R=q[h/(2k_L)+h/(2k_R)]\), hence \(k_{\rm eff}=2/(1/k_L+1/k_R)\). This is a harmonic average for equal half-widths.
With \(k_L=1,\ k_R=9\) W/(m·K) and a 10 K drop over a 0.1 m pair, the effective conductivity is 1.8 W/(m·K) and the flux is 180 W/m². Using the arithmetic mean would give 500 W/m², severely underestimating the resistance of the poorer conductor. In the limit \(k_L\to0^+\), the physical flux tends to zero while that arithmetic estimate remains finite. For unequal layer thicknesses use the actual layer resistances rather than either unweighted average.
Examine uniqueness and the role of the boundary
For homogeneous fixed temperatures and an interior vector \(u\) extended by zero at both ends, grouping adjacent row contributions gives
Each term is nonnegative. Vanishing energy requires a constant vector, and the fixed ends force that constant to be zero. Thus the interior matrix is symmetric positive definite. This reasoning justifies CG and gives a uniqueness argument that does not depend on inspection of a particular numerical matrix. With only prescribed heat fluxes a spatial constant instead remains undetermined. A solution then requires overall heat compatibility and one temperature reference or a mean constraint.
As a check, take constant \(k=1\), \(L=1\), zero end temperatures and generation 2. The exact profile \(T=x(1-x)\) has central value 0.25. Central differences recover its second derivative exactly, so all uniform grid nodes satisfy the balance without truncation error. This successful check verifies signs, boundary handling and the quadratic patch. To measure a convergence order use a smooth field with a nonzero leading truncation term, such as a sine profile, and compare at common physical positions.
Background · Can fixing one node hide an incompatible heat balance?
With specified flux at both ends, a steady source must exactly equal the net heat leaving the domain. After moving boundary terms to the right, the discrete equations have the form \(KT=b\), where \(K\) is symmetric and its rows sum to zero. Consequently
Pinning a temperature removes the undetermined additive constant. If the vector \(b\) fails this sum test, however, the pinned solve creates a reaction at that node. Physically that reaction is an unmodelled heat supply or heat sink. After solving, restore the original equation at the pinned node and inspect its residual. It exposes exactly the load that would have to be supplied to maintain the supposed steady state.
Why fixing one boundary value controls the solution
Suppose the left end of a conducting rod is held at zero temperature and the right end is insulated. A finite system of flux balances may be invertible on one mesh. We would also like a bound which survives refinement. In the continuous problem, use the space \(V=\{v\in H^1(0,L):v(0)=0\}\). Its members have square-integrable first derivatives and a well-defined endpoint value. Every admissible difference between two temperature fields belongs to this same space. The fundamental theorem of calculus and Cauchy–Schwarz give
The second inequality follows by integrating the first and bounding its inner integral by the full derivative norm squared. Thus a small temperature gradient forces the temperature itself to be small in this particular space. Take a possibly discontinuous conductivity with \(0<k_0\le k(x)\le k_1\) almost everywhere and a square-integrable heat source \(f\). Testing the balance and integrating once gives \(a(u,v)=\ell(v)\) for every \(v\in V\), with
The upper bound on conductivity gives
The lower bound gives \(a(v,v)\ge k_0\|v'\|_2^2\), called coercivity. The endpoint inequality bounds \(|\ell(v)|\) by \(L\|f\|_2\|v'\|_2/\sqrt2\). These are the hypotheses of the Lax–Milgram theorem on the Hilbert space with norm \(\|v'\|_2\). Consequently the weak solution exists and is unique. For two loads, subtract the weak equations and test with their solution difference. Cancelling one derivative norm gives
Every conforming discrete subspace inherits the same estimate.
How large a change can a load error produce?
In scaled units let \(L=1,\ k=2,\ f=3\). Integration of \(-2u''=3\), first from the insulated end and then from the fixed end, gives
Its derivative norm is
The theorem guarantees at most \(3/(2\sqrt2)=1.0607\). Raising the source everywhere by \(0.12\) changes that norm of the difference by \(0.06/\sqrt3=0.03464\), within the guaranteed \(0.04243\). The estimate also applies to nonuniform perturbations of the same load norm. If both ends are insulated, constants have zero derivative and can be added freely. A net heat input then rules out steady balance altogether.
Practise on sheet 1 · A longer rod with a clamped or insulated left end. Further reading · Heidelberg University · Lecture Notes on Scientific Computing with Partial Differential Equations · §5.5 Abstract Existence Theory, Theorem 5.22 (Lax–Milgram), and §6.3 Mixed Problem.
Eliminate boundary values with the correct sign
With four intervals on a unit rod, fixed left temperature 10, fixed right temperature 20 and zero source, multiply each row by \(h^2/k\). The three unknowns then satisfy a tridiagonal system with diagonal two, off-diagonal minus one and load \((10,0,20)^T\). Moving a fixed value to the right changes its sign, producing positive boundary contributions here. Solving gives the linearly spaced interior temperatures 12.5, 15 and 17.5. Every discrete face reports the same flux for constant \(k\).
This deliberately simple case isolates boundary elimination and sign conventions. Reversing only one load sign can generate a plausible-looking smooth curve with entirely wrong end-to-end transport. After checking the values, also sum all interior balances and verify cancellation of the internal face contributions. The resulting global statement includes only boundary fluxes and any source integrated over the interior control volumes.
Prove a discrete maximum principle from the face balances
Let positive conductances \(G_{i-1/2}\) and \(G_{i+1/2}\) connect each internal node to its neighbours, with both end temperatures specified. In the absence of internal sources its balance reads \(G_{i-1/2}(u_i-u_{i-1})+G_{i+1/2}(u_i-u_{i+1})=0\). Dividing by the sum of the conductances makes \(u_i\) a convex combination of its two neighbours. If a strict global maximum occurred inside the domain above both prescribed boundary values, its neighbours would each have to equal this maximum. Repeating along the connected grid would carry the same value to a boundary, contradicting the assumption.
The same reasoning applied to the negative field bounds the minimum. With a nonnegative internal heat source \(s_i\) on the right, an interior minimum below both boundaries would have both outgoing temperature differences nonpositive. Their positive weighted sum cannot equal a positive source, and if the sum is zero, propagation again carries the minimum to the boundary. A positive source may raise an interior maximum while preserving the lower comparison bound. Negative face conductances or a disconnected component invalidate the argument; symmetry and a small algebraic residual do not by themselves restore it.
Compare two thermal loads without inverting their matrices
Connect internal nodes 1 and 2 to end temperatures zero and ten, using consecutive conductances 1, 2 and 4 W/K. With no source the equations are
The first gives \(u_1=2u_2/3\), and the second gives
Both values lie between the boundary temperatures. The common leftward heat flow has magnitude \(40/7\) W, checked independently from each of the three temperature drops times its conductance.
Add a heat source of 7 W at node one. The difference \(v\) between new and old solutions has zero boundary values and satisfies
The second relation gives \(v_1=3v_2\), so
Both internal states warmed, consistent with the comparison principle applied to the difference. The additional outflow at the left boundary is \(1\cdot3=3\) W and at the right is \(4\cdot1=4\) W, accounting for the full applied source.
This provides two independent implementation tests. Conservation checks that the boundary power change equals the injected power. Monotonicity checks the signs of all changes in the field. A sign error in a face contribution can violate one of these checks even while the computed algebraic residual for the incorrectly assembled matrix is tiny. Both tests use physically accessible quantities and remain meaningful when no exact closed-form solution of a complex geometry is available.
The argument extends to a connected graph, since a weighted average at a maximising node requires equality along every positive-conductance edge. This observation is useful for testing an unstructured implementation. Deliberately disconnecting an entirely insulated component produces a free constant there, so boundary comparisons cannot control that component until a temperature reference or independent constraint is supplied.
Change parameters · Flux differences for an elliptic balance
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.