Science Lab · Chemistry & Physics

Gas in a Box

A box of helium and argon atoms, drawn to scale and slowed down a hundred billion times. Push the piston, heat the walls, pull out the divider, and watch what the atoms do. The gauge and the graphs show why squeezing a gas raises its pressure, why heating it does the same, and why a bike pump gets warm.

Scenes

Piston speed

Live numbers

Temperature
—
Pressure
—
averaged over
—
Volume (area)
—
P·A
—
N·k·T
—
P·A ÷ N·k·T
—
Helium
—
Argon
—
Work by piston
—
Heat from walls
—

Helium and argon: average speed and average kinetic energy of one atom. A 2-D pressure is a force per length of wall, in millinewtons per meter. 1 zJ (zeptojoule) = 10⁻²¹ J. The pressure is averaged from a moment after your last change, so wait a few seconds after each change.

Missions

    Keys, with the box selected: ↑ ↓ move the piston, ← → change the temperature, D the divider, space pauses. Tap an atom to follow it.

    What you're seeing

    The box is a thin slice of gas, drawn to scale. It is 28 nanometers wide (a nanometer is a billionth of a meter). The gold dots are helium atoms, 0.14 nm in radius, and the blue dots are argon atoms, 0.188 nm. Each atom flies in a straight line until it hits a wall or another atom, then bounces off without losing any energy.

    Real atoms are far too fast to watch. A helium atom at room temperature would cross this box in roughly 20 trillionths of a second, so the simulation runs about 100 billion times slower than real life: one second on screen shows 10 picoseconds (at 1×).

    Every flash on a wall is an atom hitting it. The pressure gauge adds up those pushes. The thermometer reads the atoms' average kinetic energy, the histogram sorts the atoms by speed, and the P–V graph traces pressure against volume as you move the piston.

    The box holds a few hundred atoms. A real one-liter bottle of air holds about 2.5 × 1022 molecules: 25 thousand billion billion. With that many, the pressure and temperature hold perfectly steady. With a few hundred, you can see them jitter.

    The science

    Temperature is motion

    The temperature of a gas measures how fast its molecules move. More exactly, it measures their average kinetic energy, the energy of motion. In the real, three-dimensional world:

    average of ½ m v² = 3⁄2 k T    (3-D)      average of ½ m v² = k T    (2-D, this box)

    Here m is a molecule's mass, v its speed, T the temperature in kelvins, and k = 1.380649 × 10−23 J/K is Boltzmann's constant. Each direction a molecule can move in carries ½kT of energy on average. Our flat atoms can move in two directions, so they carry kT; real ones carry 3⁄2kT.

    At 20 °C (293 K), nitrogen molecules in the air have a root-mean-square speed of about 511 m/s, faster than sound. For light helium atoms it is about 1,350 m/s, and for heavy argon atoms about 430 m/s. In our flat box the same temperature gives speeds about 18% lower, because two directions share less energy than three.

    Pressure is collisions

    When an atom bounces off a wall, its speed toward the wall, v⊥, flips around, so the wall gets a push of 2mv⊥. In air, each square centimeter of wall gets about 3 × 1023 of these pushes every second, and together they feel like one steady force. Pressure is that force spread over the wall: per square meter in the real world (pascals, N/m²), and per meter of wall in a flat 2-D world (N/m). Adding up the pushes gives the ideal-gas law:

    P · V = N · k · T    (3-D)      P · A = N · k · T    (2-D, this box)

    N is the number of molecules and V the volume (in 2-D, the area A). The panel shows both sides of the law live, in zeptojoules. For one liter of air at sea-level pressure (101,325 Pa) and 20 °C, it gives N = PV / kT = 101,325 × 0.001 / (1.380649 × 10−23 × 293.15) ≈ 2.5 × 1022 molecules.

    Boyle's law: squeeze it

    Keep the temperature and the number of molecules fixed and halve the volume. The molecules are packed twice as tightly, so twice as many hit each bit of wall every second, and the pressure doubles. Pressure times volume stays the same.

    P1V1 = P2V2

    Gay-Lussac's law: heat it

    Keep the volume fixed and heat the gas. The molecules hit the walls harder and more often, and the pressure rises in proportion to the temperature in kelvins. Going from 300 K to 600 K doubles the pressure. Going from 20 °C to 40 °C does not: that is only 293 K to 313 K, a 7% rise.

    P1 / T1 = P2 / T2

    Fast and slow at the same time: the Maxwell–Boltzmann distribution

    In a gas at one temperature, molecules don't all move at the same speed. Collisions keep trading energy between them, so a few crawl, most move at middling speeds, and a few race at several times the average. The shape of that spread was worked out by James Clerk Maxwell and Ludwig Boltzmann. For a flat 2-D gas it is:

    f(v) = (m v / kT) · e−m v² / 2kT    most likely speed √(kT/m),   root-mean-square speed √(2kT/m)

    In 3-D, it is f(v) = 4π (m/2πkT)3/2 v² e−m v²/2kT, with root-mean-square speed √(3kT/m). The histogram compares the atoms' real speeds with the 2-D curve.

    Heavy molecules move slower

    At the same temperature, every kind of molecule has the same average kinetic energy. An argon atom is about 10 times heavier than a helium atom, so it moves √10 ≈ 3.16 times slower:

    vHe / vAr = √(mAr / mHe) = √(39.948 / 4.0026) = 3.16

    This is also why light gases leak out through tiny holes faster than heavy ones (Graham's law).

    Mixing

    Take out the divider, and each atom wanders off in a zigzag, knocked this way and that. Before long both gases fill the whole box. Nothing pushes them to mix. There are simply far more mixed arrangements than sorted ones, so random motion almost always ends up mixed. That is also why mixed gases never sort themselves out again.

    Why a bike pump gets warm

    When an atom bounces off a piston that is moving toward it, it comes back faster, like a tennis ball off a swinging racket. So pushing a piston in speeds up the atoms: the work you do becomes their kinetic energy, and the gas gets hotter. Pulling the piston out does the opposite, and the gas cools. The energy rule (the first law of thermodynamics) is:

    change in the gas's energy = work done on it + heat flowing into it

    If you pump fast, there is no time for the heat to leak out, so all of the work stays in the gas. For our flat gas of single atoms, squeezing it slowly to half its area doubles its temperature (T · A stays the same). Air in 3-D heats less, but still a lot: squeezed to half its volume with no heat lost, air at 20 °C would reach about 114 °C. In a real pump the air keeps leaking heat to the metal, and friction adds some warmth too, which is why the barrel ends up warm rather than hot. Diesel engines squeeze air so hard and so fast that it gets hot enough to light the fuel without a spark.

    The cooling side matters too. Air that rises in the sky expands as the pressure drops, and it cools by about 9.8 °C for every kilometer it rises (when it is dry). That cooling is how clouds form.

    Try this

    Boyle's law. Pick One gas. Wait a few seconds for the pressure to settle and note it. Drag the piston down to 50% and wait again: the pressure is about twice as high. Try 25%. On the P–V graph, your points follow the dashed curve, a hyperbola.
    The Celsius trap. With the volume fixed, raise the temperature from 300 K to 600 K. The pressure doubles. Then work out what 300 K and 600 K are in degrees Celsius (subtract 273.15) and see why doubling a Celsius temperature never doubles the pressure.
    Order to chaos. Pick Same speed. Every atom starts with the same speed, so the histogram begins as one tall spike. Watch collisions melt it into the Maxwell–Boltzmann curve within a few seconds.
    Heavy and light. Pick Two gases. Compare the average speeds in the panel: helium is about 3 times faster, yet both have the same average energy. Take out the divider. Which gas spreads faster? Put the divider back once they've mixed: they stay mixed.
    Bike pump. Pick Bike pump (insulated walls), set the piston speed to Slow and push it to 50%: the temperature roughly doubles (about 2.1 times in our box). Start again with the piston on Fast: the same squeeze heats the gas about 2.6 times. A fast piston plows into atoms piled up in front of it, so it pushes against a higher pressure and does extra work. Pull the piston back out and watch the gas cool.
    Not so ideal. Pick Crowded and squeeze. Compare P·A with N·k·T: the measured pressure climbs above the ideal-gas law, because the atoms take up room and get in each other's way.
    At home (safe and easy): screw the cap tightly onto an empty plastic bottle and put it in the freezer for an hour. The air inside cools, its molecules slow down and push less, and the air outside dents the bottle. Or, after pumping up a bike tire or a ball, feel the pump's barrel near the bottom: it's warm.

    A common mix-up

    "When a gas gets hot, its molecules get bigger." They don't. A helium atom is the same size at 100 K and at 1,000 K, and so are the atoms in the box. What changes is their speed. Faster atoms hit the walls harder and more often, so the pressure rises. If the walls can give, as a balloon's can, the gas pushes them out and takes up more room. The gas expands, but each molecule stays the same size.

    A related mix-up: "slow molecules are colder." In Two gases, the argon atoms are about three times slower than the helium atoms, but they are at exactly the same temperature, because temperature is about energy, not speed.

    How the simulation works

    The model. Each atom is a hard disk with its real mass (helium 4.0026 u, argon 39.948 u) and its van der Waals radius. Atoms feel no force except when they touch, and every collision is perfectly elastic. Helium and argon are good choices for this: they are single atoms with no parts to spin or wobble.

    The steps. Each frame is cut into sub-steps short enough that no atom moves more than 0.08 nm. A grid of 0.55 nm cells finds the pairs that could touch, and for each one the exact moment of contact is solved for, so atoms bounce at the true distance. The walls are mirrors. The piston bounces atoms in its own moving frame, which is how it does work on the gas. Thermostat walls send each atom that hits them back with a random velocity drawn from the wall's temperature.

    The readings. Pressure is the total momentum the atoms give the four outer walls, divided by the time and the length of wall. Temperature is the total kinetic energy divided by N k. The pressure shown is averaged from a moment after your last change, so it gets steadier the longer you wait.

    What's simplified. The box is flat (2-D), it holds hundreds of atoms instead of 1022, and time is slowed 1011 times. Real atoms also pull on each other slightly when close, which is why real argon turns liquid below 87 K. Ours never attract, so they stay a gas at any temperature.

    How it was checked

    TestResultExpected
    Energy, 240 atoms, insulated walls, 3,000 ps, 95,243 collisionsdrift 3 × 10−140
    Ideal-gas law with tiny atoms (P·A ÷ N·k·T)1.0021
    Same, real-size helium, 100 atoms1.0331.034 (hard-disk theory with wall effect)
    Same, 250 atoms1.0671.069
    Speeds vs. 2-D Maxwell–Boltzmann, after starting at one speedlargest gap 0.7%0
    Equipartition, He started at 600 K, Ar at 100 K: energy ratio1.0021
    Same: average speed of He ÷ Ar3.159√(39.948 / 4.0026) = 3.159
    Thermostat walls at 600 K: gas temperature598.9 K600 K
    Boyle: pressure at half the area ÷ full area (thermostat)2.042.07 (hard-disk theory; 2 for an ideal gas)
    Gay-Lussac: pressure at 600 K ÷ 300 K2.0012
    Very slow (5 m/s) insulated squeeze to half the area: temperature ratio2.0992.093 (2 for an ideal gas)
    Same squeeze with the piston at 100 m/s (Slow) and 800 m/s (Fast)2.111 and 2.570more than 2.093, since a moving piston does extra work
    Same squeeze: work done by piston vs. energy gained685.126 zJ vs. 685.126 zJequal

    Our atoms take up a little room, and in a box only 28 nm wide that shows: the pressure runs a few percent above the ideal-gas law. The measured values match the equation of state for hard disks (Henderson, 1975), corrected for the space the atoms can't reach next to the walls.

    Sources

    @teddyrookbook GitHub