MaterialSim Grain Growth

MaterialSim Grain Growth preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Default-person Paulo Blikstein (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 591 times • Downloaded 108 times • Run 1 time
Download the 'MaterialSim Grain Growth' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; two different materials or phases
breed [ element1s element1 ]  ;; element1 is the main material
breed [ element2s element1 ]  ;; element2 is the materials which is
                              ;; dispersed inside element1 (second-phase particles)

element1s-own [
  neighbors-6   ;; agentset of 6 neighboring cells
]

turtles-own [
  neighboring-turtles  ;; agentset of surrounding atoms
  sides-exposed        ;; number of sides exposed to walls  (between 0 and 4)
]

globals [
  logtime                          ;; log of time
  colors                           ;; used both to color turtles, and for histogram
  xmax                             ;; max x size
  ymax                             ;; max y size
  average-grain-size               ;; average grain size
  logaverage-grain-size            ;; log of average grain size (for plotting)
  initial-loggrain-size            ;; For grain growth exponent calculation and graphing
  initial-logtime                  ;; For grain growth exponent calculation and graphing
  grain-growth-exponent            ;; Grain growth exponent
  update-plots?                    ;; boolean for updating plots immediately
]

;; setup checks whether user has chosen "import image" or random in the chooser-widget

to setup
  if starting-point = "Random Arrangement" [
    makes-initial-box-random
  ]
  if starting-point = "Import Image" [
    import-image
  ]
  reset-ticks
end 

to setup-hex-grid
  ;; setup the hexagonal grid in which atoms will be placed
  ;; and creates turtles
  set-default-shape element2s "square 2"
  
  ask patches [
    sprout 1 [
      ;; if there is a second element, create the corresponding atoms
      ifelse (percent-element2 > random 100) [
        ;; element2 is the fixed second-phase particle
        set breed element2s
        set color white
        set heading 360
      ]
      [
        ;; element1 is the main material which grows grains
        set breed element1s
        set shape atom-shape
        set color random 139
        ;; to ensure that the colors are distinct, we only let
        ;; colors deviate from base color by plus or minus 3
        set color one-of base-colors - 3 + random 6
        set heading color
      ]      
      ;; shift even columns down
      if pxcor mod 2 = 0  [ set ycor ycor - 0.5 ] 
    ] 
  ]
  
  ; the two lines below are for NetLogo 3D. Uncomment them, if you are using NetLogo 3D.
  ; ask element1s [ set shape3d "sphere" ]
  ; ask element2s [ set shape3d "cube" ]
  
  ;; now set up the neighbors6 agentsets
  ask element1s [
    ;; define neighborhood of atoms
    ifelse pxcor mod 2 = 0
      [ set neighbors-6 element1s-on patches at-points [[0 1] [1 0] [1 -1] [0 -1] [-1 -1] [-1 0]] ]
      [ set neighbors-6 element1s-on patches at-points [[0 1] [1 1] [1  0] [0 -1] [-1  0] [-1 1]] ] 
  ]
end 

;; makes initial box for image import

to makes-initial-box
  setup-hex-grid
end 

;; makes initial box for random arrangement

to makes-initial-box-random
  clear-all
  setup-hex-grid
end 

;; import image into turtles

to import-image
  clear-all
  let file user-file
  if file = false [ stop ]
  ;; imports image into patches
  import-pcolors file
  ;; converts the square grid to an hex grid
  makes-initial-box
  
  ;; transfers the image to the turtles. Rounds the color values to be integers.
  ask turtles [
    set color round pcolor
    set heading color
  ]
  
  ;; erases the patches (sets their color back to black),
  ask patches [ set pcolor black ]
  reset-ticks
end 

to define-neighboring-turtles
  ;; defines neighboring turtles. Some are "off" because atoms are in hexagons
  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]
    ])
  ]  
end 

to go  
  ;;initiates grain growth
  let total-atoms count turtles
  
  ;; stops when there is just one grain
  if average-grain-size >= total-atoms [ stop ]
  
  ;;limits grain growth to element1, element2 represent the stationary second-phase particles
  ask element1s [grain-growth]
  
;  ;; calculates grain variables at a given frequency to save CPU processing
;  ;; we + 1 to ticks to put it in sync with plots (that are updated in 'tick')
;  if remainder (ticks + 1) ticks-per-measurement = 0 [
;    count-grains-and-measure-grain-size
;  ]
  
  ;; advance Monte Carlo Steps (simulation time)
  ;; one Monte Carlo Step represents 'n' reorientation attemps,
  ;; where 'n' is the total number of atoms
  tick 
end 

to count-grains-and-measure-grain-size
  ;; we only do this for ticks > 0 since we can't take log of 0
  if ticks > 0 [
    set logtime log ticks 10
  ]
  grain-count
  if average-grain-size != 0 [
    set logaverage-grain-size (log (average-grain-size) 10)
  ]
  ;; we set the initial log time and grain size at 20 (we don't start
  ;; calculating grain size until then to give the system a bit of time to stabilize
  if ticks = 20 [
    set initial-logtime logtime
    set initial-loggrain-size logaverage-grain-size
  ]
  ;; only initiates grain size calculation after 20 ticks
  if ticks > 20 [
    ;; calculate the angular coefficient of the grain growth curve
    ;; since it is a log-log plot, it's the grain growth exponent
    set grain-growth-exponent (-1 * ((logaverage-grain-size - initial-loggrain-size) /
      (initial-logtime - logtime)))
  ]
end 

to grain-count
  ;; count number of grains based on the number of linear intercepts
  
  let orientation-for-intercept-count 90 ;; direction of intercepts count
  let intercepts 0
  let total-atoms count turtles
  
  ;; asking only elements1 with xcor less than 24
  ;; those at 24 are on the 'edge of the world' which means
  ;; that they will never have neighbors to their right.
  ;; we therefore simply ignore them for this purpose.
  ask element1s with [ xcor < 24 ] [
    ;; checks if there is a turtle to the right for the intercept calculation
    let target-patch patch-at-heading-and-distance orientation-for-intercept-count 1
    ifelse target-patch != nobody and any? turtles-on target-patch [
      ;; If there is a turtle, checks if the heading is different.
      let right-neighbor one-of turtles-on target-patch
      if heading != [ heading ] of right-neighbor [
        ;; If heading is different, add 1 to 'intercepts'.
        set intercepts (intercepts + 1)
      ]
    ]
    [
      ;; if there is no turtle, simply add 1 to 'intercepts'.
      ;; A turtle/nothing interface is considered as grain boundary.
      set intercepts (intercepts + 1)
    ]
  ]
  ;; we add one to intercepts so that zero intercepts = one grain, one intercept = 2 grains, etc.
  set average-grain-size total-atoms / (intercepts + 1)
end 


;; Grain growth procedure - free energy minimization
;; if another random crystallographic heading minimizes energy, switches headings, otherwise keeps the same.

to grain-growth
  ;; if atom has no neighbors, it is surrounded by element2s, and will not change its orientation
  if not any? neighbors-6 [ stop ]
  
  ;; calculates the PRESENT free energy
  let present-heading (heading)
  let present-free-energy count neighbors-6 with [ heading != present-heading ]
  
  ;; chooses a random orientation
  let future-heading ([heading] of (one-of neighbors-6))
  
  ;; calculates the FUTURE free energy, with the random orientation just chosen
  let future-free-energy count neighbors-6 with [ heading != future-heading ]
  
  ;; compares PRESENT and FUTURE free-energies; the lower value "wins"
  ifelse future-free-energy <= present-free-energy
    [ set heading future-heading ]
    [ if (annealing-temperature > random-float 100) [ set heading (future-heading) ] ]
  ;; this last line simulates thermal agitation (adds more randomness to the simulation)
  
  ;;update the color of the atoms
  set color heading
end 

;; drawing procedure

to turtle-draw
  if mouse-down? [    ;; reports true or false to indicate whether mouse button is down
    ask patch mouse-xcor mouse-ycor [
      ask element1s in-radius brush-size [
        set color read-from-string draw-color
        set heading color
      ]
    ]
    display
  ]
end 

;; in the drawing mode, erases the whole "canvas" with red

to erase-all
  ask element1s [
    set color red 
    set heading color
  ]
end 


; Copyright 2005 Uri Wilensky.
; See Info tab for full copyright and license.

There are 15 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago MaterialSim Grain Growth Download this version

Attached files

File Type Description Last updated
MaterialSim Grain Growth.png preview preview over 11 years ago, by Reuven M. Lerner Download
MaterialSim Grain Growth.png preview Preview for 'MaterialSim Grain Growth' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.