Skip to content

vjoy1/2d_phase_transitions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simulating Phase Transitions in 2D Lattice Models

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:

  1. Exact Enumeration: For small lattice sizes, we calculate properties by enumerating every possible microstate.
  2. 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.


Project Structure

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.

Models and Methods

1. Ising Model via Exact Enumeration

The 2D Ising model is a classic model of ferromagnetism. The Hamiltonian is given by:

$$ \mathcal{H} = -J \sum_{\langle i,j \rangle} s_i s_j $$

where $s_i = \pm 1$ are spins on a square lattice and the sum is over nearest neighbors.

  • 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 the enumeration/heat_capacity_calculations.ipynb notebook to compute and plot the average energy and specific heat as a function of temperature.

2. q-State Potts Model via Monte Carlo Simulation

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:

$$ \mathcal{H} = -J \sum_{\langle i,j \rangle} \delta_{\sigma_i, \sigma_j} $$

where $\sigma_i \in {1, 2, ..., q}$. Note that for $q=2$, this model is equivalent to the Ising model.

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 large q. A comparison of the convergence speed between the two algorithms is a key part of this project.

How to Run the Simulations

Prerequisites

  • A C++ compiler that supports C++20 (like g++ or clang++).
  • Python 3 with Jupyter Notebook, NumPy, and Matplotlib for data analysis.

Compilation

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_name

This is built upon to content covered in the statistical mechanics course at Imperial College.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages