-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswendsen-wang-percolation-T-ana-topo.py
207 lines (150 loc) · 5.94 KB
/
swendsen-wang-percolation-T-ana-topo.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
205
206
207
import numpy as np
import random
import numba
from numba import jit , prange , config, njit, threading_layer
from functions import initgrid
from functions import critical
from functions import fill_bonds_identify_clusters
from functions import check_percolation_nonperiodic
from functions import fill_bonds_identify_clusters_check_periodic_perco
from functions import decision
from scipy.signal import savgol_filter
import scipy
from numpy import savetxt
from math import exp
from scipy.stats import norm
import time
start_time = time.time()
from math import log
from uncertainties import ufloat
from uncertainties import unumpy
from scipy.optimize import curve_fit
import uncertainties.umath as umath
import matplotlib.pyplot as plt
import time
start_time = time.time()
@jit(nopython=True,cache = False ,locals={'p_start_x': numba.float64 , 'p_start_y': numba.float64, 'p_start_d': numba.float64, 'T': numba.float64} , fastmath = True)
def swendsen_wang_chain_magnetisation2(grid,J_x , J_y , J_d , p_start , delta_p,res, periodic = True):
T = -2*J_x * 1/(log(1-p_start))
p_start_x = p_start
p_start_y = 1 - exp(-2*(1/T)* J_y)
p_start_d = 1 - exp(-2*(1/T)* J_d)
T_values = [0.]
percolated_1 = False
label, label_ids, percolated_2= fill_bonds_identify_clusters_check_periodic_perco(p_start_x, p_start_y, p_start_d, grid)
grid_flipped = 1 - grid
if percolated_2 == False:
label_flipped, label_ids_flipped, percolated_1 = fill_bonds_identify_clusters_check_periodic_perco(p_start_x, p_start_y, p_start_d, grid_flipped)
else:
label_flipped, label_ids_flipped = fill_bonds_identify_clusters(p_start_x, p_start_y, p_start_d, grid_flipped, True)
for steps in range(0,res):
if (percolated_2 == True) or (percolated_1 == True):
p_start_x = p_start_x - delta_p
else:
p_start_x = p_start_x + delta_p
if p_start_x >= 1:
p_start_x = 1
elif p_start_x <= 0:
p_start_x = 0
else:
pass
for id_1 in label_ids:
if decision(0.5):
for xx in range(0, len(grid)):
for yy in range(0, len(grid)):
if label[yy][xx] == id_1:
grid[yy][xx] = 1 - grid[yy][xx]
else:
pass
for id_2 in label_ids_flipped:
if decision(0.5):
for xx in range(0, len(grid)):
for yy in range(0, len(grid)):
if label_flipped[yy][xx] == id_2:
grid[yy][xx] = 1 - grid[yy][xx]
else:
pass
T = -2*J_x * 1/(log(1-p_start_x))
p_start_y = 1 - exp(-2 * (1 / T) * J_y)
p_start_d = 1 - exp(-2 * (1 / T) * J_d)
percolated_1 = False
label, label_ids, percolated_2 = fill_bonds_identify_clusters_check_periodic_perco(p_start_x, p_start_y,
p_start_d, grid)
grid_flipped = 1 - grid
if percolated_2 == False:
label_flipped, label_ids_flipped, percolated_1 = fill_bonds_identify_clusters_check_periodic_perco(
p_start_x, p_start_y, p_start_d, grid_flipped)
else:
label_flipped, label_ids_flipped = fill_bonds_identify_clusters(p_start_x, p_start_y, p_start_d,
grid_flipped, True)
T_values.append(T)
#print(steps)
#T_c =-2 / np.log(1 - p_start_x)
return p_start_x , T_values[1:] , grid
@jit(nopython=True )
def data_gen(N, J_x , J_y , J_d, steps):
grid = initgrid(N,0.5)
#a = 0.
a,b , grid= swendsen_wang_chain_magnetisation2(grid,J_x , J_y , J_d,0.5,0.001,10000, periodic = True)
a,b ,grid = swendsen_wang_chain_magnetisation2(grid,J_x , J_y , J_d,a,1/(20*(N**2)),steps, periodic = True)
return b
@jit(nopython=True, parallel = True , fastmath = True)
def data_gen2(N , J_x , J_y , J_d):
probs = [0.] * len(N)
err_probs = [0.] * len(N)
for i in range(0,len(N)):
probs_temp = [0.] * 10
probs_merged = np.array([0.])
probs_merged = probs_merged[1:]
for j in prange(0,10):
b = data_gen(N[i],J_x , J_y , J_d, 100000)
b = np.asarray(b)
p = 1 - np.exp(-2*(1/b)*J_x)
probs_temp[j] = np.mean(p)
#plt.hist(p,1000)
#plt.show()
probs[i] = np.mean(np.asarray(probs_temp))
print(probs[i])
err_probs[i] = np.std(np.asarray(probs_temp))/np.sqrt(float(len(probs_temp)))
print(err_probs[i])
print(i)
return probs , err_probs
#N = np.asarray([20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120])
#N = np.asarray([10,20,30,40,50,60,70,80,90,100])
#N = np.asarray([80])
N = np.asarray([64])
#N = np.asarray([64])
J_x = 1
J_y = 1/2
J_d = 0
#numba.set_num_threads(4)
probs , probs_err = data_gen2(N , J_x , J_y , J_d)
T = []
T_err = []
T2 = []
T_err2 = []
for i in range(0,len(probs)):
p = ufloat(probs[i] , probs_err[i])
T_dist = -2*J_x/umath.log(1-p)
print(T_dist)
#n,bins,patches = plt.hist(T_dist, 1000,align='mid')
#plt.show()
#plt.cla()
#n,bins,patches = plt.hist(p, 1000,align='mid')
#plt.show()
#plt.cla()
#print(len(p),'asdasd')
#print(p_mean_std)
#print(T_mu)
#print(1/critical(J_x,J_y,J_d))
#T.append(-2*J_x/np.log(1-np.mean(p)))
T.append(T_dist.nominal_value)
T_err.append(T_dist.std_dev )
T2.append(T_dist.nominal_value)
T_err2.append(T_dist.std_dev)
print(T)
print(T_err)
#np.savetxt("./data/temps" + str(J_x)+ str(J_y)+str(J_d)+str(N)+ ".csv",T , delimiter= ',')
#np.savetxt("./data/tempserr + " + str(J_x)+ str(J_y)+str(J_d)+ str(N)+".csv",T_err , delimiter= ',')
#np.savetxt("./data/systemsizes + " + str(J_x)+ str(J_y)+str(J_d)+".csv",N , delimiter= ',')
print("--- %s seconds ---" % (time.time() - start_time))