Physics (and math) of the hard-sphere-gas simulation

1. About size and density

By default my "molecules" have a radius of 1 pixel and are confined to a box 200 pixels wide (clicking on "Make particles bigger" gives them a two-pixel radius). To compare to a real-world gas, one would have to say that 1 pixel is roughly 1 angstrom and that the box is therefore about m on the side. Using PV = NkT (where k is Boltzmann's constant and N is the number of molecules) you can check that at normal temperature and pressure (1 atm, 300 K) a (cubical) box of that size should contain about 200 molecules.

Of course, 200 molecules in a two-dimensional box m on the side are going to collide a lot more often than the same 200 molecules in a three-dimensional box m on the side. From this point of view, the mean free path l is the quantity that should be taken as a reference. For a gas of hard disks in 3 dimensions, l is of the order of , where d is the molecules' diameter. In two dimensions, I get

which means that in order to see comparable mean free paths, the number of particles in the two-dimensional box should be smaller than in the three-dimensional box by (roughly) the ratio of d to L (L is the lenght of the box's side), or about 1/100 in our case. So to simulate a gas at normal temperature and pressure you should have very few particles in the box, say 4 or so.

2. About speed and the units of time.

All the molecules are given the same initial speed, , in different directions. For air at normal temperature and pressure, the rms speed is of the order of 500 m/s (483 for oxigen, 517 for nitrogen). In the animation, time is measured in units of , where L is the size of the box. If we assume that L = m , and use the above value for , we find one unit of time for the simulation would be about 4 picoseconds! So we're watching things in extreme slow motion.

Since it takes 10 units of time to cover the distance L, the speed is L/10 = 20 pixels/time unit. Using this with the formula in the previous section for the mean free path yields an average time between collisions, , of the order of

time units (with the particle's diameter, d, in pixels). For comparison, Reif (Fundamentals of Statistical and Thermal Physics, McGraw-Hill, 1965; section 12.2) gives a mean collision time for air molecules at normal temperature and pressure of about 600 picoseconds.

To check the equation above from the computer simulation, one should keep in mind that, if is the total number of collisions after a time t, this means that each molecule has collided, on the average, about 2/N times (the factor of 2 is because each collision involves two molecules!). Thus, the average collision time per molecule should be obtained from the simulation as

If you run the simulation a few times and compare this to the above (theoretical) equation for , you should get a pretty decent match to within a proportionality factor of the order of unity. I haven't been able to calculate the proportionality factor exactly from the theory, though. Can anybody out there help me?

3. The speed distribution.

The Maxwellian distribution of velocities for a two-dimensional ideal gas would be


The term in the exponent is just the kinetic energy divided by kT. This distribution is normalized so that the integral over the two velocity components yields N, the total number of molecules in the box. To go from this to a distribution of speeds, write in polar coordinates, as , and integrate over the angles, to get

The average kinetic energy per molecule obtained from this distribution is

which is consistent with the equipartition theorem (an average energy of kT/2 per degree of freedom--we have two degrees of freedom in this two-dimensional example). Note that the total kinetic energy of our gas is always the same and equal to , so we can say that the temperature of our gas is , in terms of the molecules' initial speed. This differs by a factor 3/2 from the familiar 3-dimensional result (which was used above to estimate the rms speed of air molecules at room temperature).

The fraction of molecules with speeds between v and is easily obtained by integrating the distribution of speeds F(v). The result is

This is what I have plotted in the program (the blue line in the "distribution of speeds" box). The width of each "bin" is about 0.244 . (I chose that strange fraction, instead of just one-fourth of , to avoid having the initial speed fall at precisely the edge of the fourth bin.) There are ten bins, so the curve goes from v = 0 to v = 2.44 .

I'm not done yet! I have some remarks on chaos and irreversibility coming up. (Maybe I should put them on a separate page. This one is getting long!)

If you had the patience to read through all this, and have any comments or suggestions, please send them to me at