-
Notifications
You must be signed in to change notification settings - Fork 1
/
Observables_functions.py
108 lines (89 loc) · 2.78 KB
/
Observables_functions.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
import numpy as np
from numba import jit
@jit(nopython=True)
def get_magnetisation_squared(lattice):
"""
Calculates and returns the magnetisation squared sum over the lattice.
Parameters
----------
lattice: np.ndarray (float)
The input lattice containing L×L spins.
Returns
-------
M2: float
Magnetisation squared sum over the lattice.
"""
M2 = np.sum(np.cos(lattice))**2 + np.sum(np.sin(lattice))**2
return M2
@jit(nopython=True)
def get_energy(J, L, lattice):
"""
Calculates and returns the energy sum over the lattice.
Parameters
----------
J: float
Coupling constant. It must follow that J>0 such that we are studying the ferromagnetic XY-model.
L: int
Lattice size where the total number of spins is given by L×L.
lattice: np.ndarray (float)
The input lattice containing L×L spins.
Returns
-------
E: float
Energy sum over the lattice.
"""
a = np.arange(0, L, 1, dtype=np.int32)
e_right = np.cos(lattice - lattice[:, a - 1])
e_left = np.cos(lattice - lattice[:, a - (L - 1)])
e_down = np.cos(lattice - lattice[a - 1, :])
e_up = np.cos(lattice - lattice[a - (L - 1), :])
e = -J/2 * (e_right + e_left + e_down + e_up)
E = np.sum(e)
return E
def get_energy_per_spin_per_lattice(J, lattice):
"""
Calculates and returns the energy of each spin in the lattice.
Parameters
----------
J: float
Coupling constant. It must follow that J>0 such that we are studying the ferromagnetic XY-model.
lattice: np.ndarray (float)
The input lattice containing L×L spins.
Returns
-------
E: np.ndarray (float)
Energy of each spin in the lattice.
"""
E = -J * (np.cos(lattice - np.roll(lattice, 1, axis=0)) +
np.cos(lattice - np.roll(lattice, -1, axis=0)) +
np.cos(lattice - np.roll(lattice, 1, axis=1)) +
np.cos(lattice - np.roll(lattice, -1, axis=1)))
return E
def vorticity(lattice):
"""
Calculates the vorticity of a given lattice.
Parameters
----------
lattice: np.ndarray (float)
The input lattice containing L×L spins.
Returns
-------
vorticity: float
The normalised vorticity of a given lattice.
"""
def fix_pi(lattice):
"""
Makes sure that the angle range is only from -pi to pi.
"""
lattice[lattice>np.pi] = lattice[lattice>np.pi]%(-np.pi)
lattice[lattice<=-np.pi] = lattice[lattice<=-np.pi]%(np.pi)
return lattice
l = np.roll(lattice,1,axis=1)
ld = np.roll(np.roll(lattice,1,axis=1),1,axis=0)
d = np.roll(lattice,1,axis=0)
s1 = fix_pi(lattice - l)
s2 = fix_pi(l - ld)
s3 = fix_pi(ld - d)
s4 = fix_pi(d - lattice)
vorticity = np.abs((np.sum(s1+s2+s3+s4)))
return vorticity