-
Notifications
You must be signed in to change notification settings - Fork 0
/
htscan.py
204 lines (165 loc) · 5.96 KB
/
htscan.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"""A program to scan a grid in H-T space, using annealing in the T direction"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from os import system, path
from tscan import binning
Tc = 0.702
dH = 0.01 # The variation of H used to compute the derivative
Hs_mean = np.linspace(1, 50, 4)
# reduced_Ts = np.logspace(-6, 0)
# Ts = Tc * (1 + reduced_Ts)
Ts = np.linspace(0.5, 3, 100)
reduced_Ts = (Ts - Tc) / Tc
# Add intermediate values of H for differentiation
dxs = np.array([[-0.5, 0.5]]).repeat(len(Hs_mean), axis=0)
Hs = np.column_stack([Hs_mean, Hs_mean]) + dxs * dH
Hs = Hs.reshape((-1,))
cfgfile = "config/scan.in"
outdir = "data/scanHT/"
def make_filename(H, T):
return outdir + "scan_{}_{}.out".format(H, T)
def run_sim():
statefile = outdir + "annealing.state"
for H in Hs:
firstpass=True
for T in Ts:
f = make_filename(H, T)
if firstpass: # Do not load from the state file
system("./sim {} \"filename={}\" \"temperature={}\" \"H=(0 0 {})\" \"outstate={}\""
.format(cfgfile, f, T, H, statefile))
firstpass = False
if path.exists(f):
print("Skipped H={}, T={}".format(H, T))
else:
system("./sim {} \"filename={}\" \"temperature={}\" \"H=(0 0 {})\" \"outstate={}\" \"instate={}\" \"Nthermal=100\" "
.format(cfgfile, f, T, H, statefile, statefile))
def rescale(s, H, epsilon):
# critical exponents and temperature (theoretical ones)
beta = 0.365
gamma = 1.39
delta = 4.8
x = epsilon ** (gamma + beta) / H
y = s * (1 - 1 / delta)
return x, y
def susceptibility_from_fluctuation():
kiss = np.zeros((len(Hs), len(Ts)))
for i, H in enumerate(Hs):
for j, T in enumerate(Ts):
data = np.loadtxt(make_filename(H, T))
Mz = np.mean(data[:, -1])
kiss[i, j] = 1 / T * (np.mean(Mz * Mz) - np.mean(Mz) ** 2)# we assumed kb = 1
return kiss
def load_Mz():
Mzss = np.zeros((len(Hs), len(Ts)))
errs = np.zeros((len(Hs), len(Ts)))
for i, H in enumerate(Hs):
for j, T in enumerate(Ts):
data = np.loadtxt(make_filename(H, T))
Mzss[i, j], errs[i, j] = np.mean(data[:, -1]), np.std(data[:, -1])
return Mzss, errs
def fluct_vs_diff():
# Get the fluctuation susceptibility
ki_fluct = susceptibility_from_fluctuation()
ki_fluct = (ki_fluct[::2] + ki_fluct[1::2]) / 2
# Get the susceptibility from differentiation
Mzss, errs = load_Mz()
ki_diff = (Mzss[1::2] - Mzss[::2]) / dH
# First with one
plt.figure()
plt.scatter(Ts, ki_fluct[0], label="Fluctuation susceptibility")
plt.errorbar(Ts, ki_diff[0], errs[0], label="Differentation susceptibility", fmt=".")
print(ki_diff[0], ki_diff[-1])
plt.legend()
plt.xlabel("T")
plt.ylabel("χ")
# Then with all
plt.figure()
for i, H in enumerate(Hs_mean):
# plt.scatter(Ts, ki_fluct[0], label="Fluctuation susceptibility - {:.2}".format(H))
plt.plot(Ts, ki_diff[i], label="Differentation susceptibility - {:.2}".format(H))
plt.legend()
plt.xlabel("T")
plt.ylabel("χ")
# Then normalized version
plt.figure()
for i, H in enumerate(Hs_mean):
# plt.scatter(Ts, ki_fluct[0], label="Fluctuation susceptibility - {:.2}".format(H))
x, y = rescale(ki_diff[i], H, reduced_Ts)
plt.scatter(x, y, label="Differentation susceptibility - {:.2}".format(H))
plt.xscale('log')
plt.legend()
plt.xlabel("")
plt.ylabel("")
plt.show()
def analysis():
shape = (len(Hs), len(Ts))
Harr = np.zeros(shape)
Tarr = np.zeros(shape)
Marr = np.zeros(shape)
susc_fluct = np.zeros(shape)
for i, H in enumerate(Hs):
for j, T in enumerate(Ts):
data = np.loadtxt(make_filename(H, T))
Mz = np.mean(data[:, -1])
Harr[i, j] = H
Tarr[i, j] = T
Marr[i, j] = Mz
if not T == 0:
M = data[:, -1]
susc_fluct[i, j] = (np.mean(M * M) - np.mean(M) ** 2) / T # we assumed kb = 1
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_wireframe(Harr, Tarr, Marr, color='green')
ax.set_xlabel('H')
ax.set_ylabel('T')
ax.set_zlabel('M_z per site')
# We want to show every plot at once
plt.figure()
for H in Hs:
Mzs = []
for T in Ts:
data = np.loadtxt(make_filename(H, T))
Mzs.append(np.mean(data[:, -1]))
plt.plot(Ts, np.array(Mzs), label="H={}".format(H))
plt.xlabel("T []")
plt.ylabel("Mz per site []")
# We want to compute the susceptibility, i.e. the derivative of M
# wrt H
Hdiff = np.diff(Harr, axis=0)
susc = np.diff(Marr, axis=0) / Hdiff
Harr_half = (Harr[:-1, :] + Harr[1:, :]) / 2
Tarr_half = (Tarr[:-1, :] + Tarr[1:, :]) / 2
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_wireframe(Harr_half, Tarr_half, susc, color='green')
ax.set_xlabel('H')
ax.set_ylabel('T')
ax.set_zlabel('susceptibility per site')
plt.figure()
for H, T, s in zip((Hs[:-1] + Hs[1:]) / 2, Tarr_half, susc):
plt.plot(T, s, label="H={:.2}".format(H))
plt.xlabel("T []")
plt.ylabel("dm/dH []")
plt.legend()
plt.figure()
for H, T, s in zip(Hs, Tarr, susc_fluct):
plt.plot(T, s, label="H={:.2}".format(H))
plt.xlabel("T []")
plt.ylabel("dm/dH []")
plt.legend()
plt.figure()
for H, T, s in zip((Hs[:-1] + Hs[1:]) / 2, Tarr_half, susc):
x, y = rescale(s, H, T)
plt.plot(x, y, label="H={:.2}".format(H))
plt.xlabel("εˠ⁺ᵝ/H")
plt.ylabel("χ/H^(1/̣δ-1)")
plt.legend()
plt.figure()
for H, T, s in zip(Hs, Tarr, susc_fluct):
x, y = rescale(s, H, T)
plt.plot(x, y, label="H={:.2}".format(H))
plt.xlabel("εˠ⁺ᵝ/H")
plt.ylabel("χ/H^(1/̣δ-1)")
plt.legend()
plt.show()