This repository contains the work of Erica Løken, Mads Mestl and Heine Husdal for Project 4 in the course FYS3150 – Computational Physics at the University of Oslo.
In this project, we study the temperature-dependent behaviour of the two-dimensional Ising—Lenz model. The model consists of a lattice of spins, where each spin can take values
The Ising—Lenz model is simulated using the Markov chain Monte Carlo method with the Metropolis—Hastings acceptance rule, where spins are flipped according to probabilities given by the Boltzmann distribution. We study the thermodynamic quantities of the system such as the energy per spin, magnetisation per spin, heat capacity per spin and magnetic susceptibility per spin as function of temperature and lattice size
src/- C++ source filesinclude/- Header filespython/- Python scripts for plotting resultsfigures/- Generated plots and graphsoutput/- Simulation output filesdata/- Precomputed simulation output files used in the reportreport/- Project pdf report
All C++ programs are compiled and executed using the provided Makefile.
To compile the C++ code, navigate to the project root directory and run:
makeThis will build all executables in build/. If you wish to compile a specifc program, individual builds are made using the following commands:
make 2x2 # build 2×2 validation program
make burnin # build burn-in simulation
make hist # build histogram simulation
make temps # build temperature-sweep simulation
make temps_zoom # build temperature-sweep simulation with zoomed temperatures
make timing # build timing test programThe above was tested on Linux, but it might not work out of the box on other systems due to library paths. You might need to adjust the CXX and CXXFLAGS variables in the Makefile according to your system setup. For example, on a Mac you might use:
# Mac OS with Homebrew-installed g++
make CXX=g++-12 CXXFLAGS='-O3 -std=c++17 -I include -Wall -Wextra -fopenmp'To run the compiled C++ code, navigate to the project root and run the corresponding make commands:
make run-2x2 # run analytical validation of 2x2 lattice at T = 1.0 J/kB
make run-burnin # run burn-in simulation at T = 1.0 J/kB and T = 2.4 J/kB
make run-hist # run histogram simulation for L = 20
make run-temps # run temperataure sweep for L = 40, 60, 80, 100
make run-temps-zoom # run temperataure sweep for finding Cv/N peak for L = 40, 60, 80, 100
make run-timing # run timing test for parallelisation analysisIf not already built, they will auto-compile. Output files are saved in output/ directory.
Some programs are parallelised with OpenMP. To specify the number of threads, set the OMP_NUM_THREADS environment variable before running. For example, to use 4 threads on main_histogram.cpp, run:
OMP_NUM_THREADS=4 make run-histFor plotting, a python environment is required. To install the required packages, run:
pip install -r requirements.txtFor plotting results after running all simulations, navigate to the python/ directory and run plotting scripts using:
python plot_burnin.py # Burn-in plot
python plot_histogram.py # Histogram plots
python plot_error_convergence_2x2.py # Plot of running relative error for 2x2 lattice
python plot_temperatures.py # Observables (eps, m, Cv/N, chi/N) vs temperature
python plot_critical_temp.py # Critical temperature extrapolation
python plot_timing_test.py # Timing test plotAll plots are saved in the figures/ directory.
The C++ code has been successfully compiled and linked using
g++ (Ubuntu 13.3.0-6ubuntu2~24.04)g++-12 (Homebrew GCC 12.4.0) 12.4.0