Monday 29 January 2018

2D Ising model v1.1.2

This updated version now has accurate figures which match those of the results obtained in Giordano's  book. The simulation has been run twice and the first simulation is represented by the color red and the second simulation is represented by the color blue.
"""
2D Ising model v1.1.2

Modified
Version 1.0: Thu Nov  9 17:34:37 2017
Version 1.1: Sun Jan 21 18:54:34 2018
Version 1.1.1 Mon Jan 22 20:34:28 2018
Version 1.1.2 Mon Jan 29 11:08:00 2018

@author: jameslowe1995

"""
#libraries
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from numpy.random import rand
import numpy

#Adjustable Varibles
H = 2   # Initializng lattice: 1 = all +1s, 2 = all -1s, 3 = random +1s and -1s
Tfinal = 5 #Final temperature
Tinterval = .1 # Intervals between temperature points
T = 1 #Starting temperature
L = 10 #Lattice array L*L
MonteCarloSweeps = 1000 #Monte Carlo Sweeps

#Fixed variables
i = 1
j = 1
r = 0
m = 0
Kb = 1.38064852e-23 #Boltzmanns constant

if H == 1:

    #Initialize lattice all +1s
    lattice = numpy.zeros((L, L))+1

if H == 2:

    #Initialize lattice all -1s
    lattice = numpy.zeros((L, L))-1

if H ==3:
    #Initialize lattice random +1s and -1s
    lattice = 2*np.random.randint(2, size=(L,L))-1

#plot intial lattice           
plt.figure(4,figsize=(10, 10), dpi=80)
X, Y = np.meshgrid(range(L), range(L))
plt.pcolormesh(X, Y, lattice, cmap=plt.cm.RdBu);
plt.xlabel("Initial configuration")

while T <= Tfinal:

    sweeps = 0
    x = 0
    y = 0
    z = 0
    energy = 0
    magnetism =0
    E = 0
    M = 0
    S = 0
    latticetotal = numpy.zeros((L, L))

    while sweeps < MonteCarloSweeps:
      while z == 0:
            if x < (L):
                if y < (L):
                    s =  lattice[x, y]

                    #boundary condition 1
                    if y == 0:
                        if x == 0:
                            Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(L-1)%L,y] + lattice[x,(L-1)%L]               

                    #boundary condition 2
                    if y == 0:
                        if x < L-1:
                            if x != 0:
                                Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y] + lattice[x,(L-1)%L]     

                    #boundary condition 3 
                    if y == 0:
                        if x == L-1:
                            Eflip = lattice[(0)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y] + lattice[x,(L-1)%L] 

                    #boundary condition 4 
                    if y > 0:
                        if x == 0:
                            Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y]+lattice[(L-1)%L,y]

                    #boundary condition 5       
                    if y > 0:
                        if y != L-1:
                            if x == L-1:
                                Eflip = lattice[(x-1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y]+lattice[(0)%L,y]

                    #boundary condition 6
                    if y == L-1:
                        if x == 0:
                            Eflip = lattice[(x+1)%L,y] + lattice[x,(0)%L] + lattice[(L-1)%L,y]+lattice[x,(y-1)%L]

                    #boundary condition 7                     
                    if y == L-1:
                        if x < L-1:
                            if x != 0:
                                Eflip = lattice[(x+1)%L,y] + lattice[x,(0)%L] + lattice[(x-1)%L,y]+ lattice[x,(y-1)%L]                           

                    #boundary condition 8           
                    if y == L-1:
                        if x == L-1:
                            Eflip = lattice[(0)%L,y] + lattice[x,(L-1)%L] + lattice[(x-1)%L,y]+ lattice[x,(y-1)%L]

                    #boundary condition 9                     
                    if y < L-1:
                        if y > 0:
                            if x < L-1:
                                if x > 0:
                                    Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y]+ lattice[x,(y-1)%L]
                           
                    Eflip2 = 2*s*Eflip

                    if Eflip2 < 0:
                        s = s*-1 #flip the value

                    elif rand() < np.exp(-Eflip2*(1/T)):
                        s = s*-1 #flip the value
                 
                lattice[x,y] = s               

                if y <= L-1:
                    x = x + 1

                    if x == L:
                        x = 0
                        y = y + 1

                if y == L:
                    x = 0
                    y = 0
                    sweeps = sweeps + 1                   

                value = lattice[x,y]
                energy += Eflip*(-value)
                magnetism = np.sum(lattice)

                E = E + energy
                E = E/3
                M = M + magnetism
              #  S = S + (magnetism*magnetism)
             


                if sweeps == MonteCarloSweeps:
                    z = 1                   

    E = (E/(MonteCarloSweeps*L*L))
    M = (M/(L*L*MonteCarloSweeps*100)) 
   # S = (((S/(MonteCarloSweeps*L*L)))-((E*E)/(MonteCarloSweeps*L*L)))*(1/T)*(1/T)
 
    print("Energy = ", E, " - magnetism = ",abs(M), " at temperature = ", T)
 
    plot the lattice           
    plt.figure(figsize=(10, 10), dpi=80);
    X, Y = np.meshgrid(range(L), range(L))
    plt.pcolormesh(X, Y, lattice, cmap=plt.cm.RdBu);
    plt.xlabel(T)

    plt.figure(2,figsize=(10, 10))
    plt.ylim([-2,0])
    plt.xlim([0,5])
    plt.plot(T, E, 'ro', )
    plt.xlabel("Temperature",)
    plt.ylabel("Energy per Spin ")
    plt.title("Thermal average of the energy versus temperature")

    plt.figure(3,figsize=(10, 10))
    plt.ylim([-0.1,1.1])
    plt.xlim([0,5])
    #plt.plot([0,0], [0,6], 'k-', lw=2)
    plt.plot(T, abs(M), 'bo')
    plt.xlabel("Temperature")
    plt.ylabel("Magnetization ")
    plt.title("Spontaneous magnetization as a function of temperature")

    plt.figure(8,figsize=(10, 10))
    plt.plot(T, S, 'ro', )
    plt.xlabel("",)
    plt.ylabel(" ")
    plt.title("")

    T = T + Tinterval





Monday 22 January 2018

2D Ising model v1.1.1

This updated version now has an accurate Y-axis scale on magnetism and Energy graphs. A 10x10 lattice is simulated as to compare with the graphs from Giordano s book. The temperature interval is set to .1 as to achieve a quick simulation.

"""
2D Ising model v1.1.1

Modified
Version 1.0: Thu Nov  9 17:34:37 2017
Version 1.1: Sun Jan 21 18:54:34 2018
Version 1.1.1 Mon Jan 22 20:34:28 2018

@author: jameslowe1995

"""
#libraries
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from random import randint
from numpy.random import rand
import numpy

#Adjustable Varibles
H = 2   # Initializng lattice: 1 = all +1s, 2 = all -1s, 3 = random +1s and -1s
Tfinal = 4 #Final temperature
Tinterval = .1 # Intervals between temperature points
T = 1 #Starting temperature
L = 10 #Lattice array L*L
MonteCarloSweeps = 1000 #Monte Carlo Sweeps

#Fixed variables
i = 1
j = 1
r = 0
m = 0
Kb = 1.38064852e-23 #Boltzmanns constant

if H == 1:

    #Initialize lattice all +1s
    lattice = numpy.zeros((L, L))+1

if H == 2:

    #Initialize lattice all -1s
    lattice = numpy.zeros((L, L))-1

if H ==3:
    #Initialize lattice random +1s and -1s
    lattice = 2*np.random.randint(2, size=(L,L))-1

#plot intial lattice           
plt.figure(4,figsize=(10, 10), dpi=80)
X, Y = np.meshgrid(range(L), range(L))
plt.pcolormesh(X, Y, lattice, cmap=plt.cm.RdBu);
plt.xlabel("Initial configuration")

while T <= Tfinal:

    sweeps = 0
    x = 0
    y = 0
    z = 0
    energy = 0
    magnetism =0
    E = 0
    M = 0
    latticetotal = numpy.zeros((L, L))

    while sweeps < MonteCarloSweeps:
      while z == 0:
            if x < (L):
                if y < (L):
                    s =  lattice[x, y]

                    #boundary condition 1
                    if y == 0:
                        if x == 0:
                            Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(L-1)%L,y] + lattice[x,(L-1)%L]               

                    #boundary condition 2
                    if y == 0:
                        if x < L-1:
                            if x != 0:
                                Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y] + lattice[x,(L-1)%L]     

                    #boundary condition 3 
                    if y == 0:
                        if x == L-1:
                            Eflip = lattice[(0)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y] + lattice[x,(L-1)%L] 

                    #boundary condition 4 
                    if y > 0:
                        if x == 0:
                            Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y]+lattice[(L-1)%L,y]

                    #boundary condition 5       
                    if y > 0:
                        if y != L-1:
                            if x == L-1:
                                Eflip = lattice[(x-1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y]+lattice[(0)%L,y]

                    #boundary condition 6
                    if y == L-1:
                        if x == 0:
                            Eflip = lattice[(x+1)%L,y] + lattice[x,(0)%L] + lattice[(L-1)%L,y]+lattice[x,(y-1)%L]

                    #boundary condition 7                     
                    if y == L-1:
                        if x < L-1:
                            if x != 0:
                                Eflip = lattice[(x+1)%L,y] + lattice[x,(0)%L] + lattice[(x-1)%L,y]+ lattice[x,(y-1)%L]                           

                    #boundary condition 8           
                    if y == L-1:
                        if x == L-1:
                            Eflip = lattice[(0)%L,y] + lattice[x,(L-1)%L] + lattice[(x-1)%L,y]+ lattice[x,(y-1)%L]

                    #boundary condition 9                     
                    if y < L-1:
                        if y > 0:
                            if x < L-1:
                                if x > 0:
                                    Eflip = lattice[(x+1)%L,y] + lattice[x,(y+1)%L] + lattice[(x-1)%L,y]+ lattice[x,(y-1)%L]
                           
                    Eflip2 = 2*s*Eflip

                    if Eflip2 < 0:
                        s = s*-1 #flip the value

                    elif rand() < np.exp(-Eflip2*(1/T)):
                        s = s*-1 #flip the value
                 
                lattice[x,y] = s               

                if y <= L-1:
                    x = x + 1

                    if x == L:
                        x = 0
                        y = y + 1

                if y == L:
                    x = 0
                    y = 0
                    sweeps = sweeps + 1                   

                value = lattice[x,y]
                energy += Eflip*(-value)
                magnetism = np.sum(lattice)

                E = E + energy
                E = E/4
                M = M + magnetism
             


                if sweeps == MonteCarloSweeps:
                    z = 1                   

    E = (E/(MonteCarloSweeps*L*L))
    M = (M/(L*L*MonteCarloSweeps*100))     
 
    print("Energy = ", E, " - magnetism = ",abs(M), " at temperature = ", T)
 
    #plot the lattice           
    plt.figure(figsize=(10, 10), dpi=80);
    X, Y = np.meshgrid(range(L), range(L))
    plt.pcolormesh(X, Y, lattice, cmap=plt.cm.RdBu);
    plt.xlabel(T)

    plt.figure(2,figsize=(15, 10))
    plt.plot(T, E, 'ro', )
    plt.xlabel("Temperature (T)",)
    plt.ylabel("Energy ")

    plt.figure(3,figsize=(15, 10))
    plt.plot(T, abs(M), 'bo')
    plt.xlabel("Temperature (T)")
    plt.ylabel("Magnetization ")

    T = T + Tinterval







On a side note by setting the Monte Carlo sweeps to 1 it is possible to see the relationship between each temperature point. Below is a 100x100 lattice with a temperature interval of 0.1 





Supervisor Meeting outcome 22/01/2018

Objectives from meeting:

  • Adjust y axis resolution of 2D model so that the energy and magnetism values match those from Giordanos book. 
  • Write up what has been achieved thus far for interim report 
  • Purchase Ethernet switch online for cluster
  • Time permitting reproduce Landaus 1D ising model   
  •  Application for ICHEC - Proposal and Abstract now required can be taken from interim report.
  • Look into summer of HPC (closing date).

Thursday 18 January 2018

Supervisor Meeting outcome 18/01/2018

After a brief hiatus due to exams a meeting was held with my project supervisor to discuss the next steps of the project to be completed for Monday 22/01/2017. These outcomes include:

  • Simulation of a 1D Ising model from the book computational physics (Landau).
  • Once this is working, integrate the working code with the existing 2D model I had produced before Christmas.
  • Write up a grant application to the Irish Centre for High-End computing for the use of their supercomputer.
On a side note the PCs for the Beowulf cluster are now in my possession and i will begin to slowly piece the cluster together over time. The main focus of the project as it stands will be the operation of the model.

Monday 1 January 2018

References


[1] N.J. Giordano. “Statistical Mechanics, Phase Transitions and the Ising Model” in Computational Physics, 1st ed., Alison Reeves, Ed. New Jersey: Pretence Hall 1997, pp.204-231.

[2] IEEE-CS/ACM Joint Task Force - Software Engineering Ethics and Professional Practices, [online] Available: https://www.computer.org/web/education/code-of-ethics

[3] The Institution of Engineers of Ireland. - Code of Ethics, [online] Available: http://www.engineersireland.ie/about/code-of-ethics-and-bye-laws.aspx

[4] J. Block, P. Virnau and T. Preis, “Multi-GPU accelerated multi-spin Monte Carlo simulations of the 2D Ising model”, Computer Physics Communications, Volume 181, Issue 9, pp. 1549-1556, Sep 2010.

[5] A. Züleyha, M. Ziya, Y. Selçuk, Ö.M. Kemal and T. Mesut, “Simulation of glioblastoma multiforme (GBM) tumor cells using ising model on the Creutz Cellular Automaton” Physica A: Statistical Mechanics and its Applications, Volume 486, pp 901-907, Mar 2017.

[6] S.D. Mostovoy, O.V. Pavlovsky, “Critical Casimir effects in 2D Ising model with curved defect lines”, Physics Letters A, Volume 382, Issue 5, pp 276-282, 2018.

 [7] D. Ridge, D. Becker, P. Merkey and T. Sterling, "Beowulf: harnessing the power of parallelism in a pile-of-PCs," 1997 IEEE Aerospace Conference, Snowmass at Aspen, CO, 1997, pp. 79-91 vol.2.

[8] S. Sampath, B. B. Sagar and B. R. Nanjesh, "Performance evaluation and comparison of MPI and PVM using a cluster based parallel computing architecture," 2013 International Conference on Circuits, Power and Computing Technologies (ICCPCT), Nagercoil, 2013, pp. 1253-1258.