-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinder.py
executable file
·91 lines (57 loc) · 2.21 KB
/
Binder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
from __future__ import division #necessary to perform division of ints effectively cast into floats before division
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as rand
import IsingClass #module written to carry out the required calculations (metropolis, neighbours, energy, magnetization, etc.)
def main():
steps = 3000 #steps for equilibrium
temp_steps = 20 #step size for increase in temperature [J/k]
kT = np.linspace(1.0,4.0,temp_steps) #temperature values
#arrays for future plotting
magnetization = np.zeros(temp_steps)
mag_square = np.zeros(temp_steps)
mag_four = np.zeros(temp_steps)
binder = np.zeros(temp_steps)
for l in range(len(kT)):
temperature = kT[l]
#initialise observables to zero
M = 0
M_sq = 0
M_fth = 0
#reset to random initial configuration
lattice = model.spin_config()
#set out to reach equilibrium
for t in range(steps):
model.metropolis(lattice, temperature)
#collect statistics
stat_steps = int(steps/2)
for k in range(stat_steps):
model.metropolis(lattice, temperature)
mag = model.mag_per_spin_b(lattice)
M += mag
M_sq += mag**2
M_fth += mag**4
#observables, after equilibrium is achieved, normalised by sweeps
magnetization[l] = abs(M)/stat_steps
mag_square[l] = M_sq/stat_steps
mag_four[l] = M_fth/stat_steps
for l in range(len(kT)):
binder[l] = 1 - mag_four[l]/(3*(mag_square[l]**2))
plt.plot(kT, binder, label = "N = %d"%N)
plt.legend(loc = "best")
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.title("Binder cumulant $U_4$ versus temperature")
plt.xlabel("$T$ $[J/k_B]$")
plt.ylabel("$U_4$")
plt.axvline(2.269, color ='r',linestyle='dashed', label="$T_c^{theory} = 2.269$ $[J/k_B]$")
plt.legend()
plt.grid()
N_vals = [8, 10, 25, 32, 50, 64] #side sizes
J = 1.0 #coupling in the hamiltonian
h = 0.0 #external field
for N in N_vals:
model = IsingClass.Ising(N,J,h) #constructor
main()
plt.show()