SELLC Physics Lab

Ideal gas particle box

Argon atoms as hard discs in a nanometre box with a movable piston. Nothing here assumes PA = NkBT — the pressure is measured from the momentum the atoms actually deliver to the walls, and the gas law comes out of the collisions.

First experiment

  1. Predict. 100 hard discs fill a 10 nm box at 300 K. Double the starting temperature to 600 K in the same box. Does the wall pressure P double? Does Z = PA/NkBT change?
  2. Manipulate. Start from the defaults (load this setup) and note P (wall impulse) and Z. Then set Initial temperature T₀ to 600 K: the gas restarts from the same seed.
  3. Observe. P goes from about 3.44 to about 6.90 mN/m — double, to within 1 % — and P · A keeps tracking N kB T. Z stays near 1.17 at both temperatures, and vrms rises by √2, from 353 to 500 m/s.
  4. Explain. Pressure here is momentum delivered to the walls per unit length per second (the box is two-dimensional, hence N/m). Atoms √2 faster hit √2 harder and √2 as often, so P ∝ T. Z sits above 1 because the discs take up area; hard discs have no energy scale, so Z depends on the area fraction η, not on T.

More experiments, with expected results: What to try. Symbols, units and assumptions: Physics & limits.

The box

2-D molecular dynamics

Disc colour runs from blue (slow) to orange (fast) — the same information the speed histogram below carries. The dashed rectangle is the piston's full travel; the hatched block is the piston itself. One disc is ringed and drags its recent track behind it, so you can count free flights between collisions by eye.

State — the gas law, measured

Sim time—
N—
T (equipartition)—
A (area)—
P (wall impulse)—
P uncertainty—
P · A—
N kB T—
Z = PA / NkBT—
Z, hard-disc EOS—
Area fraction η—
T, ideal adiabat—
T, hard-disc adiabat—
Piston—
RNG seed—

Conservation, transport and statistics

Kinetic energy—
ΔU vs reset—
First-law residual—
Work by piston—
|Σ p| (not conserved)—
λ measured—
λ dilute theory—
λ Enskog (dense)—
vrms—
⟨v⟩—
χ² / ν vs Maxwell—
Throughput—

Measurements

Speed distribution vs the 2-D Maxwell–Boltzmann curve

  • Measured (200 ps of samples)
  • f(v) = (m/kBT) v e−mv²/2kBT
  • vmp = —
  • ⟨v⟩ = —
  • vrms = —
The curve is not fitted. It is the analytic 2-D density evaluated at the temperature measured from ⟨v²⟩ of the same 200 ps of samples it is drawn against (χ²/ν uses its own samples the same way), so any disagreement is real disagreement. The three vertical bands mark the characteristic speeds; note that they are not at the same place — in 2-D their ratio is fixed at 1 : 1.253 : 1.414.

P–A trace as the piston moves

  • Measured trace
  • Ideal isotherm P = NkBT/A
  • Hard-disc isotherm P = Z(η)NkBT/A
  • Ideal adiabat PA² = const
  • Hard-disc adiabat (Henderson EOS)
All four ghosts are re-anchored to the state at which the piston last started moving (with isothermal walls, to the wall setpoint). With the thermostat off and adiabatic walls, a slow compression runs a few per cent above the purple hard-disc adiabat; with isothermal walls it runs a few per cent above the teal hard-disc isotherm — and well above the blue ideal one. The few per cent is the hard-wall surface term described under Assumptions and limits. The green and blue curves are the textbook ideal gas; the gap between each and its hard-disc partner is the excluded-area effect, and it is real, not numerical error.

The physics

Units warning — this gas is two-dimensional. In 2-D there is no volume and no area to push against: a wall is a line, so pressure is a force per unit length and is measured in N·m⁻¹, not pascals. The "volume" is the box area A, in m². Their product PA is an energy in joules, which is exactly what NkBT is. Every number on this page is SI; nothing is in arbitrary units.

Governing equations

Equation of state (2-D)

P A = N kB T

Temperature from equipartition (2 degrees of freedom)

⟨Ekin⟩ = kBT ⟹ T = m ⟨v²⟩ / (2 kB)

Pressure, measured from wall impulse

P = ( Σ 2m|v⊥| ) / ( Δt · L )

  • L is the wall length — here the full perimeter 2(Lx + Ly).
  • Δt is a rolling 400 ps window. The quoted ± is the standard error of that window mean, corrected for correlation: var(mean) = (s²/n)·τint over the 80 five-picosecond chunks. The correction is not cosmetic — the chunks are strongly anti-correlated (a wall hit missing from one chunk lands in the next), so the textbook s/√n overstates the real reproducibility of P by 1.8–7.1× depending on density. Even corrected, treat it as good to about a factor of two: the anti-correlation runs over the ballistic wall-to-wall crossing time, which is a sizeable fraction of the 400 ps record itself.
  • At the moving piston the impulse is 2m|vx − vwall|, which reduces to 2m|vx| when it is parked.
Compressibility factor and the excluded-area correction

Z = PA / (NkBT) = 1 + 2η + 3.13η² + …

ZHD = (1 + η²/8) / (1 − η)² , η = Nπr²/A

  • η is the fraction of the box the discs themselves occupy.
  • Hard discs have no attraction, so Z ≥ 1 always. It can only rise as you compress.
  • The second virial coefficient of hard discs is B2 = πd²/2, which is where the leading 2η comes from.
Mean free path (hard discs, 2-D)

λ0 = 1 / (2√2 n d) , n = (N − 1)/A , d = 2r

λEnskog = λ0 / g(d) , g(d) = (1 − 7η/16) / (1 − η)²

  • Measured on screen as (total distance flown by all discs) ÷ (2 × number of disc–disc collisions). Every collision retires two free flights, hence the 2.
  • In 2-D the "cross-section" is a length, not an area. A disc collides with any scatterer whose centre falls within d of its path on either side, so the swept strip is 2d wide — that is where the leading 2 comes from. Writing λ = 1/(√2 nd) is a common slip and overstates the free path by exactly a factor of two.
  • The √2 is the mean-relative-speed factor ⟨vrel⟩ = √2⟨v⟩, which holds for equal masses in any dimension.
  • n is the density of collision partners, and each disc has N − 1 of them. With N/A the theory is 11 % short at N = 10 — the measurement there is 1.12 ± 0.02 times that value — and the difference vanishes as N grows.
  • λ0 is the dilute limit. At finite density the discs crowd each other and collide more often by the contact factor g(d) — the same g that gives Z = 1 + 2ηg(d). Compare the measured value against both readouts: at the default settings it lands on the Enskog line, not the dilute one.
Maxwell–Boltzmann speed density (2-D)

f(v) = (m/kBT) v exp(−mv²/2kBT)

vmp = √(kBT/m) , ⟨v⟩ = √(πkBT/2m) , vrms = √(2kBT/m)

  • Note the bare factor of v: in 2-D the velocity-space Jacobian is 2πv dv, not 4πv² dv. The 3-D curve is a different shape.
  • ⟨v⟩ : vmp : vrms = 1 : 0.798 : 1.128 in 2-D.
Collision with a MOVING wall

vx′ = 2vwall − vx

  • Elastic reflection in the wall's frame, transformed back. An inbound piston (vwall < 0) sends every atom back faster — that factor of two is the compression work, atom by atom.
  • Treat the wall as stationary during compression and the gas silently refuses to heat up. That is the single most common bug in this kind of simulation.
Adiabatic compression of a 2-D monatomic gas

Cv = kB , Cp = 2kB , γ = Cp/Cv = 2

T Aγ−1 = TA = const , PAγ = PA² = const

  • γ = 2 here, not 5/3 — that value belongs to a 3-D monatomic gas with 3 translational degrees of freedom. In 2-D there are only 2, so U = NkBT and γ = 2.
  • Halve the area quasi-statically and the temperature doubles — provided the gas is dilute.
…and what the real hard-disc gas actually does

d ln T = − Z(η) d ln A ⟹ ln(T/Tref) = ∫ Z(η) d ln η

  • Hard discs store no potential energy, so U = NkBT and Cv = NkB exactly as for an ideal gas — but the work term −PdA carries the real pressure ZNkBT/A.
  • Set Z ≡ 1 and this collapses to TA = const. With the real Z > 1 the gas heats more: a crowded gas is stiffer, so the piston has to do more work per unit area swept.
  • Both predictions are shown live in the readouts. At η ≈ 0.08 the two differ by about 20 %, and the measurement follows the hard-disc curve — which is precisely why real-gas compressor calculations do not use the ideal relation.
First law, as bookkept on screen

ΔU = Wpiston + Qwalls + Qthermostat

  • The "first-law residual" readout is that identity minus zero. Hard-disc pair collisions cannot change the total energy, so the residual stays at rounding level (~10⁻¹⁵) no matter how violent the gas gets. If it ever grows, the collision solver is broken.
  • Do not confuse it with "ΔU vs reset" above it. That one is simply Ekin minus its value at the last reset, and it is only expected to be zero while the piston is parked and the thermostat is off — it turns green only then. Run experiment 3, 4 or 5 and it climbs past +100 %, which is the whole point of those experiments: the piston is putting work in. The invariant to watch during a stroke is the residual, not ΔU.

What to try

  1. Watch the gas law hold. Leave everything at its default and press Play. Compare the P · A and N kB T readouts: they should track each other, and Z should sit clearly above 1. Expected: Z ≈ 1.17 at Lx = 10 nm — not exactly 1, because the discs have real size. Now drag disc radius down to 0.05 nm and wait a few seconds. Expected: Z falls to about 1.02. Point particles are what "ideal" actually means.
  2. Squeeze it and see Z climb. Push box width from 16 nm down to 4 nm in steps, letting each setting settle. Expected: Z rises monotonically from about 1.11 to roughly 1.50 — and on to about 1.76 if you take the piston all the way to its 3 nm stop — rising in step with the hard-disc equation of state shown beside it, and never dipping below 1. There is no attraction in this model, so nothing can pull Z under 1 — real gases do go below 1, and that is exactly what the van der Waals a term is for.
  3. Adiabatic compression: the piston does the heating. Set N = 100, disc radius 0.08 nm (dilute, so the gas really is near-ideal), thermostat off, walls adiabatic, piston speed 10 m/s. Note T and A at 16 nm, then drag the width to 8 nm and wait for the piston to arrive. Expected: T rises from 300 K to about 625 K — the product T·A is preserved to within about 5 %, which is the γ = 2 adiabat. Nothing added heat: the inbound wall simply returned every atom faster than it arrived.
  4. Now make it non-ideal. Repeat with the radius back at 0.17 nm and N = 200. Expected: T lands near 750 K, not 600 K — a 25 % "error" against TA = const that is not an error at all. Compare the two adiabat readouts: the hard-disc prediction is right to about 2 %, and the P–A trace follows the purple curve rather than the green one. Finite particle size makes the gas stiffer, so the same stroke does more work.
  5. Break the quasi-static assumption. Repeat experiment 4 with piston speed at 200 m/s, comparable to the ~310 m/s mean thermal speed. Expected: the gas ends up hotter still — typically 820–980 K instead of 750 K — and the trace overshoots even the hard-disc adiabat. The exact figure depends on the seed: a fast stroke is not a string of equilibrium states, so the luck of which atoms meet the piston matters. A fast piston piles atoms up in front of itself, so it pushes against a higher local pressure than the equilibrium value — that is irreversibility, and it is why real compressors need intercooling.
  6. Isothermal instead. Set walls to Isothermal, leave the setpoint at 300 K, drop the piston back to 5 m/s and do the same compression. Expected: T stays near 300 K, and the trace follows the teal hard-disc isotherm, not the blue ideal one: measured, it sits about 1.2× above the ideal isotherm at the start of the stroke and about 1.45× above it at 8 nm, because Z climbs as the box shrinks. The compression work leaves through the walls as heat instead of accumulating as internal energy — and the Work by piston readout counts only that work, not the heat the piston face itself exchanges.
  7. Build the Maxwell distribution from nothing. Set initial velocities to "all discs at one speed" and reset. That mode deliberately skips the usual equilibration, so for the first instant every disc has identical speed and the histogram is a single spike sitting nowhere near the curve. Expected: the spike is visible for the first few picoseconds; χ²/ν starts at two to four times its equilibrium value and settles near 1 within roughly 100 ps of gas time, while the total kinetic energy — and therefore T — never changes by so much as one part in 10¹⁴. Equilibrium is a statement about the distribution, not about the energy.

Assumptions and limits

  • Two dimensions, not three. Every exponent changes: γ = 2 rather than 5/3, the speed density carries v rather than v², and pressure has units of N·m⁻¹. Do not carry these numbers into a 3-D problem.
  • Hard discs: infinitely stiff, no attraction. There is no Lennard-Jones well, so this gas can never condense and Z can never fall below 1. Real argon at 300 K and high density has Z < 1 because of attraction; that physics is absent here by construction.
  • Structureless particles. No rotation, no vibration, no electronic states — fine for a monatomic gas, wrong for anything molecular. Diatomics would add degrees of freedom and change Cv and γ.
  • Classical mechanics. At these densities and temperatures the thermal de Broglie wavelength of argon is ~0.016 nm, far below the mean spacing, so the classical treatment is safe. It would not be for helium near 4 K.
  • Discrete-time collision detection. Overlaps are removed by a positional correction rather than by solving for the exact time of impact, and the step sub-divides automatically when a fast disc would move more than a quarter of a diameter. That keeps energy exact but leaves the collision times slightly approximate. Below about 15 % packing nothing much suffers: λ tracks the Enskog value to within about 2 % (the residual is a wall effect, not the collision timing). Above roughly 30 % packing both measurements start to drift — λ by up to about 5 % at the 45 % cap (most at high temperature), and the wall pressure by a few per cent. The pressure is the one to watch, because the bias there is visible: Z for hard discs is a function of η alone and cannot depend on temperature, yet near the cap the measured Z spreads about 5 % between T = 50 K and T = 1200 K at identical η. That spread is pure numerics, and it is the honest limit of this solver.
  • Hard walls, not periodic boundaries — so the measured Z sits above the bulk EOS beside it. The disc centres are confined to (Lx − 2r)(Ly − 2r), not to LxLy, so the contact density at the wall — and with it PA/NkBT — carries a surface term on top of the bulk hard-disc EOS that grows with the wall length per unit area. Measured with the default discs, it is about 2 % at Lx = 16 nm and 7 % at the 3 nm stop. The naive excluded-strip estimate, 2r(Lx + Ly)/A (4.6 % and 14 % here), sets the scale, not the value: the measured term is roughly a third to a half of it. This is real physics, not solver error: hold η fixed and shrink r (400 discs at 0.08 nm instead of 100 at 0.17 nm, both at Lx = 10 nm) and the measured excess falls from about 2.4 % (2.3–2.5 % across seeds) to about 0.7 % (0.6–0.9 %) while η barely moves — it scales with the disc size, which is a surface effect, not with the packing fraction. The "Z, hard-disc EOS" readout is the bulk value; expect the measurement to run a little above it, and to converge on it as the discs shrink.
  • N is tiny. A hundred discs is less than 2 × 10⁻²² of a mole. Every measurement therefore carries visible statistical noise — the ± on the pressure is real and does not shrink by wishing. All thermodynamic statements here are statements about averages.
  • Isothermal walls fix the setpoint on average, not instant by instant. A gas held by thermal walls is a canonical ensemble, so its temperature fluctuates about Tset with a relative width of about 1/√N — roughly 7 % at N = 200. Time-averaged over a few nanoseconds it lands on the setpoint to well under a per cent, but a single reading of 320 K at a 300 K setpoint is a fluctuation, not a drift. This is exactly why single-shot measurements on small systems are untrustworthy.
  • The piston is ideal. Massless, frictionless, perfectly rigid, driven at a commanded speed. A real piston has inertia and would ring.
  • Walls are perfectly flat and either perfectly elastic or perfectly thermalising. Real surfaces sit somewhere between, described by an accommodation coefficient.
  • The area fraction is capped at 45 %. Beyond that the discs jam and the simple overlap-resolution scheme stops being trustworthy; hard discs also begin to crystallise near η ≈ 0.7, which is a different problem entirely.

Why an engineer should care

The compressibility factor Z on this page is the same Z that appears in every real-gas calculation an engineer does: sizing a compressed-air receiver, metering natural gas through an orifice plate, or computing the stored energy in an SF6 circuit breaker. Utilities buy and sell gas by standard volume, and the correction from actual to standard conditions is a Z ratio — at typical transmission pressures Z ≈ 0.85, so treating the gas as ideal misprices the delivery by roughly 15 %.

The adiabatic relation is the same one behind compressor discharge temperature. Because compression is nearly adiabatic and never quite reversible, a real machine lands hotter than the isentropic prediction — which is exactly what experiment 4 above shows, in a box of a hundred atoms. Isentropic efficiency is the ratio between those two outcomes, and intercooling exists to drag the process back toward the isotherm in experiment 5. Everything on this page is the microscopic version of a line on a compressor curve.