Simulation of a gas - release from a container

Micro controllers
Vector graphics

My java applets were developed a long time ago and have not been digitally signed. Nowadays a browser will typically not allow a java applet to run unless it is signed. Getting the applets signed is somewhat expensive, and since I no longer do any java development it is unlikely that I will get the applets signed. It it still possible to run the applets, but in that case you will need to change the security policy of your browser to allow unsigned applets to run.

Below is a java simulation of a gas, where the gas molecules are treated as hard spheres. Initially all molecules are inside a container, which can be opened. Once the container has been opened the gas molecules will escape, and one would not expect them all to get back into the container again. This is an example of an irreversible process, i.e. a process where there is a difference between forward and backward in time (the arrow of time).

The equations that govern individual collisions are unaffected by the direction time flows in. Microscopically reversion of time is equivalent to reversal of all velocities. Macroscopically, however, the situation is different, and this is due to the Second Law of Thermodynamics. The Second Law states that the entropy of an isolated system must either stay the same or increase with time. Entropy can never decrease with time. Entropy can be thought of as a measure of the disorder. The simulation starts in a state with low entropy (all molecules are inside the container) and moves to a state with higher entropy (most of the molecules are outside the container). From this higher entropy state the system can not get back to the lower entropy state, because that would decrease the entropy.

Entropy can also be viewed in a probabilistic fashion. States that are more likely have high entropy, and states that are less likely have low entropy. Imagine that out of all the states available you pick one at random. Then it is more likely that the random state you picked is a high entropy state, than a low entropy Take the gas and the container below as an example. The container occupies approximately one ninth of the available area. If the container has been open for a while, a molecule is not more likely to occupy a particular place than any other. The probability for a particular molecule to be inside the container is therefore 1/9. The probability that all 80 molecules are inside the container is (1/9)^80 = 4.58x10E-77, which is very unlikely indeed.

The simulation controls are hopefully self-explanatory.

This simulation is time reversible, but only for short periods of time (approximately 1 time unit in the simulation). Eventually the finite precision of the simulation will cause a collision to be missed/added when time is reversed. Initially this only affects two of the molecules, but when the two first affected molecules collide again the effect has spread to their two collision partners. In this way the effect spreads at an exponential rate through the gas, and will eventually have affected all of the molecules.

There is also a variant of this simulation, where the irreversible process simulated is instead mixing of two gases.