Coupling ising.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 07:52, 22 February 2023 Werner (Talk | contribs) (→Program (in Python3) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
| Line 20: | Line 20: | ||
| S1 = [-1] * N | S1 = [-1] * N | ||
| S2 = [1] * N | S2 = [1] * N | ||
| - | nsteps = 10000 | ||
| step = 0 | step = 0 | ||
| while True: | while True: | ||
| Line 36: | Line 35: | ||
| break | break | ||
| print(T, MeanCoupling / NIter) | print(T, MeanCoupling / NIter) | ||
| + | =Output= | ||
| + | A slightly modified graphics version of this program produces the following output: | ||
| + | [[Image:IsingCoupling.png|left|50px]] | ||
| + | <br clear="all" /> | ||
| =Version= | =Version= | ||
| See history for version information. | See history for version information. | ||
| [[Category:Python]] [[Category:Honnef_2015]] [[Category:MOOC_SMAC]] | [[Category:Python]] [[Category:Honnef_2015]] [[Category:MOOC_SMAC]] | ||
Current revision
This page presents the program coupling_ising.py, a heat-bath algorithm for the Ising model on an LxL square lattice in two dimensions, run for two configurations at a time. The algorithm illustrates the coupling phenomenon.
Contents |
[edit]
Description
[edit]
Program (in Python3)
import random, math
L = 7
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)}
NIter = 100
for TT in range(20, 40):
T = TT / 10
beta = 1.0 / T
MeanCoupling = 0
for iter in range(NIter):
S1 = [-1] * N
S2 = [1] * N
step = 0
while True:
step += 1
k = random.randint(0, N - 1)
Upsilon = random.uniform(0.0, 1.0)
h1 = sum(S1[nn] for nn in nbr[k])
S1[k] = -1
if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * h1)): S1[k] = 1
h2 = sum(S2[nn] for nn in nbr[k])
S2[k] = -1
if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * h2)): S2[k] = 1
if S1 == S2:
MeanCoupling += step
break
print(T, MeanCoupling / NIter)
[edit]
Output
A slightly modified graphics version of this program produces the following output:
[edit]
Version
See history for version information.

