A cooling curve, integrated step by step

A part comes out of a furnace and cools in still air. If it is small enough and conductive enough that its inside and its surface stay at the same temperature, the whole thing is one lumped heat capacity losing heat to the room, and its temperature obeys a first-order differential equation with a known solution. That makes it the right problem to check a numerical integrator against: the answer is already known, so the question is whether the method reproduces it.

use steel
use constants
digits 4

The part, and whether the method applies

Lside=50⁢mm
V=Lside3=(50⁢mm)3=125000⁢mm3
Asurf=6·Lside2=6·(50⁢mm)2=15000⁢mm2
mpart=ρsteel·V=7850⁢m⁻³·kg·125000⁢mm3=0.9813⁢kg
csteel=480⁢Jkg·K
hair=25⁢Wm2·K
ksteel=45⁢Wm·K

The lumped assumption holds when conduction inside the part is fast compared with convection off its surface — the Biot number, on the characteristic length that is volume over area. Below about a tenth, the inside and the surface differ by less than the other approximations here.

Lchar=VAsurf=125000⁢mm315000⁢mm2=8.333⁢mm
Bi=hair·Lcharksteel=25⁢kg·s⁻³·K⁻¹·8.333⁢mm45⁢m·kg·s⁻³·K⁻¹=0.00463
checkBi≤0.1=0.00463≤0.1pass

The equation

The time constant is the heat the part stores divided by the rate it loses it at one kelvin of excess.

τ=mpart·csteelhair·Asurf=0.9813⁢kg·480⁢m²·s⁻²·K⁻¹25⁢kg·s⁻³·K⁻¹·15000⁢mm2=1256⁢s
Troom=300⁢K
Tstart=500⁢K

Absolute temperatures throughout. An offset scale has no place in this arithmetic — the equation subtracts one temperature from another and scales the difference, and °C is refused for it — so the worksheet works in kelvin and converts at the end if a reader wants degrees.

fn cooling defined

Integrating it

rk4 names its method and takes its step count, because both change the answer. Fifty steps over five time constants is a step of a tenth of a time constant, which for a smooth exponential is far finer than it needs to be.

tend=5·τ=5·1256⁢s=6280⁢s
steps=50
history=rk4⁡(cooling,Tstart,0⁢s,tend,steps)=rk4⁡(cooling,500⁢K,0⁢s,6280⁢s,50)=[51x2 table]

Against the answer that is already known

fn exact defined
Tfinal_rk4=historysteps+1,2=([51x2 table])50+1,2=301.3⁢K
Tfinal_exact=exact⁡(tends)=exact⁡(6280⁢ss)=301.3⁢K
errorK=|Tfinal_rk4−Tfinal_exact|=|301.3⁢K−301.3⁢K|=6.104×10−6⁢K
checkerrorK≤0.001⁢K=6.104×10−6⁢K≤0.001⁢Kpass

Five hundred kelvin falling to three hundred and one, and the two methods agree to a thousandth of a kelvin. That is the fourth-order method earning its name: halving the step divides the error by sixteen.

The step count is part of the answer

The same integration over five steps rather than fifty — a step of a whole time constant, which is the sort of thing that looks reasonable and is not.

coarse=rk4⁡(cooling,Tstart,0⁢s,tend,5)=rk4⁡(cooling,500⁢K,0⁢s,6280⁢s,5)=[[0 s, 500 K], [1256 s, 375 K], [2512 s, 328.1 K], [3768 s, 310.5 K], [5024 s, 304 K], [6280 s, 301.5 K]]
Tfinal_coarse=coarse6,2=([[0 s, 500 K], [1256 s, 375 K], [2512 s, 328.1 K], [3768 s, 310.5 K], [5024 s, 304 K], [6280 s, 301.5 K]])6,2=301.5⁢K
errorcoarse=|Tfinal_coarse−Tfinal_exact|=|301.5⁢K−301.3⁢K|=0.1356⁢K

Still close, because an exponential decay is the easiest case there is. A worksheet integrating something stiffer would find the same step size wrong by a great deal more, and nothing here would say so — which is why the step count is written where a reader can see it rather than chosen by the engine.

The curve

axis y limits
plot⁡(history)
0 2000 4000 6000 8000 300 350 400 450 500 s K