-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinitialisation.py
138 lines (104 loc) · 4.37 KB
/
initialisation.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
import numpy as np
import numpy.random as rnd
from sys import exit
# -----------------------------------------------------------------------------------------------------------------------
# Input parameter checks
# -----------------------------------------------------------------------------------------------------------------------
def input_check(self):
'''This function check the input values for certain errors,
and exits the program with a error message.
Parameters
----------
self : NameSpace
contains all the simulation parameters
'''
if self.eq_data_points > self.MC_steps:
exit("More equilibrium data points then data points were selected.")
if self.T + self.dT * self.T_steps < 0:
exit("Selected T, T_steps and dT such that the temperature stays positive.")
if self.algorithm == 'SW' and (self.h != 0 or self.dh != 0):
exit("For SW the magnetic field should be zero.")
if self.algorithm == 'SW' and self.L > 40:
exit("This cluster size will exceed recursion depth for the backtrack algorithm.")
if self.algorithm != 'SW' and self.algorithm != 'SF':
exit("This is no valid algorithm: please select SF or SW.")
if self.T_steps%1 != 0:
exit("Temperature steps should be an integer.")
# -----------------------------------------------------------------------------------------------------------------------
# Initialisation functions
# -----------------------------------------------------------------------------------------------------------------------
def assign_spin(self):
'''Initialises the spin states in the system
Parameters
----------
self : NameSpace
contains all the simulation parameters
Returns
-------
grid_spins : 2D array (L, L)
containing al the spin values within the grid
'''
if self.spin_init == 'random':
grid_spins = rnd.rand(self.L, self.L)
grid_spins[grid_spins >= 0.5] = 1
grid_spins[grid_spins < 0.5] = -1
elif self.spin_init == 'up':
grid_spins = np.ones([self.L,self.L], dtype= int)
elif self.spin_init == 'down':
grid_spins = -1*np.ones([self.L,self.L], dtype= int)
return grid_spins
def grid_init(self):
'''Initialises the grid
Parameters
----------
self : NameSpace
contains all the simulation parameters
Returns
-------
grid_coordinates : mesh
conains all combinations of the x and y coordinates of the spins
spin_site_numbers : range (spin_site_total_number)
containing integer counters up to size of spin_site_total_number
'''
grid_x, grid_y = [range(self.L), range(self.L)]
grid_coordinates = np.meshgrid(grid_x, grid_y)
grid_coordinates = np.reshape(grid_coordinates,(2,-1))
spin_site_numbers = range(self.spin_site_total_number)
return grid_coordinates, spin_site_numbers
def matrix_init(self):
'''Initialises several parameter arrays
Parameters
----------
self : NameSpace
contains all the simulation parameters
Returns
-------
T_total : 2D array (T_steps, 1)
initialised temperature array
h_total : 2D array (T_steps, 1)
initialised magnetic field array
energy : 2D array (T_steps, 2)
initialised energy array
chi : 2D array (T_steps, 2)
initialised susceptibility array
c_v : 2D array (T_steps, 2)
initialised specific eat array
magnetisation : 2D array (T_steps, 2)
initialised magnetisation array
energy_i : 2D array (MC_steps, 1)
initialised energy_i array
magnetisation_i : 2D array (MC_steps, 1)
initialised magnetisation_i array
chi_i : 2D array (MC_steps, 1)
initialised susceptibility_i array
'''
T_total = np.zeros([self.T_steps, 1])
h_total = np.zeros([self.T_steps, 1])
energy = np.zeros([self.T_steps, 1])
magnetisation = np.zeros([self.T_steps, 2])
chi = np.zeros([self.T_steps, 2])
c_v = np.zeros([self.T_steps, 2])
energy_i = np.zeros([self.MC_steps, 1])
magnetisation_i = np.zeros([self.MC_steps, 1])
chi_i = np.zeros([self.MC_steps, 1])
return T_total, h_total, energy, chi, c_v, magnetisation, energy_i, magnetisation_i, chi_i