turtles-own [ temp ;; this turtle's temperature neighboring-turtles ;; agentset of surrounding turtles sides-exposed ;; number of sides exposed to cooling walls (between 0 and 4) ] globals [ ave-metal-temp ;; shows average temperature of all metal num-frozen ;; keeps track of how many atoms are frozen time ;; keeps track of time passing in system temp-range ;; for histogram colors ;; used both to color turtles, and for histogram pens ;; keeps track of all the histogram's pen names ] to setup locals [ymax xmax] ca set colors sentence (white - 1) [cyan sky blue violet magenta pink red] set pens [] set temp-range (init-metal-temp - melting-temp) / (length colors - 1) set ymax (height + 1) / 2 set xmax (width + 1) / 2 ;; create turtles everywhere inside the given box range ask patches [ if ((abs pycor) < ymax) and ((abs pxcor) < xmax) [ sprout 1 [ set shape "T" set temp init-metal-temp set-color ] ] ] ;; set sides of box for cooling ask patches [ if (heat-top? and (pycor = ymax) and (abs pxcor <= xmax)) or (heat-left? and (pxcor = (- xmax)) and (abs pycor <= ymax)) or (heat-right? and (pxcor = xmax) and (abs pycor <= ymax)) or (heat-bottom? and (pycor = (- ymax)) and (abs pxcor <= xmax)) [ set pcolor 16 ] ] ask turtles [ set neighboring-turtles (turtles at-points [[-1 1] [ 0 1] [1 1] [-1 0] [ 0 0] [1 0] [-1 -1] [ 0 -1] [1 -1]]) set sides-exposed (count patches at-points [[-1 1] [ 0 1] [1 1] [-1 0] [ 0 0] [1 0] [-1 -1] [ 0 -1] [1 -1]] with [(not any? turtles-here) and (pcolor = black)]) ] set ave-metal-temp init-metal-temp set time 0 setup-plots do-plots end to go ;; stop if all turtles are below melting temp if (max (values-from turtles [temp]) < melting-temp) [ stop ] ;; otherwise... set time (time + 1) set num-frozen 0 ask turtles [ cool-turtles ] ask turtles [ set-color ] ask turtles [ rotate ] set ave-metal-temp (mean values-from turtles [temp]) do-plots end ;; turtle procedure -- if metal is liquid and it is next to a solid, ;; change its heading to that of the solid; otherwise, just rotate ;; randomly to rotate locals [frozen-neighbors] if (temp >= melting-temp) [ set frozen-neighbors (neighboring-turtles with [temp <= melting-temp]) ifelse (any? frozen-neighbors) [ set heading (heading-of (random-one-of frozen-neighbors)) ] [ rt random-float 360 ] ] end ;; turtle procedure -- sets turtle's temp to ave temp of all ;; neighboring turtles and patches added turtle's own temp in twice so ;; it changes more slowly to cool-turtles locals [total-temp total-num] set total-temp ((sum values-from neighboring-turtles [temp]) + (room-temp * sides-exposed) + temp) set temp (total-temp / (count neighboring-turtles + sides-exposed + 1)) end ;; turtle procedure to set-color locals [ index ] ; create index ranging from 1 to 8 for all melting colors set index (floor ((temp - melting-temp) / temp-range)) + 1 ifelse (index < 1 ) [ set color white - 1 set num-frozen (num-frozen + 1) ] [ if index >= length colors [ set index (length colors) - 1 ] set color item index colors ] end to setup-plots set-current-plot "Average Metal Temperature" set-plot-y-range room-temp init-metal-temp set-current-plot "Number Solidified" set-plot-y-range 0 count turtles set-current-plot "Temperatures" set-plot-y-range 0 count turtles set-histogram-num-bars 1 + (length colors) make-histogram-pens end to make-histogram-pens locals [index top bottom] set bottom (round room-temp) set top (round melting-temp) set index 0 repeat (length colors) [ create-temporary-plot-pen bottom + " - " + top set-plot-pen-mode 1 set-plot-pen-color (item index colors) set pens lput (bottom + " - " + top) pens set index index + 1 set bottom top set top (round ((index * temp-range) + melting-temp)) ] end to do-plots set-current-plot "Average Metal Temperature" plot ave-metal-temp set-current-plot "Number Solidified" plot num-frozen if histogram? [ do-histogram ] end to do-histogram locals [index temp-color] set-current-plot "Temperatures" set index 0 repeat (length colors) [ set temp-color (item index colors) set-current-plot-pen (item index pens) plot-pen-reset ;; plot each bar of histogram separately if any? turtles with [color = temp-color] [ plotxy index count turtles with [color = temp-color] ] set index index + 1 ] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created 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. ; ; 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 Crystallization Directed model. ; http://ccl.northwestern.edu/netlogo/models/CrystallizationDirected. ; 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/CrystallizationDirected ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 393 10 799 437 16 16 12.0 1 10 1 1 1 CC-WINDOW 9 298 357 441 Command Center BUTTON 263 72 331 108 go go T 1 T OBSERVER T BUTTON 221 24 287 61 NIL setup NIL 1 T OBSERVER T SLIDER 9 27 172 60 room-temp room-temp -20.0 100.0 20.0 1.0 1 NIL SLIDER 9 66 172 99 init-metal-temp init-metal-temp 1550.0 2500.0 1550.0 10.0 1 NIL SLIDER 9 104 172 137 melting-temp melting-temp 500.0 1500.0 500.0 1.0 1 NIL MONITOR 93 236 195 285 ave-metal-temp ave-metal-temp 3 1 SLIDER 13 152 126 185 width width 1 31 29 2 1 atoms SLIDER 13 189 126 222 height height 1 31 29 2 1 atoms PLOT 6 447 310 648 Average Metal Temperature time ave-metal-temp 0.0 100.0 20.0 1550.0 true true PENS "ave-metal-temp" 1.0 0 -65536 false PLOT 313 447 546 648 Number Solidified time crystal quant. 0.0 100.0 0.0 625.0 true false PENS "amount" 1.0 0 -16777216 false PLOT 553 447 811 647 Temperatures colors quantity 0.0 8.0 0.0 625.0 false true PENS "quantity" 1.0 1 -65536 false MONITOR 13 236 83 285 time time 0 1 SWITCH 208 248 340 281 histogram? histogram? 0 1 -1000 BUTTON 183 72 250 107 go once go NIL 1 T OBSERVER T SWITCH 183 123 325 156 heat-top? heat-top? 1 1 -1000 SWITCH 180 191 322 224 heat-bottom? heat-bottom? 1 1 -1000 SWITCH 248 157 372 190 heat-right? heat-right? 1 1 -1000 SWITCH 133 157 247 190 heat-left? heat-left? 1 1 -1000 @#$#@#$#@ BACKGROUND ----------- The information window of this model assumes the user has already read and understood the original Crystallization Basic model. WHAT IS IT? ----------- Some metal applications require that a metal's grains form specific patterns. To achieve this, the metal is only cooled from certain sides. This can be done in several ways. For example, when molds are made of metal, wires are used to heat up the mold where they want the metal to crystallize last. For molds made of sand, pieces of metal are put where the liquid metal should crystallize first. The inserted metal (known as a heat sink), works to quickly suck the heat out of the liquid metal. This model represents the cross-section of a block of liquid metal cooling in a metal mold. The surrounding mold quickly sucks the heat out of the liquid metal. However, you can select some of the sides to be heated, which prevents heat from escaping out of those sides. By selecting which sides of the metal are heated, you can control the shapes of the resulting grains. (Note that the actual number of atoms is small compared to a real metal sample and the metal is only two-dimensional.) HOW TO USE IT ------------- Buttons: SETUP: Resets the simulation, and sets the metal to the correct size. GO-ONCE: Runs the simulation for one time step. GO: Runs the simulation continuously until either the GO button is pressed again, or all of the atoms are frozen. Sliders: WIDTH: How many atoms wide the metal is. HEIGHT: How many atoms high the metal is. ROOM-TEMP: Varies the temperature of the room. INIT-METAL-TEMP: Varies the initial temperature of the metal. MELTING-TEMP: Varies the temperature at which the metal solidifies. Monitors: AVE-METAL-TEMP: Monitors the average temperature of all the atoms. TIME: Keeps track of the time that has elapsed during each run. Switches: HEAT-TOP?: Prevents the top side of the metal from starting to cool. HEAT-LEFT?: Prevents the left side of the metal from starting to cool. HEAT-RIGHT?: Prevents the right side of the metal from starting to cool. HEAT-BOTTOM?: Prevents the bottom side of the metal from starting to cool. HISTOGRAM?: Turns the histogram plotting on and off. Turning off the histogram speeds up the model. Graphs: AVERAGE METAL TEMPERATURE: Plots the average temperature of all the metal over time. NUMBER SOLIDIFIED: Plots how many metal atoms are below the melting temperature over time. TEMPERATURES: Histograms how many atoms are in each temperature range. (Note that the colors of the histogram match the actual colors of the atoms.) THINGS TO TRY --------------- Set HEAT-TOP? and HEAT-RIGHT? to On and HEAT-BOTTOM? and HEAT-LEFT? to Off. Predict which atom will be the last to solidify. Now run the model and see if your prediction was correct. A contractor asks you to create a piece of metal for her that only has horizontal grain boundaries, and no vertical ones. Find settings for HEAT-TOP?, HEAT-RIGHT?, HEAT-BOTTOM?, and HEAT-LEFT? that result in approximately these sorts of grain boundaries. Set HEAT-TOP? and HEAT-BOTTOM? to Off and HEAT-LEFT? and HEAT-RIGHT to On. Run the model to completion. How do these settings affect the grain boundaries? How would these grain boundaries affect the properties of the metal? EXTENDING THE MODEL ------------------- In this model, heating a side simply results in the room temperature having no affect on that side. However, in real applications, heated sides still cool the metal, but at a slower rate. Change the cool-turtles procedure so heated sides factor into how atoms are cooled. As mentioned in the "What is it" section, molds made of sand use inserted pieces of metal to control which side of the metal should crystalize first. The inserted metal (known as a heat sink), works to quickly suck the heat out of the liquid metal. Change the model so instead of just having heated sides, there are also cooled sides that cause a faster cooling rate. NETLOGO FEATURES ------------------ In the setup procedure, a turtle is created on every patch within the requested dimensions. This is achieved by asking every patch satisfying certain conditions to SPROUT 1. Note how we can draw a multi-colored histogram. The HISTOGRAM primitive can only draw in one color at a time, but we work around this by calling it over and over again, plotting only one bar each time, changing the pen color each time. RELATED MODELS -------------- Crystallization Basic Crystallization Moving Crystallization Bending CREDITS AND REFERENCES ---------------------- Original implementation: Carrie Hobbs, for the Center for Connected Learning and Computer-Based Modeling. To refer to this model in academic publications, please use: Wilensky, U. (2002). NetLogo Crystallization Directed model. http://ccl.northwestern.edu/netlogo/models/CrystallizationDirected. 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/CrystallizationDirected for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 t true 0 Rectangle -7566196 true true 46 47 256 75 Rectangle -7566196 true true 135 76 167 297 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ setup repeat 37 [ go ] @#$#@#$#@ @#$#@#$#@