Ising Benchmark
No preview image
Model was written in NetLogo 4.1pre9
•
Viewed 201 times
•
Downloaded 38 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
globals [ result sum-of-spins ;; sum of all the spins -- keeping track of this ;; means that we can always instantly calculate ;; the magnetization (which is the average spin) ] patches-own [ spin ;; holds -1 or 1 ] to benchmark random-seed 2929 reset-timer setup 0 repeat 2000000 [ go ] set result timer end to setup [initial-magnetization] ca ask patches [ ifelse initial-magnetization = 0 [ set spin one-of [-1 1] ] [ set spin initial-magnetization ] recolor ] set sum-of-spins sum [spin] of patches setup-plot update-plot end to go ask one-of patches [ update ] tick update-plot end to update ;; patch procedure ;; flipping changes the sign on our energy, so the difference in energy ;; if we flip is -2 times our current energy let Ediff 2 * spin * sum [spin] of neighbors4 if (Ediff <= 0) or (temperature > 0 and (random-float 1.0 < exp ((- Ediff) / temperature))) [ flip ] end to flip ;; patch procedure set spin (- spin) set sum-of-spins sum-of-spins + 2 * spin recolor end to recolor ;; patch procedure ifelse spin = 1 [ set pcolor red ] [ set pcolor blue ] end to-report magnetization report sum-of-spins / count patches end ;;; plotting procedures to setup-plot set-current-plot "Magnetization" ;; draw a horizontal line to show the x axis set-current-plot-pen "axis" auto-plot-off plotxy 0 0 plotxy 1000000000 0 auto-plot-on end ;; in the real model this isn't a separate procedure and we don't ;; bother calling set-current-plot and set-current-plot-pen all the ;; time. but I've left this in here so the model functions partly as ;; a benchmark on set-current-plot and set-current-plot-pen (and on ;; function call overhead) to update-plot set-current-plot "Magnetization" set-current-plot-pen "average spin" plotxy ticks magnetization end
There are 3 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.