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 procedure setup the model. Builds the box, initial number of particles and defines the particles ;; as cirlces. It also address the inital speed of the particles, energy and pressure of the system. to setup ca set initspeed 10.0 set initmass 1.0 set box-edge (screen-edge-x - 1) 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 end ;; updates particle speed, energy and system pressure 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 ;; runs the model to go ask turtles [ bounce ] ask turtles [ move ] set vclock (vclock + 1) if (vclock = vsplit) [ set clock (clock + 1) set vclock 0 update-variables ask turtles [ set pressure 0 ] ] end ;; turtle procedure to bounce off the wall instead of moving through the wall. 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-at dx dy yellow [ stop ] ; get the coordinates of the patch we'll be on if we go forward 1 set new-px round (xcor + dx) set new-py round (ycor + dy) ; 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 ;;turtle procedure on getting turtles to move. to move jump ( speed / vsplit ) check-for-collision end ;;turtle procedure to see if in a position to collide with another turtle. 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 ;; turtle procedure to calculate collision. 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 ;; turtle procedure to calculate new speed and headings ;; 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 ;; patch procedure to make 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 ;; turtle procedure to make sure initial turtles are placed inside the box. to random-position setxy ((1 - box-edge) + random ((2 * box-edge) - 2)) ((1 - box-edge) + random ((2 * box-edge) - 2)) 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 2003. 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 Chem Pressure 1 model. ; http://ccl.northwestern.edu/netlogo/models/ChemPressure1. ; 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/ChemPressure1 ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 262 10 556 325 35 35 4.0 1 10 1 1 1 CC-WINDOW 17 209 242 384 Command Center BUTTON 127 42 242 92 go go T 1 T OBSERVER T BUTTON 11 42 116 91 NIL setup NIL 1 T OBSERVER T SLIDER 12 101 243 134 initial-particles initial-particles 0 500 100 10 1 NIL MONITOR 14 144 243 193 particles count turtles 0 1 @#$#@#$#@ Connected Chemistry Curriculum is currently under development, for more information please refer to http://ccl.northwestern.edu/curriculum/chemistry/ WHAT IS IT? ----------- This model simulates the behavior of gas particles that are trapped in a fixed container. The model is specifically looking at how a number of particles affect the pressure of this system. The independent variables within this model are the number of initial particles and the amount of particles added while the simulation is running. Adding a spurt of particles into the container increases the number of particles that are moving and colliding with each other and the walls. This model is part of the Connected Chemistry High School Curriculum and is the first model in a series that explore the concept of pressure. In this model, students look at the relationship between number of particles and pressure. The other Chem Pressure models use the same model but look at different aspects and variables within the same system. This model has been adapted from GasLab Pressure Box, which can be found in the Unverified section of the GasLab folder found under Chemistry and Physics. These pressure models are part of a suite of models that students use to gain deeper insight on Gas Laws and particle behavior. Other models in this suite include the Chem Volume models and Chem Heat Box models. In all of the Connected Chemistry Curriculum models, the same basic rules are used for expressing what happens when gas particles collide. Each model has different features in order to show different aspects of the behavior of gases. HOW IT WORKS ------------ Particles are modeled as perfectly elastic particles with no energy except their kinetic energy -- 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" when 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 - sets up the initial conditions set on the slider. Be sure to wait till the Setup button stops before pushing GO. GO - runs the code again and again. Sliders: INITIAL-PARTICLES - sets the number of gas particles in the box when the simulation starts. Monitors: PARTICLES - 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 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 ---------------- Can you observe collisions with the walls as they happen? For example, do the particles change color? Direction? THINGS TO TRY ------------- Try different settings, especially the extremes. Are the particles behaving in a similar way? EXTENDING THE MODEL ------------------- Add a monitor to record the pressure at every time tick. Add a button and slider that allows for the user to add more particles into the box at any given time, while the model is running. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (2002). NetLogo Chem Pressure 1 model. http://ccl.northwestern.edu/netlogo/models/ChemPressure1. 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/ChemPressure1 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 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@