Non-equilibrium systems, such as those undergoing relaxation dynamics, are crucial for understanding real-world phenomena. The 2D Ising model is a fundamental framework for studying phase transitions and spin dynamics in statistical mechanics. This repo contains codes that simulate and analyze the magnetization dynamics of the 2D Ising model under various temperatures
You need to have Python 3.9 installed along with the following libraries to run the simulations:
numpy1.26.4matplotlib3.10.0
Clone the repository:
git clone https://github.com/bowenyu066/ising-kmc.git
cd ising-kmcSetting up a virtual environment is recommended:
conda create -n ising-kmc python=3.9
conda activate ising-kmc
pip install numpy==1.26.4 matplotlib==3.10.0Or, you can install the dependencies from requirements.txt in your current environment:
pip install -r requirements.txtSource codes are located in the src/ising-kmc directory. You can simulate the 2D Ising model dynamics using either the random-sequential update method:
python src/ising-kmc/random_sequential.py --beta 0.6 --N 20 --J 1.0 --H 0.0 --MAX_TIME 25000Or the next-reaction method:
python src/ising-kmc/next_reaction.py --beta 0.6 --N 20 --J 1.0 --H 0.0 --MAX_TIME 5000Here, --beta is the inverse temperature, --N refers to the size of the lattice --J is the coupling constant --H is the external magnetic field --MAX_TIME is the maximum simulation steps (defaults to 5000 for next-reaction method and 25000 for random-sequential method).
The simulation was conducted on a examples/ directory, including:
-
beta=0.3.giftobeta=0.7.giffor both random-sequential and next-reaction methods: the relaxation dynamics of the magnetization$M$ towards equilibrium at different inverse temperatures$\beta$ -
random-sequential.pngandnext-reaction.png: The magnetization$M(t)$ as a function of time$t$ for the random-sequential update method and the next-reaction method, respectively, at different inverse temperatures$\beta$ -
random-sequential-eq.pngandnext-reaction-eq.png: The equilibrium magnetization$M$ as a function of inverse temperature$\beta$ for the random-sequential update method and the next-reaction method, respectively
The 2D Ising model consists of a lattice of spins
where
where
where
The 2D Ising model is the first model that was shown to exhibit a non-trivial phase transition at thermodynamic limit
When the system approaches phase transition, the magnetization
where
Regarding the simulations, we focus on the relaxation behavior of the magnetization
The random-sequential update method is a discrete-time method where each spin is updated sequentially. The algorithm is as follows:
- Initialize the
$N \times N$ lattice with random spins$s_{(i, j)} = \pm 1$ . - Set the flipping rate
$w_{(i, j)}$ for each spin$s_{(i, j)}$ :
- Calculate the change in energy
$\Delta E$ if$s_{(i, j)}$ is flipped:
- Set the flipping rate
$w_{(i, j)}$ as follows:
- Update the maximum flipping rate
$w = \max_{i, j} w_{(i, j)}$ .
- Select a random spin
$(i, j)$ , and calculate the flipping probability$p = w_{(i, j)} / w$ within the time step$\Delta t = 1 / w$ . Generate a random number$r$ from a uniform distribution$[0, 1]$ . If$r < p$ , flip the spin$s_{(i, j)}$ . Otherwise, do nothing. - Update the time
$t = t + \Delta t / N^2$ , where$N^2$ is the total number of spins. - Repeat steps 2-4 until the system reaches equilibrium.
The next-reaction method is a continuous-time method where the time to the next reaction (i.e., spin flip) is calculated. The algorithm is as follows:
- Initialize the lattice with random spins
$s_{(i, j)} = \pm 1$ . Set the initial time$t = 0$ . - Set the flipping rate
$w_{(i, j)}$ and the reaction time$\tau_{(i, j)}$ for each spin$s_{(i, j)}$ :
- Calculate the change in energy
$\Delta E$ if$s_{(i, j)}$ is flipped:
- Set the flipping rate
$w_{(i, j)}$ as follows:
- Generate a random number
$r$ from a uniform distribution$[0, 1]$ . Set the reaction time$\tau_{(i, j)} = -\ln r / w_{(i, j)}$ . - Store the reaction time
$\tau_{(i, j)}$ in an indexed min-heap.
- Select the spin
$(i, j)$ with the minimum reaction time$\tau_{(i, j)}$ from the min-heap. Flip the spin$s_{(i, j)}$ . - Update the time
$t = \tau_{(i, j)}$ . - Update the reaction time for the neighboring spins and the spin
$(i, j)$ itself as follows:$\tau_{(i, j)} = t + \Delta \tau_{(i, j)}$ , where$\Delta \tau_{(i, j)} = -\ln r / w_{(i, j)}$ ,$r \sim \text{Unif}[0, 1]$ . Update the min-heap. - Repeat steps 3-5 until the system reaches equilibrium.

