This project explores phase transitions in 2D statistical mechanics models using C++ for simulations and Python for data analysis. The primary focus is on the Ising model and its generalization, the q-state Potts model. We investigate their thermodynamic properties by employing two distinct computational techniques:
- Exact Enumeration: For small lattice sizes, we calculate properties by enumerating every possible microstate.
- Monte Carlo (MC) Methods: For larger systems where enumeration is computationally infeasible, we use the Metropolis and Glauber algorithms to sample the configuration space.
The goal is to observe critical phenomena, such as the divergence of heat capacity near the critical temperature, and to compare the efficiency of different simulation dynamics.
The repository is organized into two main parts:
-
📁 enumeration/: Contains the code and results for the exact enumeration of the 2D Ising model. This method is precise but only practical for small systems ($N \le 6 \times 6$ ). -
📁 simulation/: Contains the code and results for Monte Carlo simulations of the q-state Potts model. This approach allows us to study larger systems and explore their dynamics. -
📁 helper_functions.hpp/.cpp: Core functions used across different simulations (e.g., lattice setup, energy calculations). -
*.ipynb: Jupyter notebooks used for plotting and analyzing the data generated by the C++ programs.
The 2D Ising model is a classic model of ferromagnetism. The Hamiltonian is given by:
where
-
enumeration/enumeration.cpp: This program iterates through all$2^N$ possible configurations for an$N=n \times n$ lattice. -
Outputs: It calculates the density of states
$\mathcal{N}(E)$ , which is then used in theenumeration/heat_capacity_calculations.ipynbnotebook to compute and plot the average energy and specific heat as a function of temperature.
The q-state Potts model is a generalization of the Ising model where each spin can be in one of q states. The Hamiltonian is:
where
We use two different Monte Carlo algorithms to simulate this model:
- Metropolis Algorithm (
simulation/metropolis_convergence.cpp): A standard MC method where a random spin flip is proposed and accepted or rejected based on the change in energy. This was used to study the model's phase transition. - Glauber Dynamics (
simulation/glauber_equilibration.cpp,simulation/glauber_convergence.cpp): A different dynamic where a new spin value is chosen from a probability distribution based on the local energy landscape. This method is particularly more efficient than Metropolis for models with largeq. A comparison of the convergence speed between the two algorithms is a key part of this project.
- A C++ compiler that supports C++20 (like
g++orclang++). - Python 3 with Jupyter Notebook, NumPy, and Matplotlib for data analysis.
All C++ programs should be compiled with the -O3 optimization flag and linked with helper_functions.cpp.
# General compilation command
g++ -O3 -std=c++20 path/file.cpp helper_functions.cpp -o executable_nameThis is built upon to content covered in the statistical mechanics course at Imperial College.