Cluster ising.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 21:32, 22 September 2015 Werner (Talk | contribs) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | This page presents the Python3 program cluster_ising.py, the Wolff cluster algorithm for the Ising model on an LxL square lattice in two dimensions | ||
| + | |||
| + | __FORCETOC__ | ||
| + | =Description= | ||
| + | |||
| + | =Program= | ||
| + | |||
| + | |||
| import random, math | import random, math | ||
| Line 23: | Line 31: | ||
| for j in Cluster: | for j in Cluster: | ||
| S[j] *= -1 | S[j] *= -1 | ||
| + | |||
| + | =Version= | ||
| + | See history for version information. | ||
| + | |||
| + | [[Category:Python]] [[Category:Oxford_2024]] [[Category:MOOC_SMAC]] | ||
Current revision
This page presents the Python3 program cluster_ising.py, the Wolff cluster algorithm for the Ising model on an LxL square lattice in two dimensions
Contents |
[edit]
Description
[edit]
Program
import random, math
L = 100
N = L * L
nbr = {i : ((i // L) * L + (i + 1) % L, (i + L) % N,
(i // L) * L + (i - 1) % L, (i - L) % N)
for i in range(N)}
T = 2.5
p = 1.0 - math.exp(-2.0 / T)
nsteps = 10000
S = [random.choice([1, -1]) for k in range(N)]
for step in range(nsteps):
k = random.randint(0, N - 1)
Pocket, Cluster = [k], [k]
while Pocket != []:
j = random.choice(Pocket)
for l in nbr[j]:
if S[l] == S[j] and l not in Cluster \
and random.uniform(0.0, 1.0) < p:
Pocket.append(l)
Cluster.append(l)
Pocket.remove(j)
for j in Cluster:
S[j] *= -1
[edit]
Version
See history for version information.
