Ising Model in 2D¶
Source code: https://github.com/osscar-org/quantum-mechanics/blob/master/notebook/statistical-mechanics/ising_model.ipynb
The Cython computing kernel is adapted from the code presented in the Pythonic Perambulations blog.
Goals¶
- Understand how the Ising model can predict the ferromagnetic or antiferromagnetic behavior of a square (2D) spin lattice.
- Compute the average magnetization of the Ising model using a Monte Carlo algorithm.
- Examine the effects of the interaction parameter $J$ (ferromagnetic vs. antiferromagnetic behavior).
- Identify the critical temperature of the system from the simulation results.
- Investigate finite-size effects and their effect on fluctuations.
Background Theory¶
Tasks and exercises¶
Run the simulation with the default parameters (and $J>0$) and check the plot of the magnetization per spin as a function of the simulation step. What happens at very low temperatures? And at intermediate temperatures? And at very high temperatures? And what happens for $J<0$?
Solution
For a positive $J$ value, parallel neighboring spins are energetically favored. Therefore, at $T=0$ we expect all spins to be aligned: the system is ferromagnetic. At low temperature, spin will still tend to be aligned with their neighbors, with some local fluctuations as temperature increases. Fluctuations become very large close to $T_c$, and above $T_c$ they become predominant and, on average, we obtain zero net magnetization. On the other hand, $J<0$ will lead to a checkerboard pattern for the final spin configuration at low temperatures, i.e., an antiferromagnetic configuration. When $J=0$, there is no interaction between spins and we always obtain a random spin configuration.
Simulate a large system (200x200) with, e.g., $J=1$ and $T=2.5$. Is the simulation converging with the selected number of steps? Which values can you inspect to determine the convergence of the simulation?
Solution
A large number of simulation steps can be needed before properties converge, especially when we are close to $T_C$.
You can check the plot of the integrated quantities (total energy, magnetization per spin) to see if the value is converged (their values are constant save for small fluctuations with simulation step), or if you need to increase the number of steps.
Set $J=1$ and start from all spin up (i.e., disable a random starting configuration). Run multiple simulations at various temperatures. Can you approximately identify the critical (Curie) temperature using the plot below the interactive controls?
Solution
We suggest that you start from a small size system (50x50) to avoid excessively long simulations, and choose a long number of simulation steps (1000) to be approximately converged (see previous question).Theoretically, $T_C$ for the 2D Ising model (and $J=1$) is about 2.27 (see the Wikipedia page of the Square lattice Ising model), as visualized by the analytical exact solution plotted below the interactive controls.
You should see that the simulation results follow relatively closely the analytical curve for $T \ll T_c$ or for $T \gg T_C$, but large fluctuations occur close to the Curie temperature. We suggest that you run multiple runs for each temperature to see the fluctuations. You should be able to reproduce the curve and thus approximately identify the transition temperature.
We suggest that you try the same with different values of $J$.
- Set $J=1$, and simulate the system close to $T_C$. Investigate the magnitude of fluctuations as a function of system size.
Solution
Consider for instance both a small (50x50) and a large system (200x200), $J=1$, and $T=2.5$. Run a few simulations (at least 5 or 10) for each system size (note that each simulation for the large system will take many seconds). Verify that fluctuations are less pronounced for the larger system.Note that the difference in fluctuations might not be very large, since the two systems are still relatively similar in size. The difference in the magnitude of the fluctuation can also be visualized by inspecting the fluctuations of the averaged quantities in the two plots of the magnetization per spin and total energy as a function of the simulation step.
- Consider a 100x100 system, set $J=1$ and $T=1.7$. Use a large number of simulation steps, and enable the randomization of the initial spin configuration. Investigate the formation of domains. Are they more stable for large or small systems?
Solution
If you run the simulation multiple times, you will notice that often the simulation does not reach the expected (positive or negative) analytical exact result, but will have intermediate magnetization values due to the formation of domains. These might disappear during the simulation, but sometimes they will remain even after 1000 simulation steps.If you consider a smaller system (e.g. 50x50), you should notice that there is a higher probability that the domains disappear during the simulation. In fact, the cost of a domain scales as the length of its boundary, which (for very large systems) becomes a negligible cost with respect to the total energy of the system (that scales with the number of spins, i.e. quadratically with respect to the system size) and therefore can exist for a long time; in addition, domains will have a higher probability to merge for a small system.
Legend¶
(How to use the interactive visualization)
Controls¶
The "size" slider defines the number of spins along each dimension. You can also adapt the number of simulation steps, the value of the exchange interaction parameter $J$, and the temperature of the simulation (note: units have been chosen so that the Boltzmann constant $k_B=1$).
By default, we set all spin up for the initial configuration. This induces a bias for short simulations (but can help avoid the formation of domains); you can instead randomize the initial configuration by ticking the checkbox "Randomize initial spin configuration".
Running the simulation and output plots¶
Click the "Run simulation" button to start the simulation with the selected parameters.
In particular, the figures above the controls display the time evolution of the last simulation that was executed. The figure on the left shows the spin configuration. A yellow pixel represents a spin up and blue represents a spin down. After the simulation finished, you can click "Play" to view the evolution of the simulation step by step (or drag manually the "Frame" slider). The figure on the top right shows the evolution of the magnetization per spin over the simulation as a function of the Monte Carlo simulation step number. The figure on the bottom right shows the total energy as a function of the step number.
In addition, at every new simulation, a new green point is added to the bottom plot, showing the magnetization per spin as a function of temperature $T$. The analytical exact solution for the chosen value of $J$ is also shown (see Wikipedia page on the square lattice Ising model for more details on the exact solution). Note that when a random initial configuration is selected instead of all spin up, there shall be both blue and red curves for the analytical solution due to the possibility of having negative magnetization in that case.
Changing any slider (except for the temperature slider) will reset the bottom plot. You can change the temperature and run the simulation multiple times to compare the analytical solution with the results of the simulation.