This repository contains code for the Monte Carlo Calculation of an Ising model.
The code was used for the course Thermal and Statistical Physics, where I did TA and taught students how to do the Monte Carlo Simulation for the Ising Model.
Code author: Jiawei Zang (jiaweizang)
Consider the 2D L*L-spin Ising model, in which each site is associated with a variable
It has periodic boundary conditions:
Based on Monte Caro method, the main procedure is as follows:
-
Create a L * L lattice, and start with a given spin configuration
$s_p$ and energy$E_p$ -
Select a site at random and propose to flip the spin on that site (i.e. change the sign of the variable on that site).
-
Compute the new energy
$E_{new}$ , and calculate the energy difference$\Delta E = E_{new} - E_p$ . -
Accept or reject the proposal with the detailed balance probability: a) if
$\Delta E<=0$ , accept the proposal. b) if$\Delta E>0$ , accept the proposal with probability$P = e^{−\frac{\Delta E }{k_BT}}$ , and reject proposal with probability 1-P. -
Return either the original state or the new state according to whether the proposal is accepted.
-
Go back to step 2, repeat the procedure n_max times until it reaches equilibrium.
- set
$k_B = 0$ - we need to consider boundary conditions: we can use the trick: i% N. For example, 0%N=0, (N+2)%N=2