Animation #3

Molecules at a constant temperature

The applet requires Java 1.4.1 or higher to run. It will not run on Windows 95 or Mac OS 8 or 9. Mac users must have OS X 10.2.6 or higher and use a browser that supports Java 1.4 applets (Safari works, IE does not). On other operating systems, you may obtain the latest Java plugin from Sun's Java site.

created with NetLogo

view/download model file: GasLab Gas in a Box.nlogo

This program simulates the behavior of gas molecules.

The Gas-in-a-Box model is one in a collection of GasLab models that use the same basic rules for expressing what happens when gas molecules collide. Each one has different features in order to show different aspects of the behavior of gases.

Molecules have kinetic energy (that which is due to their motion). Collisions between molecules are perfectly elastic. Molecules are colored according to speed -- blue for slow, green for medium, and red for high speeds.

Coloring of the molecules is based on INITSPEED, molecules with a speed less than 50% of INITSPEED are blue, ones that are more than 50% faster are red, while all in between are green.

The exact way two molecules collide is as follows:
1. Two molecules "collide" if they find themselves on the same patch.
2. A random axis is chosen, as if they are two balls that hit each other and this axis is the line connecting their centers.
3. They exchange momentum and energy along that axis, according to the conservation of momentum and energy. This calculation is done in the center of mass system.
4. Each turtle is assigned its new velocity, energy, and heading.
5. If a turtle finds itself on or very close to a wall of the container, it "bounces" -- that is, reflects its direction and keeps its same speed.

Initial settings:
- BOX-SIZE-PERCENT: size of the box. (percentage of the screen size)
- NUMBER: number of gas molecules
- INITSPEED: initial speed of the molecules
- INITMASS: mass of the molecules

The SETUP button will set the initial conditions. The GO button will run the simulation.

Other settings:
- TRACE?: Traces the path of one of the molecules. This path fades over time to make the screen less cluttered.

- FAST, MEDIUM, SLOW: numbers of molecules with different speeds: fast (red), medium (green), and slow (blue).
- AVG-SPEED: average speed of the molecules.
- AVG-ENERGY: average kinetic energy of the molecules.
- CLOCK: number of ticks that have run.

- SPEED COUNTS: plots the number of molecules in each range of speed.
- SPEED HISTOGRAM: speed distribution of all the molecules. The gray line is the average value, and the black line is the initial average.
- ENERGY HISTOGRAM: distribution of energies of all the molecules, calculated as m*v*v/2. The gray line is the average value, and the black line is the initial average.

Initially, all the molecules have the same speed but random directions. Therefore the first histogram plots of speed and energy should show only one column each. As the molecules repeatedly collide, they exchange energy and head off in new directions, and the speeds are dispersed -- some molecules get faster, some get slower.

What is happening to the numbers of molecules of different colors? Does this match what's happening in the histograms? Why are there more blue molecules than red ones?

Can you observe collisions and color changes as they happen? For instance, when a red molecule hits a green molecule, what color do they each become?

Why does the average speed (avg-speed) drop? Does this violate conservation of energy?

The molecule histograms quickly converge on the classic Maxwell-Boltzmann distribution. What's special about these curves? Why is the shape of the energy curve not the same as the speed curve?

Watch the molecule whose path is traced in gray. Does the trace resemble Brownian motion? Can you recognize when a collision happens? What factors affect the frequency of collisions? What about the "angularity" of the path? Can you get it to stay "local" or travel all over the screen?

In what ways is this model an incorrect idealization of the real world?

Set all the molecules in part of the screen, or with the same heading -- what happens? Does this correspond to a physical possibility?

Try different settings, especially the extremes. Are the histograms different? Does the trace pattern change?

Are there other interesting quantities to keep track of?

Look up or calculate the REAL number, size, mass and speed of molecules in a typical gas. When you compare those numbers to the ones in the model, are you surprised this model works as well as it does? What physical phenomena might be observed if there really were a small number of big molecules in the space around us?

We often say outer space is a vacuum. Is that really true? How many molecules would there be in a space the size of this computer?

Could you find a way to measure or express the "temperature" of this imaginary gas? Try to construct a thermometer.

What happens if there are molecules of different masses? (See GasLab Two Gas model.)

What happens if the collisions are non-elastic?

How does this 2-D model differ from a 3-D model?

Set up only two molecules to collide head-on. This may help to show how the collision rule works. Remember that the axis of collision is being randomly chosen each time.

What if some of the molecules had a "drift" tendency -- a force pulling them in one direction? Could you develop a model of a centrifuge, or charged molecules in an electric field?

Find a way to monitor how often molecules collide, and how far they go between collisions, on the average. The latter is called the "mean free path". What factors affect its value?

In what ways is this idealization different from the idealization that is used to derive the Maxwell-Boltzmann distribution? Specifically, what other code could be used to represent the two-body collisions of molecules?

If MORE than two molecules arrive on the same patch, the current code says they don't collide. Is this a mistake? How does it affect the results?

Is this model valid for fluids in any aspect? How could it be made to be fluid-like?

Notice the use of the histogram primitive.

Notice how collisions are detected by the molecules and how the code guarantees that the same two molecules do not collide twice. What happens if we let the patches detect them?

This was one of the original Connection Machine StarLogo applications (under the name GPCEE) and is now ported to NetLogo as part of the Participatory Simulations project.

To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo GasLab Gas in a Box model. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See for terms of use.