MS5033 · MONTE CARLO LAB

Local moves.
Collective patterns.

These animations are based on my teaching codes, order.jl and Potts.jl. I wrote these codes to explain spin alignment and grain growth through local changes on a lattice. Both simulations use a 256 × 256 periodic lattice with 200 sweeps for Ising and 2,000 sweeps for Potts.

Ising spin alignment.

Each attempted move flips one spin. The Metropolis rule accepts an energy decrease and accepts an increase with probability \(e^{-\Delta E/T}\), using \(k_B=J=1\). Here \(T=1.5\). The movie shows same-spin domains developing from random initial spins.

\[H=-J\sum_{\langle ij\rangle}s_i s_j,\qquad s_i\in\{-1,+1\}.\]

Download Ising movie ↓ · Energy diagnostics ↓

Blue and red identify the two spin states. One sweep means 65,536 attempted updates, not a calibrated physical time. Single-spin flips do not conserve composition. The function in my original teaching code is named “Glauber,” but its acceptance rule is Metropolis. This ferromagnetic example illustrates spin alignment; it does not demonstrate unlike-neighbor chemical ordering in an alloy.

Potts grain growth.

Start with a distinct orientation label at every pixel: 65,536 single-pixel grains. The labels are randomly permuted over the grid. As neighboring orientations take over sites, small grains disappear and surviving grains grow. A site proposes adopting a neighbor’s label; acceptance depends on the change in the number of mismatched nearest-neighbor bonds, with \(T=0.3\).

Download Potts movie ↓ · Boundary-energy diagnostics ↓ · Surviving orientation counts ↓

The movie samples every 25 sweeps. Fixed rainbow colors label orientations; they do not encode chemical concentration or energy. Labels are categorical orientation states, not numerical Euler angles: all unlike nearest-neighbor bonds have the same energy here. Dark outlines mark unlike neighbors; similar colors need not mean similar orientations. The four-neighbor square lattice can leave grid-related anisotropy in the boundaries. This neighbor-copy algorithm is a grain-growth teaching heuristic. Its proposal probabilities are not generally symmetric, so this acceptance rule should not be presented as an equilibrium Potts sampler satisfying detailed balance.

Run either example.

Julia source ↓ Download the Python notebook ↓ · Read the code in steps →

julia monte_carlo.jl ising ising_results
julia monte_carlo.jl potts potts_results

python -m pip install numpy
python monte_carlo.py ising ising_results
python monte_carlo.py potts potts_results

The movies were computed with Julia. The matching NumPy implementations use transparent sequential loops and run more slowly. Both languages were exercised; the NumPy checks used smaller 16 × 16 grids. Independent random generators mean trajectories differ. Neither movie is an equilibrium or convergence claim.

The effect of changing a model assumption.

Raise the Ising temperature and inspect domain persistence. For Potts, compare the boundary energy as a function of sweep count at different temperatures. For an alloy with fixed composition, compare with the Kawasaki exchange dynamics in my teaching code, where atoms swap rather than change identity.

Discuss mixing, ordering and the regular-solution approximation →

How I develop my codes.

I start with a small calculation, check its result and then add the next part. These lessons follow the same sequence, with explanations and checks at each stage. Open the worked Python, Julia and C lessons →