-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_mag.py
71 lines (55 loc) · 1.95 KB
/
plot_mag.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
import numpy as np
import matplotlib.pyplot as plot
N = 400 #no. of spins
x = np.linspace(0.1, 4, 64)
Tc = 2/np.log(1+np.sqrt(2)) #which is nearly equals to 2.269
Mean_Collect = []
Std_Collect = []
for temp in x:
with open("Data/Mag/Temp_%s.csv" %temp, "r") as infile:
Data = infile.readlines()
Abs_Data = np.array([abs(float(x)) for x in Data[2:]])
MPS = np.mean(Abs_Data/N) # <|Magnetization|> per spin
STDPS = np.std(Abs_Data[2:]/N) # standard deviation per spin
Mean_Collect.append(MPS)
Std_Collect.append(STDPS)
#Mean field
MF = []
s = 1
for temp in x:
for _ in range(1000):
s = np.tanh(Tc/temp * s)
MF.append(s)
#Coding for Osager Solution's for Finding Curie Temperature.
OM = [] #Osager's Magnetization
for temp in x:
if float(temp) < Tc:
O =(1-(np.sinh(np.log(1+np.sqrt(2))*(Tc/temp)))**(-4))**(1/8)
OM.append(O)
elif float(temp) > Tc:
O = 0
OM.append(O)
f1 = plot.figure()
plot.plot(x/Tc,MF, color = "darkblue", marker = "*", label = "Mean Field Approximation")
plot.grid()
plot.title("Absolute Magnetization Mean Field Approximation")
plot.legend(loc = "best")
plot.xlabel("Reduced Temperature T/Tc")
plot.ylabel("Absolute Magnetization per spin")
plot.savefig('./figures/Magplot_mf.png')
f2 = plot.figure()
plot.plot(x/Tc, OM, color = "salmon", marker = "*", label = "Onsager's formula")
plot.grid()
plot.title("Absolute Magnetization Onsager's formula")
plot.legend(loc = "best")
plot.xlabel("Reduced Temperature T/Tc")
plot.ylabel("Absolute Magnetization per spin")
plot.savefig('./figures/Magplot_om.png')
f3 = plot.figure()
plot.errorbar(x/Tc,Mean_Collect, yerr = Std_Collect, color= "forestgreen", fmt = "o", label = "Simulation Data")
plot.grid()
plot.title("Absolute Magnetization Simulation")
plot.legend(loc = "best")
plot.xlabel("Reduced Temperature T/Tc")
plot.ylabel("Absolute Magnetization per spin")
plot.savefig('./figures/Magplot_sim.png')