globals [ avg-speed avg-energy ;; current averages avg-speed-init avg-energy-init ;; initial averages clock vsplit vclock ;; clock variables box-edge ;; patch coords of box's edge initspeed initmass ;; initial particle settings total-pressure switch-now? pressure-history ] 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 pressure ;; collision info (both turtles) ] ;; this setup of the model which makes the box and number of the inital particles. to setup ca set initspeed 10.0 set initmass 1.0 set box-edge (round (screen-edge-x * box-size / 100)) make-box cct initial-particles [ set new-speed initspeed set mass initmass random-position rt random-float 360 set shape "circle" set pressure 0 recolor ] set clock 0 set vclock 0 set pressure-history [] update-variables set avg-speed-init avg-speed set avg-energy-init avg-energy setup-plots do-plotting end ;; updates each variable (speed of particles, energy and pressure) ;; after each time tick to update-variables ask turtles [ set speed new-speed set energy (0.5 * speed * speed * mass) ] ifelse any? turtles [ set avg-speed mean values-from turtles [speed ] set avg-energy mean values-from turtles [energy] set total-pressure sum values-from turtles [pressure] calculate-pressure set vsplit (round ((max values-from turtles [speed]) * 1.2)) ] [ set vsplit initspeed ] end ;; pressure of the system is calculated by the total number of particle ;; collisions with all the walls. to calculate-pressure ifelse length pressure-history < scale [ set pressure-history fput total-pressure pressure-history ] [ set pressure-history fput total-pressure (but-last pressure-history) ] end ;; releases particles into the box and makes sure all particles stay within ;; the box. to release-particles [n] while [n > 0] [ ifelse not any? turtles-at (1 - box-edge) 0 [ cct 1 [ set new-speed initspeed set mass initmass set xcor (- box-edge) rt 45 + random-float 90 set shape "circle" set pressure 0 recolor ] set n n - 1 ] [ set switch-now? true ] ] end ;; makes the model run to go ask turtles [ bounce ] ask turtles [ move ] set vclock (vclock + 1) if (vclock = vsplit) [ set clock (clock + 1) set vclock 0 update-variables do-plotting ask turtles [ set pressure 0 ] ] end ;;turtle procedure that bounced the particles off the wall when they hit. to bounce locals [ new-px new-py ] ; if we're not about to hit a wall (yellow patch), ; we don't need to do any further checks if not shade-of? pcolor-of patch-ahead 1 yellow [ stop ] ; get the coordinates of the patch we'll be on if we go forward 1 set new-px pxcor-of patch-ahead 1 set new-py pycor-of patch-ahead 1 ; check: hitting left or right wall? if (abs new-px = box-edge) ; if so, reflect heading around x axis [ set heading (- heading) set pressure pressure + abs (sin heading * mass * speed) ] ; check: hitting top or bottom wall? if (abs new-py = box-edge) ; if so, reflect heading around y axis [ set heading (180 - heading) set pressure pressure + abs (cos heading * mass * speed) ] end ;; moves turtles around the box to move jump ( speed / vsplit ) check-for-collision end ;; check to see if turtles will collide with each other to check-for-collision if count other-turtles-here = 1 [ set tmp-turtle random-one-of other-turtles-here if ((who > who-of tmp-turtle) and (turtle2 != tmp-turtle)) [ collide ] ] end ;; if turtles collide then they transfer energy and change direction to collide get-turtle2-info calculate-velocity-components set-new-speed-and-headings end to get-turtle2-info 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 locals [ vcm ] ;; CM vel. along dir. theta 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)) set vcm (((mass * v1t) + (mass2 * v2t)) / (mass + mass2) ) set v1t (vcm + vcm - v1t) set v2t (vcm + vcm - v2t) end ;; set new speed and direction for the turtles after a collision to set-new-speed-and-headings set new-speed sqrt ((v1t * v1t) + (v1l * v1l)) set heading (theta - (atan v1l v1t)) set new-speed-of turtle2 sqrt ((v2t * v2t) + (v2l * v2l)) set heading-of turtle2 (theta - (atan v2l v2t)) recolor ask turtle2 [ recolor ] end to recolor ifelse new-speed < (0.5 * initspeed) [ set color blue ] [ ifelse new-speed > (1.5 * initspeed) [ set color red ] [ set color green ] ] end ;; patches procedure in making the box to make-box ask patches with [ ((abs pxcor = box-edge) and (abs pycor <= box-edge)) or ((abs pycor = box-edge) and (abs pxcor <= box-edge)) ] [ set pcolor yellow ] ask patches with [ pycor = 0 and pxcor < (1 - box-edge) ] [ set pcolor yellow - 5 ;; trick the bounce code so particles don't go into the inlet. set pcolor-of patch-at 0 1 yellow set pcolor-of patch-at 0 -1 yellow ] end ;; makes sure all turtles added take a random position within the box to random-position setxy ((1 - box-edge) + random-float ((2 * box-edge) - 2)) ((1 - box-edge) + random-float ((2 * box-edge) - 2)) end ;;; plotting procedures to setup-plots set-current-plot "Particle Count vs. Time" set-plot-y-range 0 number end to do-plotting set-current-plot "Particle Count vs. Time" plot count turtles set-current-plot "Pressure vs. Time" plot mean pressure-history end ; ***NetLogo Model Copyright Notice*** ; ; This activity and associated models and materials were created as part of the project: ; MODELING ACROSS THE CURRICULUM. The project gratefully acknowledges the support of the ; National Science Foundation, National Institute of Health and the Department of Education ; (IERI program) -- grant number REC # 0115699. Additional support was provided through the ; project: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS ; -- NSF (REPP program) -- grant number REC #9814682. ; ; Copyright 2002 by Uri Wilensky. Updated 2002. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (2002). NetLogo GasLab Pressure Box model. ; http://ccl.northwestern.edu/netlogo/models/GasLabPressureBox. ; 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 ; http://ccl.northwestern.edu/netlogo/models/GasLabPressureBox ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 262 10 556 325 35 35 4.0 0 10 1 1 1 CC-WINDOW 329 394 535 561 Command Center MONITOR 262 336 320 385 clock clock 0 1 MONITOR 329 336 413 385 avg-speed avg-speed 2 1 BUTTON 9 85 97 118 go go T 1 T OBSERVER NIL BUTTON 9 42 97 75 NIL setup NIL 1 T OBSERVER T PLOT 7 405 252 582 Particle Count vs. Time time count 0.0 20.0 0.0 200.0 true false SLIDER 106 42 253 75 box-size box-size 5.0 100.0 90.0 1.0 1 NIL MONITOR 422 336 505 385 avg-energy avg-energy 3 1 SLIDER 137 128 253 161 number number 0 200 100 1 1 NIL BUTTON 9 128 128 161 release-particles release-particles number NIL 1 T OBSERVER T SLIDER 106 85 253 118 initial-particles initial-particles 0 500 100 10 1 NIL MONITOR 257 394 326 443 particles count turtles 0 1 PLOT 8 171 253 347 Pressure vs. Time time pressure 0.0 20.0 0.0 100.0 true false MONITOR 8 352 105 401 NIL total-pressure 3 1 SLIDER 109 357 253 390 scale scale 0 10 5 1 1 clock cycles @#$#@#$#@ WHAT IS IT? ----------- This model simulates the behavior of gas particles trapped in a fixed volume container. All of the particles have the same mass and speed at the start of the simulation. As the simulation continues, the particles move around the container colliding with other particles and the walls of the container. The speed of the particles changes but the mass of the particles will always stay the same. Particles are modeled as perfectly elastic particles with no energy except kinetic energy. In an elastic collision, the total amount of kinetic energy is the same before and after the collision between the particles. When two particles collide they transfer energy between each other and recalculate their direction and speed. Even though the turtles have transferred kinetic energy, the collision is still elastic. The total amount of kinetic energy has not changed prior to the collision, instead it has been redistributed. For example, if one particle is a fast moving particle and the other is a slow moving particle. After the collision, the fast moving particle will move slower and the slow moving particle will move faster. This can be seen in the change of color of each of the particles. Particles are colored according to their speed; blue for slow, green for medium, and red for fast speeds. Particle collisions with the wall are also elastic but tend to result in no change since the wall has no kinetic energy and therefore, the particle speed will stay the same but the direction of the particle after the collision will change. The sum of the particle collisions with the walls at each time tick is how pressure is calculated in this model. The Basic Pressure model is one in a collection of GasLab models that uses the same basic rules for expressing what happens when gas particles collide. Each model has different features to show the different aspects of the Gas Laws. Multiple adaptations of this model can be found in the Chemistry folder of the Curricular Models section under the names Chem Pressure 1, 2, and 3. They are all part of a suite of models used to teach students about the Gas Laws from a chemistry prospective. HOW IT WORKS ------------- 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. HOW TO USE IT ------------- Buttons: SETUP - puts in the initial conditions you have set with the sliders. Be sure to wait till the SETUP button stops before pushing GO. GO - runs the code again and again. This is a "forever" button. RELEASE-PARTICLES - releases particles into the box when pressed while the simulation is running Sliders: BOX-SIZE - The size of the box as a percentage of the screen size INITIAL-PARTICLES - the number of gas particles in the box when the simulation starts NUMBER - the number of gas particles released into the box SCALE - determines the number of clock ticks over which the different measurements are taken Monitors: CLOCK - number of clock cycles that GO has run. AVG-SPEED - average speed of the particles. AVG-ENERGY - average kinetic energy of the particles. PARTICLES - the number of particles in the box TOTAL-PRESSURE - the pressure of the gas particles in the box Plots: PRESSURE - plots the pressure in the box PARTICLE COUNT - plots the number of particles in the box Initially, the particles are not moving. Therefore the initial pressure is zero. As the particles start moving, they all first have the same speed in random directions. As the particles repeatedly collide, they exchange energy and head off in new directions, and the speeds are dispersed -- some particles get faster, some get slower. THINGS TO NOTICE ---------------- What is happening to the particles in the box as a new spurt of particles comes in? Can you observe collisions with the walls as they happen? For example, do they change color? Direction? Can you relate what you can see happening to the particles in the box with changes in pressure? The average speed? The average energy? Why does the pressure change over time, even when the number of particles is the same? How long does it take for the pressure to stabilize? In what ways is this model an incorrect idealization of the real world? THINGS TO TRY ------------- Try different settings, especially the extremes. Are the particles behaving in a similar way? How does this effect the pressure? The energy? Can you make the pressure graph smooth? Can you do it in more than one way? Are there other interesting quantities to keep track of? The ideal gas equation shows us that when keeping a constant temperature and volume, increasing the number of particles increases the pressure as well. Keeping a constant temperature means that the average kinetic energy of the particles, does not change, nor does their average speed. How is this related to the behavior of particles that you have seen so far? Are there any other observations that could be made to test this relationship between the number of particles and the pressure? Sometimes, when going up in an elevator, airplane or up a mountain we feel a 'popping' sensation in our ears. This is associated with changes in pressure. Can you relate between this model and these changes in pressure? Are the temperature and volume constant in this situation? EXTENDING THE MODEL ------------------- Add a histogram showing the energy of the particles at any given time. Add a switch that allows for particles to continuously be added to the box. What would happen if the box was heated? How would the particles behave? How would this affect the pressure? Add a slider and code that increases the temperature inside the box. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (2002). NetLogo GasLab Pressure Box model. http://ccl.northwestern.edu/netlogo/models/GasLabPressureBox. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 2002 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/GasLabPressureBox for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 circle false 0 Circle -7566196 true true 35 35 230 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@