-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (41 loc) · 1.07 KB
/
main.py
File metadata and controls
61 lines (41 loc) · 1.07 KB
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
"""
This file runs Ising simulation
Created: Mar. 30, 2019
Last Edited: Apr. 6, 2019
By Bill
"""
import IsingGrid
import matplotlib as mpl
import matplotlib.pyplot as plt
from copy import deepcopy
# Fundamental parameters
size = 100
temperature = 1
steps = 400
interval = 100
Jfactor = 0.5
# Generate grid
g = IsingGrid.Grid(size, Jfactor)
g.randomize()
# Animation parameters
fig, ax = plt.subplots()
data = []
# Simulation
print("Simulation begins.")
for step in range(steps):
# Single/cluster Filp
# clusterSize = g.singleFlip(temperature)
clusterSize = g.clusterFlip(temperature)
if (step + 1) % interval == 0:
data.append(deepcopy(g.canvas))
if (step + 1) % (10 * interval) == 0:
print("Step ", step + 1, "/", steps, ", Cluster size ", clusterSize, "/", size * size)
print("Simulation completes.")
# Animation
print("Animation begins.")
for frame in range(0, len(data)):
ax.cla()
ax.imshow(data[frame], cmap=mpl.cm.winter)
ax.set_title("Step {}".format(frame * interval))
plt.pause(0.01)
print("Animation completes.")