Physics Lab · Thermal physics

Thermal equilibrium

What changes when two systems at different temperatures can exchange energy, and what changes when they hold 1 or 100,000 particles each?

Physics Lab · Ahmed Maarouf

Interactive model

System A · left800 K

800 K
20 u

System B · right200 K

200 K
20 u

Number of particles in each system · 200 total

100 per side
whole number, 1 to 100,000; press Enter
Presets (per side):
Paused · adjust sliders, then run
Seed 00000000Reset draws a fresh random seed; the same seed with the same settings replays the same energies and temperatures (the drawn dots follow your screen's frame timing; blank field: replay the current seed).

Starts paused. With reduced motion enabled, the dots stay still while the physics, graphs and readouts keep running.

The thin dashed arrow shows one sampled microscopic exchange, not net heat flow; its length represents the energy exchanged. The solid arrow shows net energy transferred over the trailing 2 seconds. At equilibrium, exchanges continue in both directions, and a momentary reverse-flow arrow is not a violation of anything. Exchanges pair particles at random, regardless of position, so dots pass through each other by design. Particles remain on their own side.
Last exchange: none yet2-second net: balanced
System A · current800 K
last exchange
System B · current200 K
For 100 particles per side, the mean kinetic temperature at equilibrium is 500 K.

Particle speeds

Live histogram of the speeds of all NN particles on each side, with dashed reference curves at the measured temperatures.

A sampleB sampleDashed: large-N (Maxwell–Boltzmann) expectation; the finite-N distribution differs visibly below N ≈ 20

Temperature history

Instantaneous kinetic temperatures versus simulation time, sampled every 0.1 s. The dashed grey line is TeqT_{\mathrm{eq}}, the mean kinetic temperature. The graph keeps the full run from reset.

System A · solidSystem B · dashedTeqShaded: where TA spends 68% / 95% of its time at equilibrium (exact, finite N)exact SD = 35.3 K

Entropy of the energy split

ΔS = −44.2 kB

ΔS=S(EA)−Smax\Delta S = S(E_A) - S_{\max}, the Boltzmann entropy of the split of the energy between A and B, relative to its maximum (for N≥2N \ge 2, the most probable split). The graph shows it per particle, ΔS/(NkB)=N−1Nln⁡[4x(1−x)]\Delta S/(N k_B) = \frac{N-1}{N}\,\ln[4x(1-x)] with x=EA/Ex = E_A/E; the value beside the title is in kBk_B.

Per particle, the deficit shrinks as NN grows, so large NN looks smooth and small NN noisy. In units of kBk_B the equilibrium dips do not shrink: the fraction of equilibrium time with ΔS<−1kB\Delta S < -1\,k_B is 0,0.059,0.141,0.156→0.1570,\ 0.059,\ 0.141,\ 0.156 \to 0.157 at N=1,2,10,100,∞N = 1, 2, 10, 100, \infty (exact). The total microcanonical entropy of the isolated system is constant; the plotted entropy can fall because it keeps only the energy split EAE_A.

Equilibrium statistics: measured next to exact

Counted from 0.1 s samples, only after a burn-in of 32.5 s. Neighbouring samples are strongly correlated (relaxation time τ=6.5s\tau = 6.5\ \mathrm{s}), so the error bar counts about one independent sample per 2τ=13s2\tau = 13\ \mathrm{s}. The exact values are tail probabilities of x=EA/Ex = E_A/E, which is Beta(N,N)\mathrm{Beta}(N, N) distributed at equilibrium.

Fraction of time with |TA−Teq|>0.1Teq|T_A - T_{\mathrm{eq}}| > 0.1\,T_{\mathrm{eq}}equilibrating… (32.5 s)

Fraction of time at least as far from equilibrium as the start, |x−12|≥|x0−12||x - \tfrac{1}{2}| \ge |x_0 - \tfrac{1}{2}|equilibrating… (32.5 s)

How to read this model. In two dimensions, a particle's average translational kinetic energy is ⟨K⟩=kBT\langle K\rangle = k_B T. At a shared temperature, lighter particles have higher typical speeds, while the mean kinetic energy per particle is the same. With equal particle numbers, 800 K and 200 K approach the mean kinetic temperature of 500 K regardless of the selected masses.

Teq=TA0+TB02(equal N)T_{\mathrm{eq}} = \frac{T_{A0} + T_{B0}}{2}\quad (\text{equal } N)SD(TA)=Teq2N+1\mathrm{SD}(T_A) = \frac{T_{\mathrm{eq}}}{\sqrt{2N + 1}}f(v)=mvkBTe−mv2/(2kBT)f(v) = \frac{m v}{k_B T}\, e^{-m v^2/(2 k_B T)}

Model limits. Energy moves by a Kac-type stochastic exchange between randomly chosen pairs (Kac, 1956): at random times a pair of particles, one from each side for heat exchange or two from the same side for mixing, rotates one pair of their mass-weighted velocity components, q=mvq = \sqrt{m}v, by a small fixed angle. Pairs are chosen independently of position, so particles never collide; the dots pass through each other by design and bounce only off the walls of their own box. Molecular collisions and real wall atoms are not simulated. Each rotation conserves kinetic energy, so the total energy is conserved to machine precision. Because the rules are this simple, the statistics of the energy split are known exactly: the shaded band, the entropy axis and the exact readouts come from them. The relaxation time τ≈6.5s\tau \approx 6.5\ \mathrm{s}, set by the exchange rate and angle and the same at every NN, is a property of the model, not of a real gas. Changing NN, a temperature or a mass restarts the run with fresh random initial conditions.

Fluctuations and the second law

Heat flows from hot to cold on average. Start A hot and B cold and the energy split relaxes towards equal shares. Once there, the system is at equilibrium, and the macrostate entropy (the entropy of the energy split, in the entropy panel) goes down as often as it goes up. Large NN does not stop the dips. What it changes is their size relative to the system: an equilibrium dip is of order kBk_B at every NN, while a macroscopic change, such as recreating the 800 K / 200 K difference, is of order NkBN k_B (about 4,500kB4{,}500\,k_B at N=10,000N = 10{,}000).

The rules have no arrow of time. Each exchange rotates by +θ+\theta or −θ-\theta with equal probability, and the −θ-\theta rotation undoes the +θ+\theta one, so the exchange rules prefer no direction of time: the sequence of energy splits in an equilibrium run is just as likely played backwards. The arrow you see during relaxation comes from the improbable starting state, not from the rules.

Which entropy never decreases? The ensemble (Gibbs–Shannon) entropy, the entropy of the probability distribution over all the runs these settings could produce, never decreases here, and the mean entropy production is non-negative. Only a single run's macrostate entropy, the trace in the entropy panel, dips.

Undoing the initial difference. The second readout gives the exact fraction of equilibrium time spent at least as far from equilibrium as the start. For an 800 K / 200 K start it is 0.40 at N=1N = 1, 0.208 at N=2N = 2, and about 10−194010^{-1940} at N=10,000N = 10{,}000: not forbidden, but never going to be seen.

How big are the fluctuations?

At equilibrium the fraction of the energy held by A, x=EA/Ex = E_A/E, follows the Beta(N,N)\mathrm{Beta}(N, N) distribution, so TA=2TeqxT_A = 2T_{\mathrm{eq}}\,x has standard deviation SD(TA)=Teq/2N+1\mathrm{SD}(T_A) = T_{\mathrm{eq}}/\sqrt{2N + 1}, whatever the masses. For Teq=500KT_{\mathrm{eq}} = 500\ \mathrm{K}:

NN per sideSD(TA)\mathrm{SD}(T_A)
1289 K
2224 K
10109 K
10035.3 K
1,00011.2 K
10,0003.54 K
100,0001.12 K

A reverse arrow breaks nothing. A momentary reverse-flow arrow is not a violation of anything. Single exchanges go both ways all the time, and at equilibrium the 2-second net arrow points B→A\mathrm{B} \to \mathrm{A} as often as A→B\mathrm{A} \to \mathrm{B}.

Fluctuations cannot be harvested. To exploit a lucky dip, a device must measure the state and later erase that record; measurement and erasure cost at least as much as the dip can deliver, so on average nothing is gained (Szilard's engine, Landauer's principle, Bennett's analysis).

What about fluctuation theorems? Fluctuation theorems are exact results about time-integrated entropy production, the entropy produced over a stretch of time under a specified ensemble of initial states and a specified protocol, not about the macrostate entropy at one moment. The one for two bodies exchanging heat (Jarzynski & Wójcik, 2004) needs canonical initial states, each body at a fixed temperature with a fluctuating energy. This model starts each side at exactly its set energy, so the page does not claim to show that theorem; the papers are listed below as further reading only.

A note on temperature

The displayed T=E/(NkB)T = E/(N k_B) is the kinetic temperature (the Gibbs, or volume, temperature in two dimensions). The Boltzmann (surface) entropy gives E/((N−1)kB)E/((N - 1)\,k_B) for each side, and 2NTeq/(2N−1)2N\,T_{\mathrm{eq}}/(2N - 1) for the whole isolated system, whose Gibbs temperature is exactly TeqT_{\mathrm{eq}}; that is why TeqT_{\mathrm{eq}} is called the mean kinetic temperature (Dunkel & Hilbert, 2014; Frenkel & Warren, 2015). With the surface temperatures, dS=dQ(1/TB−1/TA)\mathrm{d}S = \mathrm{d}Q\,(1/T_B - 1/T_A) for heat dQ\mathrm{d}Q passing from A to B is exactly the increment of the plotted ΔS\Delta S. For a few particles, TT is an estimator of the energy, not a stable thermodynamic property.

Things to try

Further reading

  1. Jarzynski & Wójcik, PRL 92, 230602 (2004)
  2. Evans, Cohen & Morriss, PRL 71, 2401 (1993)
  3. Evans & Searles, PRE 50, 1645 (1994)
  4. Gallavotti & Cohen, PRL 74, 2694 (1995)
  5. Crooks, PRE 60, 2721 (1999)
  6. Wang et al., PRL 89, 050601 (2002)
  7. Evans & Searles, Adv. Phys. 51, 1529 (2002)
  8. Dunkel & Hilbert, Nat. Phys. 10, 67 (2014)
  9. Frenkel & Warren, Am. J. Phys. 83, 163 (2015)
  10. Landauer, IBM J. Res. Dev. 5, 183 (1961)
  11. Bennett, Int. J. Theor. Phys. 21, 905 (1982)
  12. Kac, Proc. 3rd Berkeley Symp. Math. Stat. Prob. 3, 171 (1956)