-
Notifications
You must be signed in to change notification settings - Fork 9
/
simulation.py
75 lines (57 loc) · 2.03 KB
/
simulation.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
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 21 16:25:29 2019
@author: Jonathan Frassineti
"""
import ising
import numpy as np
import sys
from sys import argv
import configparser
#main part of the code
config = configparser.ConfigParser()
config.read(sys.argv[1])
N = config.get('settings', 'N')
M = config.get('settings', 'M')
numberTemp = config.get('settings', 'numberTemp')
startTemp = config.get('settings', 'startTemp')
endTemp = config.get('settings', 'endTemp')
eqSteps = config.get('settings', 'eqSteps')
lattice_T = config.get('settings', 'latticeTemp')
destination1 = config.get('paths','my_time')
destination2 = config.get('paths','my_ene')
destination3 = config.get('paths','my_mag')
N = int(N)
M = int(M)
numberTemp = int(numberTemp)
startTemp = float(startTemp)
endTemp = float(endTemp)
lattice_T = float(lattice_T)
eqSteps = int(eqSteps)
T = np.linspace(startTemp,endTemp,numberTemp)
Energy = np.zeros(numberTemp)
Magn = np.zeros(numberTemp)
inverseTemp = 1.0/T
n1 = 1.0/(eqSteps*N*M)
for tempInterval in range(numberTemp):
print("Temperature point: {}/{}".format(tempInterval,numberTemp))
config = ising.initialstate(N,M)
Energy1 = Magn1 = 0
for i in range(eqSteps):
ising.montmove(config,inverseTemp[tempInterval])
for i in range(eqSteps):
ising.montmove(config,inverseTemp[tempInterval])
Energy2 = ising.calculateEnergy(config) # calculate the energy
Magn2 = ising.calculateMagn(config) # calculate the magnetisation
Energy1 += Energy2
Magn1 += Magn2
Energy[tempInterval] = n1*Energy1
Magn[tempInterval] = n1*Magn1
print("Simulation done!")
np.save(destination2,Energy)
np.save(destination3,Magn)
print("Energies and magnetization saved.")
print("Now, simulate the system in the ordered phase along time.")
totalStates = ising.simulate(ising.initialstate(N,M),lattice_T)
np.save(destination1,np.asarray(totalStates))
print("Simulation saved.")