Monte Carlo simulation of the Ising model in ROOT
To run open root
and run .x compileMacro.C
. You can try
the examples loading them with .L
.
The class can build a multi dimensional square lattice of spins.
The class can draw 2D or 3D lattice from the class Lattice.
1000000 spin 2D model at . Each frame is the flipping of 1000 spins. First video goes from 0 to 20000th iterations, then each gif continues with the next 20000. Notice that periodic boundary conditions during the islands formation.
The lattice is a multidimensional grid. We store it in a one dimensional array, which means that we have to choose a convention. The lattice is periodical, so we can imagine a torus for a 2D lattice…
…and so on…
Imagine the vector of spins wrapped on itself as many times as the dimension of the problem. Here, a 3D representation:
It’s necessary to remember these assumptions when measuring quantities such as energy on the lattice.
Since the lattice is a mono dimensional bool *
we need a method to
count the neighbours of each spin.
Here are examples of neighbour counting for mono dimensional and bi dimensional lattice.
Reduntant terms were omitted: (i // N) * N
is zero when in max
dimension, also, (i + 1) % N
(i - 1 -N) % N
may be reduntant.
We can easily see a pattern. We use i
as the index of the
spin in the lattice, d
is a particular dimension where we
want to find the neighbours.
For a simple notation we used //
and **
in a python-ish style
meaning respectively integer division and power (power comes before
all the other operations).
(i // N**(d + 1))*N**(d + 1) + (i + N**d ) % N**(d + 1)
(i // N**(d + 1))*N**(d + 1) + (i - N**d + N**(d + 1)) % N**(d + 1)
We can loop on i
and d
to obtain all the neighbours. The process
can be executed in parallel and be reduced with if
statements on
the first and last iteration.
The first reduction is much more sensitive since let us to evaluate a single power for each dimension > 1.