SELLC Physics Lab

Ideal gas particle box

All simulations

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.

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²⟩ this instant, 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
  • Isotherm P = NkBT/A
  • Ideal adiabat PA² = const
  • Hard-disc adiabat (exact)
All three ghosts are re-anchored to the state at which the piston last started moving. With the thermostat off and adiabatic walls, a slow compression rides the purple hard-disc adiabat; with isothermal walls it rides the blue isotherm. The green curve is the textbook ideal γ = 2 adiabat — the gap between green and purple 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⟩ = kBTT = mv²⟩ / (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|vxvwall|, 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/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.
  • λ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′ = 2vwallvx

  • 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 a few per cent 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 — around 880 K instead of 750 K — and the trace overshoots even the hard-disc adiabat. 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 now follows the blue isotherm. The compression work leaves through the walls as heat instead of accumulating as internal energy.
  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 suffers: λ tracks the Enskog value to well under 1 %. Above roughly 30 % packing both measurements start to drift — λ by 3–5 % at the 45 % cap, 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 of order 2r(Lx + Ly)/A on top of the bulk hard-disc EOS. With the default discs that is about 2 % at Lx = 16 nm and 7 % at the 3 nm stop. 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) and the excess falls from 1.3 % to 0.6 % 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 about 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.