turtles-own [ temp ;; this turtle's temperature neighboring-turtles ;; agentset of surrounding turtles sides-exposed ;; how many sides turtle has exposed ] 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 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) ;; create turtles everywhere inside the given box range ask patches [ if (not circle? and ((abs pycor) < height / 2) and ((abs pxcor) < width / 2)) or (circle? and distancexy 0 0 < height / 2) [ sprout 1 [ set shape "T" set temp init-metal-temp set-color ] ] ] 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 (9 - (count neighboring-turtles)) ] 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 / 10) 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 < 0 ) [ 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 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 Basic model. ; http://ccl.northwestern.edu/netlogo/models/CrystallizationBasic. ; 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/CrystallizationBasic ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 392 10 798 437 16 16 12.0 1 10 1 1 1 CC-WINDOW 9 272 339 431 Command Center BUTTON 261 88 329 123 go go T 1 T OBSERVER T BUTTON 220 42 286 79 NIL setup NIL 1 T OBSERVER T SLIDER 7 42 158 75 room-temp room-temp -20.0 100.0 20.0 1.0 1 NIL SLIDER 7 77 159 110 init-metal-temp init-metal-temp 1550.0 2500.0 1550.0 10.0 1 NIL SLIDER 7 113 159 146 melting-temp melting-temp 500.0 1500.0 550.0 1.0 1 NIL MONITOR 14 212 123 261 ave-metal-temp ave-metal-temp 3 1 SLIDER 181 133 317 166 width width 1 31 25 2 1 atoms SLIDER 181 168 317 201 height height 1 31 25 2 1 atoms PLOT 4 443 313 644 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 315 443 548 644 Number Solidified time crystal quant. 0.0 100.0 0.0 625.0 true false PENS "amount" 1.0 0 -16777216 false PLOT 550 443 812 644 Temperatures colors quantity 0.0 8.0 0.0 625.0 false true PENS "quantity" 1.0 1 -65536 false MONITOR 135 213 205 262 time time 0 1 SWITCH 222 219 345 252 histogram? histogram? 0 1 -1000 BUTTON 182 88 249 123 go once go NIL 1 T OBSERVER T SWITCH 34 168 130 201 circle? circle? 0 1 -1000 @#$#@#$#@ WHAT IS IT? ----------- When a metal cools, it begins to solidify. The first atoms to solidify have a random orientation. However, when a liquid atom about to solidify is next to an already solidified atom, the liquid atom orients itself with the solid atom, thus creating a crystal. As more and more atoms solidify, the crystals grow. Within each crystal, all the atoms are oriented with one another, but within the entire metal, all the crystals have random orientations. Each individual crystal is called a grain. When two crystals grow up next to each other, they form what is called a grain boundary. When a metal is stressed, such as when it is pulled from both ends, deformations occur in the crystal structure. As more stress is applied, these deformations pass through the crystal structure, allowing the metal to bend. Grain boundaries prevent deformations from flowing through the metal. Therefore, pieces of metal with fewer grain boundaries tend to be ductile, while pieces of metal with more grain boundaries tend to be brittle. This model shows how grains are formed as a metal crystallizes. In it, liquid metal is placed in a room with a constant temperature much lower than that of the metal. As heat leaves the metal, the metal begins to solidify. Liquid atoms are free to rotate, but solid atoms (gray) are literally frozen. If a liquid atom is next to a solid atom, it will orient itself with it, otherwise it will rotate randomly. (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. (Ignored if CIRCLE? switch is on.) 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: CIRCLE?: If on, pressing SETUP produces a circular piece of metal. Otherwise, you get a square or rectangular piece of metal. (If CIRCLE? is on, the size of the circle is determined by the WIDTH slider, and the HEIGHT slider is ignored.) 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 HEIGHT to 19. Try to obtain the largest grains possible by systematically changing the three temperature variables. Are there multiple settings that achieve this affect? Now find the settings that result in the smallest grains. Are there multiple settings that achieve this affect? Compare the time it takes for the metal to completely crystallize using each of the settings you found in the above paragraph. To do this, use the TIME monitor. How does crystallization time relate to grain size? Keeping the HEIGHT 19, what is the fewest number of grains you can make? Why can you not make only one grain? From what part of the metal does crystallization always start from? Does setting CIRCLE? to OFF make any difference? Set the ROOM-TEMP to be 20, the INIT-METAL-TEMP to be 1550, and the MELTING-TEMP to be 500. Set CIRCLE? to OFF. Now try various settings for HEIGHT and WIDTH. Which setting achieves the largest size of grains? Which setting achieves the fewest number of grains? EXTENDING THE MODEL ------------------- Some metal applications require that the metal's grains form long strips across the metal. To achieve this, only one side of the metal is cooled. This causes all of the crystals to begin on one side of the metal, and consequently grow across its length. This is called directional solidification. In the Procedures window, change the code so one side of the room is much cooler than the others. Other metal applications require that metal consist of a single grain. One way to do this is to crystallize the metal in a magnetic field. This induces polarization in the metal atoms, causing them to line up. Add a procedure to the code that creates a magnetic field in the room. 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. With every time step, each atom's temperature changes to the average of everything around it. To do this, each turtle has a list of all of its neighboring turtles. In this model, every patch surrounding a given turtle is either occupied by a turtle or considered to be outside the metal. Therefore, the new temperature is then taken as the average of the temperatures of the neighbor list, plus the room temperature multiplied by the maximum number of neighbors minus the number of neighbors that particular turtle has. Therefore, turtles completely surrounded by other turtles don't average in the room temperature to their temperature, but turtles on the edge of the metal will. RELATED MODELS -------------- Crystallization Directed 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 Basic model. http://ccl.northwestern.edu/netlogo/models/CrystallizationBasic. 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/CrystallizationBasic 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 20 [ go ] @#$#@#$#@ @#$#@#$#@