This is a Monte Carlo simulation program for the Ising spin model. Simulations include free energy construction [1], nucleus formation [2] with umbrella sampling [1]. The program is written in C, with ffmpeg used for the generation of simulation videos. Please ensure ffmpeg is installed on your system (can be found here). Python is used to visualize the thermodynamics of the system via Jupyter notebooks for two specific experiments for validation, which can be found in analysis/
.
- Clone the repo
$ git clone https://github.com/AdityaDendukuri/IsingNucleation.git
- Create the directories
build/
andoutput/
$ cd IsingNucleation
$ mkdir build output
- Go to the build directory and run cmake as follows (you only need to do this the first time)
$ cd build
$ cmake -S ../ -B .
- This will generate the makefile in
build/
. Compile the program by simply typing:
$ make
- Run the executable
$ ./IsingNucl
Simulation output and video will be saved in output/
.
Please refer to "main.c" for the steps to invoke the simulation. There are three experiments pre-coded in "src/simul.c".
run_sim()
: Classic Metropolis Monte Carlo 2D Ising Lattice Simulation. simulation videovalidate_free_energy()
: Validating the simulation by running simulations at various temperatures and comparing the minimum energy of each temperature with the exact solution. Free energy validation based on the output of the experiment is shown in the Python Jupyter notebook inanalysis/
folder "free_energy.ipynb".run_sim_nucleation()
: Simulation of nucleus formation in 2D Ising System simulated via umbrella sampling (also known as non-Boltzmann sampling) with overlapping windows from N = 15 to 450. Refer tonucleation.ipynb
inanalysis/
folder for the analysis of the simulation data and free energy construction. simulation video.
-
The lattice size, defined in main (
int n
), is the sidelength of the lattice square (not the number of spins). That means the number of spins = n * n. -
The resolution of the output video should be the same as the lattice dimensions. The resolution of the output video is set in the function
make_video()
insrc/media.c
. The resolution should be explicitly defined in the string with the ffmpeg command. For example, if the lattice is n=50, change the resolution as "ffmpeg -s 50x50 <rest_of_the_command>". -
int* simspace
is the memory buffer holding the lattice snapshots which will be turned into a video. It is better to skip some steps before adding a frame to the video to avoid stack overflow issues.
[1] Chandler, David. Introduction to modern statistical mechanics. 1987.
[2] Brendel, Kevin, G. T. Barkema, and Henk van Beijeren. "Nucleation times in the two-dimensional Ising model." Physical Review E 71, no. 3 (2005): 031601.