Jos Stam’s fluid solver has a step you have not yet earned, diffuse, and Navier-Stokes hides the same operator in the term . Both come from one equation, the first PDE in this module you can derive from a picture of a small slab of metal. The tools: the neighbor-average reading of the Laplacian from 2.11 The Laplacian & Vector Identities, the divergence theorem of 2.10 Green, Stokes & the Divergence Theorem, BVPs from 8.1 Two-Point Boundary Value Problems, and the stability of Euler steps from 4.5 Stability Regions & Stiffness. At the end sits the question that opens the next lesson: if every wiggle dies at its own rate, can we write the exact solution?
Transcript
- Stam's fluid solver has a step called diffuse, and Navier-Stokes hides the same operator in the viscous term. Both come from one equation, which we can derive from a small slab of metal. Watch a hot bump slump toward a straight line.
- Take a slab of a thin rod, of width delta x. Its energy is rho c A delta x times the temperature, and it changes only as power crosses the faces: A q of x in, A q of x plus delta x out. Shrink the slab: rho c u t equals minus q x.
- We also need a constitutive law, physics we measure. Fourier's law says heat flows from hot to cold in proportion to the slope: q equals minus k u x. Substitute, and u t equals alpha u x x, with alpha equal to k over rho c.
- Alpha is a length squared per time: heat spreads a distance L in about L squared over alpha. Copper has alpha 1.16 times ten to the minus 4, water 1.43 times ten to the minus 7. A 1 centimetre copper block evens out in 0.86 seconds, water in 698: a ratio of 809.
- Taylor expand the neighbours and add: the neighbour average minus the centre is one half delta x squared u x x. So every point is pulled toward the average of its neighbours, at rate 2 alpha over delta x squared. A bump's tip cools, a dip warms, and a straight ramp stays put.
- Steady means u x x is zero: a straight line. Start the hot bump with the ends held at 0 and 1. The lab is within one thousandth of the line at step 3591, time 0.5746, and theory agrees: 0.2906 times e to the minus pi squared t reaches one thousandth at 0.5747.
- With insulated ends any constant is steady, so conservation chooses: the total energy cannot change, so the constant is the initial mean. A hot left half flattens to 0.5, within one thousandth at step 4087, time 0.654, and the mean stays 0.50000.
- The maximum principle: at an interior maximum u x x is at most zero, so the hot spot can only cool. From random noise at r equal 0.4, the maximum falls from 0.995 to 0.509 in 100 steps and the minimum stays 0.
- Try a ripple, e to the minus lambda t times sine of k pi x over L. It solves the equation when lambda is alpha times k pi over L, squared. The rate grows as the square of the wavenumber, so the k equals 8 ripple dies 64 times faster than the single hump.
- After 100 steps, time 0.016, the lab reads 0.854, 0.531, 0.0784 and 2.98 times ten to the minus 5 for k 1, 2, 4 and 8, against continuum values of 0.854, 0.532, 0.0799 and 4.08 times ten to the minus 5. Fine detail goes first, and running backwards would amplify noise without limit.
- On a grid, use forward Euler in time and a centred difference in space. With r equal to alpha delta t over delta x squared, the new value is 1 minus 2 r times the old one plus 2 r times the neighbour average. If r is at most one half, both weights are non-negative, so no step leaves the old range.
- Above one half the old value's weight is negative and the step overshoots. The sawtooth is multiplied each step by 1 minus 4 r: minus 0.6 at r equal 0.4, minus 1 at 0.5, and minus 1.2 at 0.55, growing 20 percent a step. The lab's noise reaches 3.33 times ten to the 6.
- In 2D and 3D, u t equals alpha times the Laplacian, with 4 neighbours, then 6. The old weight is 1 minus 4 r, so r is at most one quarter, and in 3D one sixth. In d dimensions delta t is at most delta x squared over 2 alpha d: halve the cell and you need 4 times the steps.
- In Navier-Stokes, one velocity component obeys u t equals nu times the Laplacian: viscosity is momentum diffusion. Between two plates the velocity relaxes to a straight line, Couette flow. For air nu is 1.47 times ten to the minus 5, the Prandtl number is about 0.68, and a viscous layer spreads 3.8 millimetres in a second. That is why Stam solves diffuse implicitly.
- To recap. Energy balance plus Fourier's law gives u t equals alpha u x x. Curvature drives change, the steady states are a line or the mean, ripples decay at alpha k pi over L squared, and FTCS is stable exactly when r is at most one half.
- Next, 9.3 solves the rod exactly: separate variables, expand in sines, and let each mode decay at its own rate. If every wiggle dies at its own rate, can we write the exact solution?
Conservation plus a constitutive law
Almost every PDE in this course is built from two ingredients. The first is a conservation law: the amount of some stuff in a region can change only because stuff crosses the boundary (or is made inside). The second is a constitutive law that says how fast stuff crosses, which is physics you measure and not mathematics you derive. Here the stuff is thermal energy.
Take a thin rod with cross-section , density , specific heat (joules to warm a kilogram by a kelvin) and temperature . A slab between and holds thermal energy
Let be the heat flux, the power crossing a unit area, in W/m, positive toward . Power enters through the left face and leaves through the right, so
Divide by and let the slab shrink: over becomes , which gives . This is the one-dimensional case of the general law : the rate of change of density plus the divergence of its flux equals the sources. (2.7 Divergence: Sources & Sinks showed why a divergence is net outflow per volume.) A heater adds a source term on the right.
Now the constitutive law. Fourier’s law (an experimental fact, from memory not derived) says heat flows from hot to cold, in proportion to the steepness of the temperature profile:
with the thermal conductivity in W/(m K). The minus sign is the second law of thermodynamics in one character: with the right side is hotter, so heat must flow left, . Substituting,
The diffusivity has units m/s, and that is the whole story of its meaning: heat spreads a distance in a time of order . Rough values from memory: copper , , gives m/s; water , , gives ; air , , gives . A cm copper block evens out in about s; a cm layer of still water needs s, almost twelve minutes. The ratio of the two diffusivities is .
The equation is linear, second order in space (a condition at each end) and first order in time (one initial profile).
as neighbor average minus centre
What does do to a point? Taylor-expand the neighbors, as in 2.4 Taylor Series in One and Several Variables:
Add the two and divide by two:
So the heat equation says, up to higher-order terms,
Every point is pulled toward the average of its two neighbors, at a rate that grows with finer detail. At the tip of a hot bump the neighbors are cooler than the centre, the bracket is negative, and the tip cools. In a cold dip the neighbors are warmer and the dip warms. On a straight ramp each point is the exact average of its neighbors, the bracket vanishes, and nothing changes there: the profile is a steady state even though heat is flowing through it. Curvature drives the change in temperature; slope drives the flow.
Steady states
If nothing changes, , and the heat equation reduces to the ODE , whose solutions are . The boundary conditions pick and .
- Both ends fixed, and : . This is the BVP of 8.1 Two-Point Boundary Value Problems with the right-hand side set to zero. The flux is constant: whatever enters at one end leaves at the other.
- Both ends insulated, (no flux): any constant solves the ODE, so the ODE does not choose one. Conservation does. Integrate the PDE over the rod: . The total energy cannot change, so the constant must equal the initial mean temperature.
- One end fixed, one insulated: the flux must vanish at the insulated end, so the profile is the constant .
The maximum principle
Maximum principle. Let solve the heat equation for and . Then the largest value of over that rectangle is attained at or at an end , (and the same for the smallest value). With insulated ends the statement is the same with ends dropped: the range of never leaves the range of the initial data.
The mechanism: at an interior maximum , so and the hot spot can only cool. (The gap, that may equal zero there, is closed in a full proof by adding a small to make the inequality strict.) Heat left alone does not concentrate itself. For simulation this is a design rule: a step that produces a temperature outside the initial range, or a negative smoke density, has an error of the wrong kind.
Smoothing: short wavelengths die first
Try a ripple, . Then and , so the equation holds exactly when
The decay rate grows as the square of the wavenumber. The ripple with has eight half-waves in the rod and decays times faster than the single hump with . Mechanism: a ripple of wavelength has curvature of order times its amplitude, so its crests are far above the average of their neighbors and its troughs far below, and the pull toward the average is correspondingly stronger. Fine detail has the steepest curvature and is erased first; broad features linger.
Hence the smoothing behavior of diffusion. Any initial profile is made of ripples, and after a time everything with is gone. It also gives diffusion its arrow of time: running the equation backwards would multiply each ripple by , amplifying noise at the shortest scales without limit, so the backward problem is ill-posed.
The rod’s slowest mode sets the relaxation time. With both ends fixed, the straight-line steady state is approached like , so the -folding time is , a tenth of the crude .
Diffusion in 2D and 3D
Nothing in the slab argument needs the slab to be one-dimensional. For a small region with boundary , the energy balance is , with Fourier’s law now . The divergence theorem turns the surface integral into a volume integral, and because was arbitrary the integrands must match:
The neighbor-average reading carries over: on a grid is times (average of four neighbors minus centre) in 2D, times that for six neighbors in 3D. Steady states satisfy , and the maximum principle holds in any dimension for the same reason: at an interior maximum .
Viscosity is momentum diffusion
Return to 11.4 Viscosity & the Navier–Stokes Equations. Strip away advection and pressure, and one velocity component obeys
That is the heat equation with in the role of . A fast layer of air hands momentum to a slower one as a hot rod hands heat to a cold one, because molecules wander between layers carrying their velocity. The kinematic viscosity of air, m/s (from that lesson), is near its thermal diffusivity above: the ratio is the Prandtl number of air (the name and its role are from memory). Everything above transfers: a viscous layer spreads a distance about ( mm after one second, a scale and not an exact value), the velocity between two plates relaxes to a straight line (Couette flow), and viscosity kills the smallest eddies first, the dissipation end of 11.9 Turbulence: An Introduction and the reason layers thicken in 11.8 Boundary Layers.
Discretise it: FTCS and the one-half limit
Put the equation on a grid , with the temperature at step , time step . Replace by the forward difference (Euler) and by the centred second difference, the stencil you derived from Taylor series. This is FTCS (forward time, centred space), and with :
The right-hand form is the neighbor-average picture made literal: a weighted average of the old value and the neighbors’ average, with weights and . Two consequences, one statement.
Discrete maximum principle. If , both weights are non-negative and add to one, so the new value is a convex combination of old values and cannot leave their range. Each step respects the maximum principle, hence so does the run. At the scheme replaces each value by the exact neighbor average.
Instability above one-half. If , the weight is negative: a point that is above its neighbors is pushed below them, overshooting. The worst case is the sawtooth , which each step multiplies by . At the factor is : it flips sign and shrinks. At it is exactly , flipping forever. At it is : every step grows it by . The ODE view of 4.5 Stability Regions & Stiffness gives the same limit. The grid’s ripples are eigenvectors of the method-of-lines system, with eigenvalues from down to about ; forward Euler needs , which is , so .
In 2D the same argument has weight on the old value and on the average of four neighbors, so ; in 3D, . In dimensions : halve the cell size and you need four times as many steps, on four times as many cells in 2D.
The lab
The rod has , (time in units of ), intervals, and . What to try, and what the sim prints:
- Steady state, ends fixed at and . Start from the hot bump. The curve slumps toward the straight line, and the readout falls below at step , . Theory predicts it: the slowest mode of starts at amplitude (projected from the initial profile), and gives .
- Insulated ends. Choose the step preset (left half at , right half at ) and insulate both ends. The mean readout stays and the profile flattens to within of at step , ; the slowest mode is a cosine of initial amplitude , and .
- Smoothing. Fixed ends at , , start from one smooth bump or eight ripples. After steps () the mode readouts give for (continuum : ), for (), for () and for (). The ripple, grid points per wavelength, is the one the scheme gets least right.
- Maximum principle and the limit. Pick random noise (fixed ends at ). At the running max falls from to in steps and the min stays , inside the starting range as promised. At the range is : inside, but the sawtooth part never decays (factor ). At it is , flagged as outside, with the factor shown.
Fixed ends are held by the scheme; the insulated ends use a ghost node with , which enforces zero slope: .
Computing it
The first loop reproduces item 3 of the lab and the second item 4.
Concept checks
Problems
A copper rod ( W/(m K), from memory) of length m has its ends held at C () and C (). Find the steady profile, the temperature at m, and the heat flux.
Show worked solution
Steady means , so . At : C, the midpoint average. The flux is W/m: negative, so heat flows toward , from hot to cold, at kW per square metre of cross-section. The same flux crosses every cross-section, since .
A rod has the nodal values with both ends held at . Take one FTCS step for (a) , (b) , (c) . Explain (c) with the weights and .
Show worked solution
Interior nodes have values and neighbors , , .
(a) : node : ; node : ; node : . Result .
(b) : . The centre is : replaced by the neighbor average.
(c) : . The centre is . The weight on the old value is , so the former hot spot is pushed below its neighbors, and below the initial minimum : a violation of the maximum principle after one step. Repeating this flips the sign every step and the magnitude grows by for the worst mode.
(a) Show that for insulated ends is constant. (b) Derive the largest stable for FTCS in 2D on a square grid and the largest for air momentum, m/s, on a mm grid.
Show worked solution
(a) for insulated ends, so the integral equals its initial value.
(b) In 2D, , with . The weights are non-negative and sum to one iff . Then s. This matches the limit quoted in the Stable Fluids lesson.
Key Takeaways
- Energy conservation on a slab gives ; Fourier’s law closes it into with , a length squared per time.
- is times (neighbor average minus centre): temperature changes where the profile is curved, and a straight ramp is steady even though heat flows through it.
- Steady states solve : a straight line for fixed ends, the conserved mean for insulated ends.
- The maximum principle (a hot spot cannot grow, no new extremes) comes from at a maximum.
- A ripple decays at rate : times faster for than . Fine detail is smoothed first, and the backward problem is ill-posed.
- FTCS is ; it keeps the maximum principle and is stable exactly when (1/4 in 2D, 1/6 in 3D). At the lab’s noise reaches in steps.
- In multiple dimensions ; the viscous term in Navier-Stokes is the same equation for momentum, which is why Stam solves diffusion implicitly.
- Next, 9.3 solves the rod exactly: separate , expand the initial profile in sines, and let each mode decay at its own rate .