# GasLab Second Law

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## WHAT IS IT?

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.

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.

## HOW IT WORKS

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:

- Two turtles "collide" if they find themselves on the same patch.
- A random axis is chosen, as if they are two balls that hit each other and this axis is the line connecting their centers.
- 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.
- Each turtle is assigned its new velocity, energy, and heading.
- 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.

## HOW TO USE IT

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.

## THINGS TO NOTICE

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?

## THINGS TO TRY

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?

## EXTENDING THE MODEL

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?

## RELATED MODELS

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

## CREDITS AND REFERENCES

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

This model was developed as part of the GasLab curriculum (http://ccl.northwestern.edu/curriculum/gaslab/) and has also been incorporated into the Connected Chemistry curriculum (http://ccl.northwestern.edu/curriculum/ConnectedChemistry/)

## HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

- Wilensky, U. (2002). NetLogo GasLab Second Law model. http://ccl.northwestern.edu/netlogo/models/GasLabSecondLaw. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

## COPYRIGHT AND LICENSE

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 http://creativecommons.org/licenses/by-nc-sa/3.0/ 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 uri@northwestern.edu.

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.

## Comments and Questions

globals [ fast average slow ;; current counts avg-speed avg-energy ;; current averages avg-speed-init avg-energy-init ;; initial averages vsplit vclock ;; clock variables left-count right-count ;; # of particles on each side propeller-velocity ;; current velocity of the propeller left-pressure right-pressure ;; pressure in each chamber left-walls right-walls ;; agentsets of the walls on each side (used when calculating pressure) propeller-angle ;; current angular position of the propeller ] turtles-own [ speed mass energy new-speed ;; turtle info v1t v1l tmp-turtle ;; collision info (turtle 1) heading2 mass2 speed2 v2t v2l turtle2 ;; collision info (turtle 2) theta ;; collision info (both particles) ] patches-own [ wall? ;; is this patch part of the wall? pressure ;; sum of momentums of particles that have bounced here during this time slice ] to setup [mode] clear-all make-box set vclock 0 crt number [ set new-speed 10.0 set shape "circle" set mass 1.0 setup-position mode recolor ] update-variables set avg-speed-init avg-speed set avg-energy-init avg-energy rotate-propeller reset-ticks end to setup-position [mode] ;; turtle procedure if mode = "corner" [ setxy (- (max-pxcor - 1)) (- (max-pycor - 1)) set heading random-float 90 fd random-float 8 ] if mode = "one side" [ setxy (- (1 + random-float (max-pxcor - 2))) (random-float (world-height - 3) + min-pycor + 1) ] if mode = "both sides" [ setxy (random-float (world-width - 3) + min-pxcor + 1) (random-float (world-height - 3) + min-pycor + 1) ] end to update-variables ask turtles [ set speed new-speed set energy (0.5 * speed * speed * mass) ] set average count turtles with [color = green] set slow count turtles with [color = blue] set fast count turtles with [color = red] set avg-speed mean [speed] of turtles set avg-energy mean [energy] of turtles set vsplit (round ((max [speed] of turtles) * 1.2)) set left-count count turtles with [xcor < 0] set right-count count turtles with [xcor >= 0] set left-pressure sum [pressure] of left-walls ask left-walls [ set pressure 0 ] set right-pressure sum [pressure] of right-walls ask right-walls [ set pressure 0 ] end to go ask turtles [ bounce ] ask turtles [ move ] ask turtles [ check-for-collision ] set vclock (vclock + 1) rotate-propeller ifelse (vclock = vsplit) [ tick set vclock 0 update-variables ] [ display ] end to rotate-propeller set-current-plot "Propeller" plot-pen-reset set propeller-angle propeller-angle - propeller-velocity / 2 plot-pen-up plotxy cos propeller-angle sin propeller-angle plot-pen-down plotxy 0 - cos propeller-angle 0 - sin propeller-angle plot-pen-up plotxy cos (propeller-angle + 90) sin (propeller-angle + 90) plot-pen-down plotxy 0 - cos (propeller-angle + 90) 0 - sin (propeller-angle + 90) ;; slow down the propeller due to friction set propeller-velocity propeller-velocity * 0.999 end to bounce ;; turtle procedure ; if we're not about to hit a wall (yellow patch), ; we don't need to do any further checks if [pcolor] of patch-ahead 1 != yellow [ stop ] ; get the coordinates of the patch we'll be on if we go forward 1 let new-px [pxcor] of patch-ahead 1 let new-py [pycor] of patch-ahead 1 let pressure-increment mass * speed ask patch new-px new-py [ set pressure pressure + pressure-increment ] ; check: hitting left, right, or middle wall? if (abs new-px = max-pxcor) or (pxcor != 0 and new-px = 0) ; if so, reflect heading around x axis [ set heading (- heading) ] ; check: hitting top or bottom wall? if (abs new-py = max-pycor) or (pxcor = 0) ; if so, reflect heading around y axis [ set heading (180 - heading) ] end to move ;; turtle procedure let old-xcor xcor jump (speed / vsplit) if (old-xcor < 0) and (xcor >= 0) [ set propeller-velocity propeller-velocity + 0.03 * speed ] if (old-xcor > 0) and (xcor <= 0) [ set propeller-velocity propeller-velocity - 0.03 * speed ] end to check-for-collision ;; turtle procedure if count other turtles-here = 1 [ set tmp-turtle one-of other turtles-here if ((who > [who] of tmp-turtle) and (turtle2 != tmp-turtle)) [ collide ] ] end to collide ;; turtle procedure get-turtle2-info calculate-velocity-components set-new-speed-and-headings end to get-turtle2-info ;; turtle procedure set turtle2 tmp-turtle set mass2 [mass] of turtle2 set speed2 [new-speed] of turtle2 set heading2 [heading] of turtle2 end to calculate-velocity-components ;; turtle procedure set theta (random-float 360) set v1l (new-speed * sin (theta - heading)) set v1t (new-speed * cos (theta - heading)) set v2l (speed2 * sin (theta - heading2)) set v2t (speed2 * cos (theta - heading2)) ;; CM vel. along dir. theta let vcm (((mass * v1t) + (mass2 * v2t)) / (mass + mass2)) set v1t (vcm + vcm - v1t) set v2t (vcm + vcm - v2t) end ;; set new speed and headings of each turtles that has had a collision to set-new-speed-and-headings set new-speed sqrt ((v1t * v1t) + (v1l * v1l)) set heading (theta - (atan v1l v1t)) let new-speed2 sqrt ((v2t * v2t) + (v2l * v2l)) let new-heading (theta - (atan v2l v2t)) ask turtle2 [ set new-speed new-speed2 set heading new-heading ] recolor ask turtle2 [ recolor ] end to recolor ;; turtle procedure ifelse new-speed < 5.0 [ set color blue ] [ ifelse new-speed > 15.0 [ set color red ] [ set color green ] ] end to make-box ask patches [ set pressure 0 set wall? false if count neighbors != 8 or ((pxcor = 0) and (abs pycor > propeller-radius)) [ set pcolor yellow set wall? true ] if (pxcor = 0) and (abs pycor <= propeller-radius) [ set pcolor gray ] ] set left-walls patches with [wall? and (pxcor < 0)] set right-walls patches with [wall? and (pxcor > 0)] end to-report calculate-order let x-patches-per-grid-cell (world-width / 5) let y-patches-per-grid-cell (world-height / 5) let counts-list [] let gridx -2 repeat 5 [ let gridy -2 repeat 5 [ let gridcount count turtles with [int (pxcor / x-patches-per-grid-cell) = gridx and int (pycor / y-patches-per-grid-cell) = gridy] set counts-list lput gridcount counts-list set gridy gridy + 1 ] set gridx gridx + 1 ] ;; show counts-list report variance counts-list end ; Copyright 2002 Uri Wilensky. ; See Info tab for full copyright and license.

There are 15 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

GasLab Second Law.png | preview | Preview for 'GasLab Second Law' | about 11 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.