NetLogo banner

 Contact Us

 Modeling Commons

 User Manuals:


NetLogo Models Library:
Sample Models/Chemistry & Physics/GasLab/Unverified

Note: This model is unverified. It has not yet been tested and polished as thoroughly as our other models.

(back to the library)

GasLab Second Law

[screen shot]

If you download the NetLogo application, this model is included. (You can also run this model in your browser, but we don't recommend it; details here.)


This model simulates the Second Law of Thermodynamics via the behavior of gas particles in a box. The Second Law of Thermodynamics states that systems tend towards increased entropy. Essentially what this means is that over time ordered systems become less ordered unless work is done on the system to keep it ordered.

This model is one in a series of GasLab models. They use the same basic rules for simulating the behavior of gases. Each model integrates different features in order to highlight different aspects of gas behavior.

The basic principle of the models is that gas particles are assumed to have two elementary actions: they move and they collide --- either with other particles or with any other objects such as walls.


Particles are modeled as perfectly elastic particles with no energy except their kinetic energy --- that which is due to their motion. Collisions between particles are elastic. Particles are colored according to speed -- blue for slow, green for medium, and red for high speeds.

The exact way two particles collide is as follows: 1. Two turtles "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.

The propeller is modeled such that it shows the effect of the flux of the particles between the two sides of the box, but does not effect or interact with the particles as they pass through. When particles move from the left side to the right side they accelerate the propeller clockwise, and likewise, when particles move from the right side to the left side they accelerate the propeller counter-clockwise.


SETUP: sets up the initial conditions and distributes the particles in one of three different modes. Be sure to wait till the Setup button stops before pushing go. CORNER: all the particles are created in the lower left corner of the box and diffuse outwards from there. ONE SIDE: all the particles are created in the left side of the box evenly distributed. BOTH SIDES: all the particles are created evenly distributed throughout the entire box. GO: runs the code again and again. This is a "forever" button. NUMBER: the number of gas particles PROPELLER-RADIUS: the radius of the propeller in the opening between the sides of the box. The size of the opening is based on the size of the propeller.

About the plots

PARTICLE COUNTS: plots the number of particles on each side of the box. PROPELLER VELOCITY: plots the velocity of the propeller: positive is clockwise, negative is counter-clockwise. PRESSURES: plots the pressure of the gas on each side of the box. ENTROPY: plots a measure of the entropy of the system. As the particles become more evenly and randomly distributed the entropy will increase.


When the particles are evenly distributed throughout the box, what do you notice about the behavior of the propeller?

In what ways is this model a correct or incorrect idealization of the real world?

In what ways can you quantify entropy? What is the best way to quantify entropy in this model? Does this model use this method? If not, what is wrong with the method being used?


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

Are there other interesting quantities to keep track of?


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 particles of different masses? (See GasLab Two Gas model.)

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

If more than two particles 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?


The GasLab suite of models, especially GasLab Maxwell's Demon, which models a theoretical system that seems to violate the Second Law of Thermodynamics.


Thanks to Brent Collins and Seth Tisue for their work on this model.

This model was developed as part of the GasLab curriculum ( and has also been incorporated into the Connected Chemistry curriculum (


If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:


Copyright 2002 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

(back to the NetLogo Models Library)