globals [ avg-speed avg-energy ;; current averages clock vsplit vclock ;; clock variables x-center y-center ;; coordinates of the center of mass done? ] 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 turtles) ] to setup ca set clock 0 set vclock 0 set done? false cct 1 [ set color green set new-speed initspeed-green set mass initmass-green set heading 180 bk new-speed ] cct 1 [ set color blue set new-speed initspeed-blue set mass initmass-blue set heading 180 + collision-angle bk new-speed ] update-variables do-plotting end to update-variables ask turtles [ set speed new-speed set energy (0.5 * speed * speed * mass) ] set x-center mean values-from turtles [ xcor ] set y-center mean values-from turtles [ ycor ] set avg-speed mean values-from turtles [ speed ] set avg-energy mean values-from turtles [ energy ] set vsplit (round ((max values-from turtles [speed]) * 1.2)) end to go ask turtles [ move stamp color ] set vclock vclock + 1 if (vclock = vsplit) [ set clock (clock + 1) set vclock 0 ] if show-center-of-mass? [ ask patch (round x-center) (round y-center) [ set pcolor gray ] ] update-variables do-plotting fade-patches end to manual setup while [ not done? ] [ go ask turtles [ if (abs pxcor = screen-edge-x) or (abs pycor = screen-edge-y) [ set done? true ] ] ] end to all-collision-angles manual set collision-angle collision-angle + 15 if collision-angle > 345 [ set collision-angle 15 ] end to all-reflection-angles manual set reflection-angle reflection-angle + 15 if reflection-angle = 360 [ set reflection-angle 0 ] end to move ;;turtle procedure jump (speed / vsplit) check-for-collision end to check-for-collision ;;turtle procedure 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 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 locals [ vcm ] ;; CM vel. along dir. theta set theta reflection-angle 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 to set-new-speed-and-headings ;;turtle procedure 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)) end to fade-patches ask patches with [ pcolor != black ] [ set pcolor ( pcolor - 0.05 ) if (round (pcolor mod 10) = black) [ set pcolor black ] ] end ;;; plotting procedures to do-plotting set-current-plot "Speeds" set-current-plot-pen "green" set-plot-pen-interval 1 / vsplit plot speed-of turtle 0 set-current-plot-pen "blue" set-plot-pen-interval 1 / vsplit plot speed-of turtle 1 end ;;; monitor procedures to-report speed-green ifelse turtle 0 = nobody [ report "" ] [ report speed-of turtle 0 ] end to-report energy-green ifelse turtle 0 = nobody [ report "" ] [ report energy-of turtle 0 ] end to-report speed-blue ifelse turtle 1 = nobody [ report "" ] [ report speed-of turtle 1 ] end to-report energy-blue ifelse turtle 1 = nobody [ report "" ] [ report energy-of turtle 1 ] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. 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. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo GasLab Single Collision model. ; http://ccl.northwestern.edu/netlogo/models/GasLabSingleCollision. ; 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/GasLabSingleCollision ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 389 10 723 365 40 40 4.0 0 10 1 1 1 CC-WINDOW 389 406 695 546 Command Center MONITOR 70 286 147 335 clock clock 0 1 MONITOR 156 286 238 335 avg-speed avg-speed 2 1 SLIDER 9 194 189 227 initmass-green initmass-green 1.0 20.0 2.0 1.0 1 NIL SLIDER 9 161 189 194 initspeed-green initspeed-green 1.0 20.0 10.0 1.0 1 NIL BUTTON 9 42 189 75 NIL manual NIL 1 T OBSERVER PLOT 70 345 332 544 Speeds time speed 0.0 5.0 0.0 20.0 true false PENS "green" 1.0 0 -11352576 true "blue" 1.0 0 -16776961 true MONITOR 249 286 333 335 avg-energy avg-energy 3 1 SLIDER 198 161 377 194 initspeed-blue initspeed-blue 1.0 20.0 10.0 1.0 1 NIL SLIDER 198 194 377 227 initmass-blue initmass-blue 1.0 20.0 2.0 1.0 1 NIL SLIDER 198 118 377 151 reflection-angle reflection-angle 0.0 345.0 0.0 15.0 1 NIL MONITOR 9 227 99 276 speed-green speed-green 3 1 MONITOR 198 227 288 276 speed-blue speed-blue 3 1 MONITOR 99 227 189 276 energy-green energy-green 3 1 MONITOR 288 227 377 276 energy-blue energy-blue 3 1 SLIDER 9 118 189 151 collision-angle collision-angle 15.0 345.0 15.0 15.0 1 NIL BUTTON 9 85 189 118 NIL all-collision-angles T 1 T OBSERVER BUTTON 198 85 377 118 NIL all-reflection-angles T 1 T OBSERVER SWITCH 198 42 377 75 show-center-of-mass? show-center-of-mass? 0 1 -1000 @#$#@#$#@ WHAT IS IT? ----------- This program simulates the behavior of gas molecules. It is related to one of the original CM StarLogo applications (under the name GPCEE) and is now ported to NetLogo as part of the PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS Project. This is one in a series of GasLab models that use the same basic rules for what happens when molecules run into each other. Each one has different features in order to show different aspects of the behavior of gases. This model is simplified to show the collision of only two molecules, since this event is so hard to watch when there are many molecules on the screen. This basic collision is the same as what is used in all the other models. Molecules are modeled as perfectly elastic particles with no internal energy except that which is due to their motion. Collisions between molecules are elastic. The exact way two molecules collide is as follows: 1. Two turtles "collide" if they find themselves on the same patch. In this model, two turtles are aimed toward each other with the same speed so that they will collide at the origin. 2. An axis is chosen, as if they were two balls that hit, and this axis were the line connecting their centers. This angle, called theta, can range between 0 and 360 degrees, and is set by the angle slider. Note that it is measured clockwise from straight up (the positive y-axis). 3. The turtles exchange momentum and energy only along that axis, according to the conservation of momentum and energy. This calculation is done in the center-of-mass system along that axis. 4. The new velocity of each turtle is translated back from the center-of-mass system to the screen reference frame. 5. Each turtle is assigned its new velocity, energy, and heading. HOW TO USE IT ------------- Setting the Initial Conditions: INITSPEED-GREEN (or -BLUE) - Sets the intial speed of the green (or blue) molecule. INITMASS-GREEN (or -BLUE) - Sets the mass of the green (or blue) molecule. COLLISION-ANGLE - Sets the angle that seperates the green and blue molecules. REFLECTION-ANGLE - Sets the angle (theta) of the collision's reflection axis. SHOW-CENTER-OF-MASS? - If On, the center of mass of the system will be shown in gray. Buttons for Running the Model: MANUAL - Runs a single collision using the currently selected settings. ALL-COLLISION-ANGLES - Runs a series of collisions with the COLLISION-ANGLE increased by 15 each time. ALL-REFLECTION-ANGLES - Runs a series of collisions with the REFLECTION-ANGLE increased by 15 each time. Seeing the Results: SPEED-GREEN (or -BLUE) - Shows the current speed of the green (or blue) molecule. ENERGY-GREEN (or -BLUE) - Shows the current energy of the green (or blue) molecule. CLOCK - Shows how many clock ticks have elapsed. Each molecule moves forward its speed each tick. AVG-SPEED - Shows the average of the speeds of the two molecules. AVG-ENERGY - Shows the average of the energies of the two molecules. SPEEDS plot - Plots the speed of each of the molecules over time. RUNNING the MODEL ----------------- Set the reflection-angle to zero. Draw a picture representing the two balls as they collide, with their two faces touching. Make the line connecting their centers be the same as theta. Draw vectors representing their motion. While running the following situations note the paths of the two particles. Can you make sense of what they do? Is it what you expected? Choose a COLLISION-ANGLE and a REFLECTION-ANGLE and push MANUAL to see one particular collision. Choose a COLLISION-ANGLE and push ALL-REFLECTION-ANGLEs to cycle through all of the angles of reflection. Choose a REFLECTION-ANGLE and push ALL-COLLISION-ANGLES to cycle through all of the angles of collsion. THINGS TO NOTICE ---------------- With COLLISION-ANGLE = 180 (directly across from each other) and REFLECTION-ANGLE = 90, it looks as if the two particles miss each other. What is happening? With REFLECTION-ANGLE = 45 degrees, the particles go off at right angles. Why? Draw a picture of what is happening at the moment of collision. With REFLECTION-ANGLE = 0 degrees, the two particles reverse direction. Why? What is the motion of the center of mass? What would you expect it to be? THINGS TO TRY ------------- Have the masses of the two particles be different. Have the initial speeds of the two particles be different. Change the initial positions and headings of the two particles. As a simple case, set one on the y-axis and the other on the x-axis, (COLLISION-ANGLE = 90) each one heading toward the origin. The center of mass is no longer stationary. Note its path. Is it what you would expect? If the center of mass is not stationary, the two particles often have different speeds after they collide, even when they have identical initial speeds and masses! Why does this happen? How can this satisfy the conservation of both energy and momentum? The fact that the velocities are not always the same after every kind of collision is essential to getting a distribution of velocities among identical particles after many collisions, which is what we observe with molecules in a gas. Does this seem like a reasonable model for colliding molecules? When is it reasonably valid, and when is it decidedly NOT valid? When two molecules collide, should theta be picked randomly -- each theta has an equal probability -- or in some other way? Would this change the eventual velocity distribution among many particles? After you have gotten used to observing and understanding these simple collisions, go to the "Free Gas" or "Gas in a Box" model. Especially watch the particle whose path is traced in gray. Does it make sense? Can you picture each collision? EXTENDING THE MODEL ------------------- Record the velocities of each particle after each collision. After you have several sets of velocities, look at the entire velocity distribution. What do you notice? Is it the Maxwell-Boltzmann distribution? CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo GasLab Single Collision model. http://ccl.northwestern.edu/netlogo/models/GasLabSingleCollision. 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/GasLabSingleCollision 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.0alpha1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@