diff --git a/mill1825/python/grid.py b/mill1825/python/grid.py new file mode 100644 index 0000000..6fd4e21 --- /dev/null +++ b/mill1825/python/grid.py @@ -0,0 +1,99 @@ +import math +from math import exp +import random +import numpy as np + +random.seed() + +def pause(): + garbage = raw_input("[PAUSE]") + +class ising_grid(object): + def __init__(self, x_dim=10, y_dim=10): + self.grid = [] + self.x_max = x_dim + self.y_max = y_dim + self.J = 1.0 + self.B = 1.0 + self.T = 1.0 + self.beta = 1/self.T + + def initialize(self): + self.grid = np.ones([self.y_max, self.x_max]) + + def compute_boltzmann_factor(self, S): + return (exp(2*(self.J*S + self.B)*self.beta), exp(-2*(self.J*S + self.B)*self.beta)) + + def metropolis(self): + + self.initialize() + + boltzmann_factor = {} + for S in [-4, -2, 0, 2, 4]: + boltzmann_factor[S] = self.compute_boltzmann_factor(S) + + M = [] + + for k in range(self.xM*self.y_max*self.x_max): + + # ------------------------ + # Metropolis algorithm + # ------------------------ + + i = random.randint(0,self.x_max-1) + j = random.randint(0,self.y_max-1) + val = self.spin(i,j) + + # if spin i is down, choose first column in precomputed boltzmann factors (corresponds to flipping the spin) + if(val == -1): + w = boltzmann_factor[self.get_S(i, j)][0] + # if spin i is down, choose second column in precomputed boltzmann factors (corresponds to flipping the spin) + elif(val == 1): + w = boltzmann_factor[self.get_S(i, j)][1] + if(w > 1): + self.flip(i, j) + else: + if(w > random.random()): + self.flip(i, j) + + M.append(self.get_M()) + + M = np.array(M) + + return np.mean(M), self.std_block(M) + + def std_block(self, data): + std = [] + blocks = 50 + split = len(data)/blocks + for i in range(blocks): + std.append(np.std(data[(i*split):((i+1)*split)])) + return np.std(np.array(std)) + + def set_T(self,T): + self.T = float(T) + self.beta = 1./self.T + + def spin(self, i, j): + return self.grid[j][i] + + def get_M(self): + return np.sum(self.grid)/self.x_max/self.y_max + + def flip(self, i, j): + self.grid[j][i] *= -1 + + def get_E(self): + E = 0.0 + for j in range(self.y_max): + for i in range(self.x_max): + E += self.get_S(i, j) + return E + + def get_S(self, i_in, j_in, p=False): + i, j = i_in%self.x_max, j_in%self.y_max + # This is where the periodic BCs are implemented + ip1, jp1 = (i_in+1)%self.x_max, (j_in+1)%self.y_max + im1, jm1 = (i_in-1)%self.x_max, (j_in-1)%self.y_max + return (self.grid[jm1][i] + self.grid[jp1][i] + self.grid[j][ip1] + self.grid[j][im1]) + diff --git a/mill1825/python/gui.py b/mill1825/python/gui.py new file mode 100644 index 0000000..31e78fc --- /dev/null +++ b/mill1825/python/gui.py @@ -0,0 +1,90 @@ +from Tkinter import * +import colorsys + +class ising_gui(object): + MIN_RED = MIN_GREEN = MIN_BLUE = 0x0 + MAX_RED = MAX_GREEN = MAX_BLUE = 0xFF + PIXEL_WIDTH = 10 + + def __init__(self, grid_x, grid_y): + self.grid_x = grid_x + self.grid_y = grid_y + self.pixels = [(0, 0, 0) for i in range(self.grid_x * self.grid_y)] + + self.root = Tk() + self.root.title("Ising Simulation %d x %d" % (self.grid_x, self.grid_y)) + self.root.resizable(0, 0) + self.frame = Frame(self.root, bd=5, relief=SUNKEN) + self.frame.pack(side = TOP) + + self.canvas = Canvas(self.frame, + width=self.PIXEL_WIDTH * self.grid_x, + height=self.PIXEL_WIDTH * self.grid_y, + bd=0, highlightthickness=0) + self.canvas.pack() + + + self.TString = StringVar() + self.EString = StringVar() + self.GString = StringVar() + + self.bframe = Frame(self.root) + self.TLabel = Label(self.bframe, anchor=N, textvariable = self.TString) + self.ELabel = Label(self.bframe, anchor=S, textvariable = self.EString) + self.GLabel = Label(self.bframe, anchor=CENTER, textvariable = self.GString) + self.bframe.pack(side = BOTTOM) + self.root.update() + + def draw_grid(self, grid): + self.set_T(grid.T) + + for j in range(grid.y_max): + for i in range(grid.x_max): + spin = grid.spin(i, j) + if(spin == 1): + self.set_pixel(i, j, (0, 0, 0x00)) + elif(spin == -1): + self.set_pixel(i, j, (0, 0, 0xFF)) + else: + self.set_pixel(i, j, (0x00, 0xFF, 0xFF)) + + self.draw() + + def set_pixel(self, x, y, hsv): + self.pixels[self.grid_x * y + x] = hsv + + def get_pixel(self, x, y): + return self.pixels[self.grid_x * y + x] + + def set_T(self, temp): + self.TString.set("T = %f" % temp) + self.TLabel.pack() + + def draw(self): + self.canvas.delete(ALL) + for x in range(len(self.pixels)): + x_0 = (x % self.grid_x) * self.PIXEL_WIDTH + y_0 = (x / self.grid_x) * self.PIXEL_WIDTH + x_1 = x_0 + self.PIXEL_WIDTH + y_1 = y_0 + self.PIXEL_WIDTH + hue = "#%02x%02x%02x" % self._get_rgb(self.pixels[x]) + self.canvas.create_rectangle(x_0, y_0, x_1, y_1, fill=hue) + self.canvas.update() + + def clear(self): + for i in range(self.width * self.height): + self.pixels[i] = (0, 0, 0) + + def _hsv_to_rgb(self, hsv): + rgb = colorsys.hsv_to_rgb(*hsv) + red = self.MAX_RED * rgb[0] + green = self.MAX_GREEN * rgb[1] + blue = self.MAX_BLUE * rgb[2] + return (red, green, blue) + + def _get_rgb(self, hsv): + red, green, blue = self._hsv_to_rgb(hsv) + red = int(float(red) / (self.MAX_RED - self.MIN_RED) * 0xFF) + green = int(float(green) / (self.MAX_GREEN - self.MIN_GREEN) * 0xFF) + blue = int(float(blue) / (self.MAX_BLUE - self.MIN_BLUE) * 0xFF) + return (red, green, blue) diff --git a/mill1825/python/ising.py b/mill1825/python/ising.py new file mode 100644 index 0000000..0ac1eb9 --- /dev/null +++ b/mill1825/python/ising.py @@ -0,0 +1,47 @@ +def pause(): + garbage = raw_input("[PAUSE]") + +from grid import * +from gui import ising_gui +import numpy as np +import matplotlib.pyplot as plt + +gui = True + +# --------------------------------------- +# Change lattice dimensions here +Ni = 20 +Nj = 20 +# --------------------------------------- + +grid = ising_grid(Ni, Nj) +if gui: display = ising_gui(Ni, Nj) + +M, M_err = [], [] +Ch, ChB = [], [] +T = np.linspace(1.0, 4.0, 30) + +grid.B = 0.00 +grid.J = 1.00 + +# --------------------------------------- +# Change Metropolis iteration scale here +grid.xM = 50 +# --------------------------------------- + +for T_i in T: + grid.set_T(T_i) + M_i, M_std = grid.metropolis() + if gui: display.draw_grid(grid) + print "T = %.3e, M = %.3e"%(T_i, M_i) + M.append(M_i) + M_err.append(M_std) + +M = np.array(M) +fig = plt.figure() +ax_1 = fig.add_subplot(111) +ax_1.errorbar(T, M, yerr=M_err, fmt="b.") +plt.xlabel("Temperature (K)") +plt.ylabel("Magnetization") + +plt.show() diff --git a/mill1825/report/ising.aux b/mill1825/report/ising.aux new file mode 100644 index 0000000..befa369 --- /dev/null +++ b/mill1825/report/ising.aux @@ -0,0 +1,16 @@ +\relax +\@writefile{toc}{\contentsline {section}{\numberline {1}Theory}{1}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}Ising Model}{1}} +\newlabel{eq:spins}{{1}{1}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.2}Monte Carlo and the Metropolis Algorithm}{1}} +\newlabel{eq:mag_avg}{{3}{1}} +\newlabel{eq:magnetization}{{4}{2}} +\@writefile{toc}{\contentsline {section}{\numberline {2}Some Coding Tricks}{2}} +\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Precomputing Boltzmann Factors}{2}} +\@writefile{toc}{\contentsline {subsection}{\numberline {2.2}Periodic Boundary Conditions}{2}} +\@writefile{toc}{\contentsline {section}{\numberline {3}Results}{2}} +\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Magnetization over temperature of a $10\times 10$ periodic lattice with a $N_x=10,000$ scale to the number of Metropolis iterations.\relax }}{3}} +\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}} +\newlabel{fig:mag10x10}{{1}{3}} +\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces Final configuration for three different temperatures.\relax }}{3}} +\newlabel{fig:mag50x50}{{2}{3}} diff --git a/mill1825/report/ising.log b/mill1825/report/ising.log new file mode 100644 index 0000000..252f8c5 --- /dev/null +++ b/mill1825/report/ising.log @@ -0,0 +1,378 @@ +This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2012.10.11) 18 FEB 2015 14:49 +entering extended mode + %&-line parsing enabled. +**ising.tex +(./ising.tex +LaTeX2e <2009/09/24> +Babel and hyphenation patterns for english, usenglishmax, dumylang, noh +yphenation, loaded. +(/usr/share/texmf-texlive/tex/latex/base/article.cls +Document Class: article 2007/10/19 v1.4h Standard LaTeX document class +(/usr/share/texmf-texlive/tex/latex/base/size12.clo +File: size12.clo 2007/10/19 v1.4h Standard LaTeX file (size option) +) +\c@part=\count79 +\c@section=\count80 +\c@subsection=\count81 +\c@subsubsection=\count82 +\c@paragraph=\count83 +\c@subparagraph=\count84 +\c@figure=\count85 +\c@table=\count86 +\abovecaptionskip=\skip41 +\belowcaptionskip=\skip42 +\bibindent=\dimen102 +) +(/usr/share/texmf-texlive/tex/latex/geometry/geometry.sty +Package: geometry 2008/12/21 v4.2 Page Geometry + +(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty +Package: keyval 1999/03/16 v1.13 key=value parser (DPC) +\KV@toks@=\toks14 +) +(/usr/share/texmf-texlive/tex/generic/oberdiek/ifpdf.sty +Package: ifpdf 2009/04/10 v2.0 Provides the ifpdf switch (HO) +Package ifpdf Info: pdfTeX in pdf mode detected. +) +(/usr/share/texmf-texlive/tex/generic/oberdiek/ifvtex.sty +Package: ifvtex 2008/11/04 v1.4 Switches for detecting VTeX and its modes (HO) +Package ifvtex Info: VTeX not detected. +) +\Gm@cnth=\count87 +\Gm@cntv=\count88 +\c@Gm@tempcnt=\count89 +\Gm@bindingoffset=\dimen103 +\Gm@wd@mp=\dimen104 +\Gm@odd@mp=\dimen105 +\Gm@even@mp=\dimen106 +\Gm@dimlist=\toks15 +) +(/usr/share/texmf-texlive/tex/latex/appendix/appendix.sty +Package: appendix 2009/09/02 v1.2b extra appendix facilities +\c@@pps=\count90 +\c@@ppsavesec=\count91 +\c@@ppsaveapp=\count92 +) +(/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty +Package: amsmath 2000/07/18 v2.13 AMS math features +\@mathmargin=\skip43 + +For additional information on amsmath, use the `?' option. +(/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty +Package: amstext 2000/06/29 v2.01 + +(/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty +File: amsgen.sty 1999/11/30 v2.0 +\@emptytoks=\toks16 +\ex@=\dimen107 +)) +(/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty +Package: amsbsy 1999/11/29 v1.2d +\pmbraise@=\dimen108 +) +(/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty +Package: amsopn 1999/12/14 v2.01 operator names +) +\inf@bad=\count93 +LaTeX Info: Redefining \frac on input line 211. +\uproot@=\count94 +\leftroot@=\count95 +LaTeX Info: Redefining \overline on input line 307. +\classnum@=\count96 +\DOTSCASE@=\count97 +LaTeX Info: Redefining \ldots on input line 379. +LaTeX Info: Redefining \dots on input line 382. +LaTeX Info: Redefining \cdots on input line 467. +\Mathstrutbox@=\box26 +\strutbox@=\box27 +\big@size=\dimen109 +LaTeX Font Info: Redeclaring font encoding OML on input line 567. +LaTeX Font Info: Redeclaring font encoding OMS on input line 568. +\macc@depth=\count98 +\c@MaxMatrixCols=\count99 +\dotsspace@=\muskip10 +\c@parentequation=\count100 +\dspbrk@lvl=\count101 +\tag@help=\toks17 +\row@=\count102 +\column@=\count103 +\maxfields@=\count104 +\andhelp@=\toks18 +\eqnshift@=\dimen110 +\alignsep@=\dimen111 +\tagshift@=\dimen112 +\tagwidth@=\dimen113 +\totwidth@=\dimen114 +\lineht@=\dimen115 +\@envbody=\toks19 +\multlinegap=\skip44 +\multlinetaggap=\skip45 +\mathdisplay@stack=\toks20 +LaTeX Info: Redefining \[ on input line 2666. +LaTeX Info: Redefining \] on input line 2667. +) +(/usr/share/texmf-texlive/tex/latex/amsfonts/amsfonts.sty +Package: amsfonts 2009/06/22 v3.00 Basic AMSFonts support +\symAMSa=\mathgroup4 +\symAMSb=\mathgroup5 +LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold' +(Font) U/euf/m/n --> U/euf/b/n on input line 96. +) +(/usr/share/texmf-texlive/tex/latex/amsfonts/amssymb.sty +Package: amssymb 2009/06/22 v3.00 +) +(/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty +Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR) + +(/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty +Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) + +(/usr/share/texmf-texlive/tex/latex/graphics/trig.sty +Package: trig 1999/03/16 v1.09 sin cos tan (DPC) +) +(/etc/texmf/tex/latex/config/graphics.cfg +File: graphics.cfg 2009/08/28 v1.8 graphics configuration of TeX Live +) +Package graphics Info: Driver file: pdftex.def on input line 91. + +(/usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def +File: pdftex.def 2010/03/12 v0.04p Graphics/color for pdfTeX +\Gread@gobject=\count105 +)) +\Gin@req@height=\dimen116 +\Gin@req@width=\dimen117 +) +(/home/nick/texmf/tex/latex/wrapfig.sty +\wrapoverhang=\dimen118 +\WF@size=\dimen119 +\c@WF@wrappedlines=\count106 +\WF@box=\box28 +\WF@everypar=\toks21 +Package: wrapfig 1999/03/11 v 3.2 +) +(/usr/share/texmf-texlive/tex/latex/graphics/color.sty +Package: color 2005/11/14 v1.0j Standard LaTeX Color (DPC) + +(/etc/texmf/tex/latex/config/color.cfg +File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive +) +Package color Info: Driver file: pdftex.def on input line 130. +) +(/usr/share/texmf-texlive/tex/latex/float/float.sty +Package: float 2001/11/08 v1.3d Float enhancements (AL) +\c@float@type=\count107 +\float@exts=\toks22 +\float@box=\box29 +\@float@everytoks=\toks23 +\@floatcapt=\box30 +) +(/usr/share/texmf-texlive/tex/latex/tools/tabularx.sty +Package: tabularx 1999/01/07 v2.07 `tabularx' package (DPC) + +(/usr/share/texmf-texlive/tex/latex/tools/array.sty +Package: array 2008/09/09 v2.4c Tabular extension package (FMi) +\col@sep=\dimen120 +\extrarowheight=\dimen121 +\NC@list=\toks24 +\extratabsurround=\skip46 +\backup@length=\skip47 +) +\TX@col@width=\dimen122 +\TX@old@table=\dimen123 +\TX@old@col=\dimen124 +\TX@target=\dimen125 +\TX@delta=\dimen126 +\TX@cols=\count108 +\TX@ftn=\toks25 +) +(/usr/share/texmf-texlive/tex/latex/colortbl/colortbl.sty +Package: colortbl 2001/02/13 v0.1j Color table columns (DPC) +\everycr=\toks26 +\minrowclearance=\skip48 +) +(/usr/share/texmf-texlive/tex/latex/amscls/amsthm.sty +Package: amsthm 2004/08/06 v2.20 +\thm@style=\toks27 +\thm@bodyfont=\toks28 +\thm@headfont=\toks29 +\thm@notefont=\toks30 +\thm@headpunct=\toks31 +\thm@preskip=\skip49 +\thm@postskip=\skip50 +\thm@headsep=\skip51 +\dth@everypar=\toks32 +) +(/usr/share/texmf-texlive/tex/latex/caption/caption.sty +Package: caption 2009/10/09 v3.1k Customizing captions (AR) + +(/usr/share/texmf-texlive/tex/latex/caption/caption3.sty +Package: caption3 2009/10/09 v3.1k caption3 kernel (AR) +\captionmargin=\dimen127 +\captionmargin@=\dimen128 +\captionwidth=\dimen129 +\caption@indent=\dimen130 +\caption@parindent=\dimen131 +\caption@hangindent=\dimen132 +) +\c@ContinuedFloat=\count109 +Package caption Info: float package is loaded. +Package caption Info: wrapfig package is loaded. +) +(/usr/share/texmf-texlive/tex/latex/caption/subcaption.sty +Package: subcaption 2008/08/31 v1.0b Adding subcaptions (AR) +\c@subfigure=\count110 +\c@subtable=\count111 +) +(/usr/share/texmf-texlive/tex/latex/fancyhdr/fancyhdr.sty +\fancy@headwidth=\skip52 +\f@ncyO@elh=\skip53 +\f@ncyO@erh=\skip54 +\f@ncyO@olh=\skip55 +\f@ncyO@orh=\skip56 +\f@ncyO@elf=\skip57 +\f@ncyO@erf=\skip58 +\f@ncyO@olf=\skip59 +\f@ncyO@orf=\skip60 +) (./ising.aux) +\openout1 = `ising.aux'. + +LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 28. +LaTeX Font Info: ... okay on input line 28. +LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 28. +LaTeX Font Info: ... okay on input line 28. +LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 28. +LaTeX Font Info: ... okay on input line 28. +LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 28. +LaTeX Font Info: ... okay on input line 28. +LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 28. +LaTeX Font Info: ... okay on input line 28. +LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 28. +LaTeX Font Info: ... okay on input line 28. + +*geometry auto-detecting driver* +*geometry detected driver: pdftex* +-------------------- Geometry parameters +paper: a4paper +landscape: -- +twocolumn: -- +twoside: -- +asymmetric: -- +h-parts: 72.26999pt, 452.9679pt, 72.26999pt +v-parts: 72.26999pt, 700.50687pt, 72.26999pt +hmarginratio: -- +vmarginratio: -- +lines: -- +heightrounded: -- +bindingoffset: 0.0pt +truedimen: -- +includehead: -- +includefoot: -- +includemp: -- +driver: pdftex +-------------------- Page layout dimensions and switches +\paperwidth 597.50787pt +\paperheight 845.04684pt +\textwidth 452.9679pt +\textheight 700.50687pt +\oddsidemargin 0.0pt +\evensidemargin 0.0pt +\topmargin -37.0pt +\headheight 12.0pt +\headsep 25.0pt +\footskip 30.0pt +\marginparwidth 35.0pt +\marginparsep 10.0pt +\columnsep 10.0pt +\skip\footins 10.8pt plus 4.0pt minus 2.0pt +\hoffset 0.0pt +\voffset 0.0pt +\mag 1000 + +(1in=72.27pt, 1cm=28.45pt) +----------------------- +(/usr/share/texmf-texlive/tex/context/base/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +\scratchcounter=\count112 +\scratchdimen=\dimen133 +\scratchbox=\box31 +\nofMPsegments=\count113 +\nofMParguments=\count114 +\everyMPshowfont=\toks33 +\MPscratchCnt=\count115 +\MPscratchDim=\dimen134 +\MPnumerator=\count116 +\everyMPtoPDFconversion=\toks34 +) +Package caption Info: Begin \AtBeginDocument code. +Package caption Info: End \AtBeginDocument code. +LaTeX Font Info: Try loading font information for U+msa on input line 35. + (/usr/share/texmf-texlive/tex/latex/amsfonts/umsa.fd +File: umsa.fd 2009/06/22 v3.00 AMS symbols A +) +LaTeX Font Info: Try loading font information for U+msb on input line 35. + +(/usr/share/texmf-texlive/tex/latex/amsfonts/umsb.fd +File: umsb.fd 2009/06/22 v3.00 AMS symbols B +) +LaTeX Font Info: Try loading font information for OMS+cmr on input line 64. + +(/usr/share/texmf-texlive/tex/latex/base/omscmr.fd +File: omscmr.fd 1999/05/25 v2.5h Standard LaTeX font definitions +) +LaTeX Font Info: Font shape `OMS/cmr/m/n' in size <12> not available +(Font) Font shape `OMS/cmsy/m/n' tried instead on input line 64. + + +Package Fancyhdr Warning: \headheight is too small (12.0pt): + Make it at least 14.49998pt. + We now make it that large for the rest of the document. + This may cause the page layout to be inconsistent, however. + +[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map} + +] +<../results/magnetization_10x10_10k.pdf, id=14, 587.19376pt x 442.65375pt> +File: ../results/magnetization_10x10_10k.pdf Graphic file (type pdf) + + + +LaTeX Warning: `!h' float specifier changed to `!ht'. + + + +pdfTeX warning: pdflatex (file ../results/50x50.pdf): PDF inclusion: found PDF +version <1.5>, but at most version <1.4> allowed +<../results/50x50.pdf, id=16, 623.93127pt x 241.703pt> +File: ../results/50x50.pdf Graphic file (type pdf) + + + +LaTeX Warning: `!h' float specifier changed to `!ht'. + +[2] [3 <../results/magnetization_10x10_10k.pdf> <../results/50x50.pdf>] +(./ising.aux) ) +Here is how much of TeX's memory you used: + 3780 strings out of 495061 + 52133 string characters out of 1182620 + 120501 words of memory out of 3000000 + 6911 multiletter control sequences out of 15000+50000 + 11195 words of font info for 44 fonts, out of 3000000 for 9000 + 28 hyphenation exceptions out of 8191 + 36i,12n,43p,642b,360s stack positions out of 5000i,500n,10000p,200000b,50000s + +Output written on ising.pdf (3 pages, 181845 bytes). +PDF statistics: + 106 PDF objects out of 1000 (max. 8388607) + 0 named destinations out of 1000 (max. 500000) + 11 words of extra memory for PDF output out of 10000 (max. 10000000) + diff --git a/mill1825/report/ising.pdf b/mill1825/report/ising.pdf new file mode 100644 index 0000000..2568bac Binary files /dev/null and b/mill1825/report/ising.pdf differ diff --git a/mill1825/report/ising.synctex.gz b/mill1825/report/ising.synctex.gz new file mode 100644 index 0000000..caa4ba5 Binary files /dev/null and b/mill1825/report/ising.synctex.gz differ diff --git a/mill1825/report/ising.tex b/mill1825/report/ising.tex new file mode 100644 index 0000000..3678a45 --- /dev/null +++ b/mill1825/report/ising.tex @@ -0,0 +1,109 @@ +\documentclass[12pt,oneside,a4paper]{article} + +\pdfminorversion 4 + +\usepackage[margin=1in]{geometry} +\usepackage[toc,page]{appendix} +\usepackage{amsmath,amsfonts,amssymb} +\usepackage{graphicx, wrapfig} +\usepackage{color} +\usepackage{float} +\usepackage{tabularx,colortbl} + +\usepackage{amsthm} + +\usepackage[font=footnotesize]{caption} +\usepackage{subcaption} + +\usepackage{fancyhdr} +\pagestyle{fancy} +\lhead{PHY 905 Project 1} +\rhead{Nicholas Miller} + +% ------------------------------------------------- + +\renewcommand{\arraystretch}{1.25} +\renewcommand{\baselinestretch}{1.0} + +\begin{document} + +\section{Theory} + +\subsection{Ising Model} + +The Ising model is a theoretical approximation of ferromagnetism. It consists of discrete variables which, in our case, represent atomic spins in a two dimensional lattice. These spin variables can take two values, shown in Eqn. (\ref{eq:spins}). +\begin{equation} +s_i = +\left\{ + \begin{array}{ll} + +1, & \text{(spin up)} \\ + -1, & \text{(spin down)} + \end{array} +\right. +\label{eq:spins} +\end{equation} +Since the force between two atoms falls off as $r^{-3}$, the Hamiltonian is written as +\begin{equation} +E = -J\sum\limits_{\langle ij\rangle} s_i s_j - H\sum\limits_i s_i +\end{equation} +where $J=1$ is the interaction strength, $H$ is the magnetic field strength, and $\langle ij\rangle$ denotes summation over nearest neighbors. For the rest of this report, the magnetic field strength will be $H=0$. + +At sufficiently low temperatures, the collection of atoms are permanently magnetized which is called ferromagnetic. At sufficiently high temperatures, the atoms have zero magnetization and the temperature at which the phase transition between these two states is called the Curie Temperature $T_c$. + +\subsection{Monte Carlo and the Metropolis Algorithm} + +The magnetization of a collection of atomic spins are numerically calculated using the Monte Carlo method. This involves choosing a random a subset of atom spins and averaging samples to compute observables. For magnetization, the average value is given by Eqn. (\ref{eq:mag_avg}). +\begin{equation} +\langle M \rangle = \frac{\sum\limits_c M \exp\left(-E/kT\right)}{\sum\limits_c \exp\left(-E/kT\right)} +\label{eq:mag_avg} +\end{equation} +where the summation is over the total number of configurations $c = 2^{N_s}$ with $N_s$ independent spins. For a reasonably small model of $N_s = 484$ (22 lattice points), the number of configurations exceeds the number of atoms in the universe, and most certainly exceeds the memory of the most powerful modern computer. It is for this reason that the Metropolis Algorithm was invented -- to make possible the stochastic computation of the Ising model. + +The Metropolis Algorithm is run for $N_xN_s$ iterations where $N_x$ is an integer: +\begin{itemize} +\item Given a specific configuration, flip a random spin $s_i\rightarrow -s_i$ +\item Compute the change in energy $\Delta E$ + \begin{enumerate} + \item Compute $w = \exp\left(-\Delta E / kT\right)$ + \item If $w \geq 1 (\Delta E \leq 0)$, accept flip + \item else if $w > \left(\text{random number} \in \left[0,1\right]\right)$, accept flip + \item else, reject flip + \end{enumerate} +\end{itemize} +The main observable of the Ising model is the magnetization $M$ given by Eqn. (\ref{eq:magnetization}) which is averaged over the entire set of $N_x N_s$ configurations. +\begin{equation} +M = \sum\limits_i s_i +\label{eq:magnetization} +\end{equation} + +\section{Some Coding Tricks} + +\subsection{Precomputing Boltzmann Factors} + + + +Computing the change in energy $\Delta E$ can be costly, but one way to ease the computational burden is by noticing that it only takes ten different values. Consider the sum of nearest neighbor spins $\sum\limits_{i,nn}s_i$. This summation can only be $\sum\limits_{i,nn}s_i \in \lbrace-4, -2, 0, 2, 4\rbrace$ and multiplying by the $j^\text{th}$ lattice point's spin $s_j$ gives two sets of spins $\sum\limits_{i,nn}s_i$ which are equal and opposite in sign. Therefore the set of ten Boltzmann factors can be precomputed for a given temperature and accessed from memory during the Metropolis loop. + +\subsection{Periodic Boundary Conditions} + +To implement periodic boundary conditions, the edges of the two-dimensional lattice must be connected. For instance, if the energy is computed at the $(i,j) = (1,1)$ site (top left corner), then the $(i-1, j)$ location must be mapped to $(N_i, j)$. This can be accomplished with the modulo function in Python. Given a $N_i \times N_j$ Python array (index starts at 0 in Python), the $(i-1, j)$ location is called as $( (i-1)\%N_i, j)$. When $i \in \left[1, N_i\right]$, $(i-1)\%N_i = i-1$. When $i=0$, however, $(i-1)\%N_i = N_i$ and the end lattice points are mapped together. The same is done for all edges of the lattice. + +\begin{figure}[!h] + \centering + \includegraphics[width=0.8\textwidth]{../results/magnetization_10x10_10k.pdf} + \caption{Magnetization over temperature of a $10\times10$ periodic lattice with a $N_x=10,000$ scale to the number of Metropolis iterations.} + \label{fig:mag10x10} +\end{figure} + +\section{Results} + +For all results, Boltzmann's constant $k_B$ was set to unity. The magnetization of a $10\times10$ periodic lattice with $N_x = 10,000$ is shown in Figure \ref{fig:mag10x10}. In the range of the phase transition ($2 \leq T \leq 2.5$) the average magnetization oscillates rapidly, but the expected behavior of the magnetization is within the error bars given by the standard deviation. + +Figure \ref{fig:mag50x50} displays three configurations at different temperatures. Each configuration is the final after $N_x N_s$ Metropolis steps. The lattice was $50\times50$ in size, and each lattice point is represented by either a black pixel (spin up) or a white pixel (spin down). The lowest temperature configuration displays almost fully spin up, the middle temperature (near the Curie temperature) shows some collections of spins, and the high temperature displays almost fully random spins. This matches what is expected from the Ising model. +\begin{figure}[!h] + \centering + \includegraphics[width=\textwidth]{../results/50x50.pdf} + \caption{Final configuration for three different temperatures.} + \label{fig:mag50x50} +\end{figure} +\end{document} diff --git a/mill1825/results/50x50.pdf b/mill1825/results/50x50.pdf new file mode 100644 index 0000000..8950a21 Binary files /dev/null and b/mill1825/results/50x50.pdf differ diff --git a/mill1825/results/50x50.svg b/mill1825/results/50x50.svg new file mode 100644 index 0000000..0869761 --- /dev/null +++ b/mill1825/results/50x50.svg @@ -0,0 +1,569 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mill1825/results/magnetization_10x10_10k.pdf b/mill1825/results/magnetization_10x10_10k.pdf new file mode 100644 index 0000000..1849f3e Binary files /dev/null and b/mill1825/results/magnetization_10x10_10k.pdf differ diff --git a/mill1825/results/spins_50x50_T1.5.png b/mill1825/results/spins_50x50_T1.5.png new file mode 100644 index 0000000..7d177c0 Binary files /dev/null and b/mill1825/results/spins_50x50_T1.5.png differ diff --git a/mill1825/results/spins_50x50_T2.5.png b/mill1825/results/spins_50x50_T2.5.png new file mode 100644 index 0000000..d2bb8ef Binary files /dev/null and b/mill1825/results/spins_50x50_T2.5.png differ diff --git a/mill1825/results/spins_50x50_T4.0.png b/mill1825/results/spins_50x50_T4.0.png new file mode 100644 index 0000000..c6fde73 Binary files /dev/null and b/mill1825/results/spins_50x50_T4.0.png differ