Enumerate ising dos.py
From Werner KRAUTH
This page presents the program Enumerate_ising_dos.py, the enumeration of the Ising-model configurations for small lattices (see also the simpler version of the program). Periodic boundary conditions are supposed.
Contents |
[edit]
Reference
W. Krauth Statistical Mechanics: Algorithms and Computations Oxford University Press (2006) This program is discussed in Lecture 3 of my ICFP course 2015 on Statistical physics. The Lectures is called "Exact computations in the two-dimensional Ising model (Kac-Ward)".
[edit]
Description
This program uses a Gray-code enumeration to go through all the configurations of the Ising model on square lattices of width L with periodic boundary conditions.
[edit]
Program
def gray_flip(t, N): k = t[0] if k > N: return t, k t[k - 1] = t[k] t[k] = k + 1 if k != 1: t[0] = 1 return t, k L = 4 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)} S = [-1] * N E = -2 * N dos = {} dos[E] = 1 tau = range(1, N + 2) for i in range(1, 2 ** N): tau, k = gray_flip(tau, N) h = sum(S[n] for n in nbr[k - 1]) E += 2 * h * S[k - 1] S[k - 1] *= -1 if E in dos: dos[E] += 1 else: dos[E] = 1 for E in sorted(dos.keys()): print E, dos[E]
[edit]
Version
See history for version information.
Categories: Python | ICFP