Professional Documents
Culture Documents
Abstract:
The properties of a two-dimensional lattice of spins were investigated using the Ising Model. A Monte Carlo
method based on the Metropolis algorithm was implemented. This algorithm generates a sequence of samples
whose statistical distribution approaches the Boltzmann distribution of the magnetic system as more iterations
are executed. Under no applied field, the magnetisation, the internal energy and the heat capacity were found to
vary significantly within the vicinity of a critical temperature, at which a continuous phase transition occurs. In
particular, plotting the magnetisation against temperature allowed to estimate the critical temperature as Tc =
2.272 0.004 and
the critical exponent as = 0.109 0.018. The theoretical values predicted by Onsager,
Tc = 2/(1 + ln 2) and = 1/8, are both found within error range. When a non-zero field was applied, the
system was found to have a non-zero magnetisation above the critical temperature and a single equilibrium
state below it.
INTRODUCTION
The magnetic properties of ferromagnets can be investigated using a simplified model of spin-spin interactions known as the Ising model. In particular, the
two-dimensional Ising model consists of a square lattice in which each site has either spin up (+1) or down
(-1). Within such model the energy of a N x N lattice
can be written as:
N2
E = J
<i j>
si s j H si
(1)
i=1
Spins on adjacent sites, called nearest neighbours, interact in a pairwise manner with strength J, known
as the exchange energy coefficient. In addition, the
externally applied magnetic field H couples linearly
with the magnetisation. is the magnetic moment of
each spin.
In 1944, Onsager published the analytic solution
to the two-dimensional Ising model [1]. The critical temperature in the thermodynamic limit (i.e. an
infinitely largelattice, N ) is predicted to be
Tc = 2/(1 + ln 2). Below this temperature, the material behaves like a ferromagnet, as the spins tend
to align in the most stable configuration even in the
absence of a field. Above it, the spins tend to be
randomly oriented unless the field is non-zero, as expected for a paramagnet. Predicted by Onsager and
rigourously proved by Yang in 1952 [2], the magnetisation is expected to depend on the temperature (be-
M=
!1/8
Tc 4
1 sinh(ln(1 + 2) )
T
(2)
ANALYSIS
The statistical mechanics of complex physical systems usually poses problems that are very difficult
to solve by analytical methods. Numerical simulation techniques are therefore indispensable tools to
the study of such problems, which range from phase
transitions in binary alloys to neural networks.
The Ising model of ferromagnetism exhibits this
feature clearly. For example, if we considered a small
10 x 10 lattice of spins, the total number of microstates would be of 2100 ' 1.2 x 1030 . Summing
IMPLEMENTATION
1. Create a N x N lattice
2. Select a lattice site
3. Determine the energy change E involved in flipping the spin
4. Decide whether to flip the spin or leave it unchanged as follows:
(a) If E < 0 flip the spin
(b) If E > 0 and exp(E/kB T ) > r, where r is a
random number generated in the interval [0,1],
flip the spin
(c) Otherwise, leave the spin unchanged
5. Repeat steps 2-4 for N 2 lattice sites
The N 2 operations described above may be thought
of as a single time step. In order to reach a quasiequilibrium state, the simulation must be run for several time steps. At this point the thermodynamic and
magnetic properties of the system may be measured
by repeating several time steps and then averaging
over the relevant quantities stored at each time instant.
This time average is equivalent to an ensemble average.
In order to ensure that each lattice site had four
nearest neighbours, periodic boundary conditions
were used. Hence, when the selected site was along
the border of the lattice, its neighbours were taken
from the opposite side of the lattice. This effectively
reduced the geometry to a torus, thus avoiding undesirable effects at the edges.
Even though the two-dimensional Ising model of
ferromagnetism was solved analytically by Onsager,
this numerical simulation technique is in fact of great
value, as it may be generalized to higher dimensions,
for which no analytical solution has been found,
and to more complex interactions (e.g. next-nearestneighbour interactions). Nevertheless, the quantitative results obtained through this method were compared to the analytical results derived by Onsager.
val allowed to significantly reduce the run time, especially for large N.
M was also the number of time steps taken to compute the ensemble average of the relevant quantities.
This also justifies the need to have a greater M closer
to the critical temperature, as the fluctuations become
significant in this region.
The CPU time required to perform 1000 single
time steps (STS) at a fixed temperature for a 20 x
20 lattice was 30 s, whereas for a 30 x 30 lattice the
same procedure took
S 2 min 40 s. Performing 100 STS
for T [1.5, 2.0] [3.0, 3.5], with T = 0.1, and 1000
STS for T [2.0, 3.0], with T = 0.05, for a 10 x 10
lattice took 1 min 30 s. The same result for N = 20
and N = 30 required 24 min and 1h 58 min of CPU
time, respectively.
4
4.1
3.1
Performance
By visualizing the lattice configuration and the magnetisation against time, a continuous phase transition
was observed to occur near T = 2.30 [J/kB ]. Above
this critical temperature Tc , the equilibrium state was
a randomly aligned lattice (figure 1) with average
magnetization zero (figure 2). Below this temperature, two different equilibrium states were observed:
one with all spins down and another with all spins up.
The system would attain one of the two states depending on the initial configuration (figure 3).
The two initial lattice configurations were used at different temperatures. The uniform lattice configuration reached quasi-equilibrium more rapidly than the
random one below the critical temperature, whereas
above it the random configuration was only slightly
faster to reach near-equilibrium. Given that the initial
temperature in mode 2 was always set below the critical temperature, the lattice was always initialized with
all spins up. For the following temperatures the initial configuration was the equilibrium configuration
of the previous temperature, therefore the initialization of the lattice was only relevant for the starting
temperature.
In addition, there were two alternative ways
of picking the spin to flip. The two functions,
single_Monte_Carlo_step_regular and single_
Monte_Carlo_step_random, were tested for different temperatures, but no significant differences in efficiency were noted. As a result, the spins were
flipped sequentially using single_Monte_Carlo_
step_regular.
Moreover, since the plots against temperature have
their most distinctive features within the vicinity of
the critical temperature, the temperature increment
was set to 0.05 for the interval T [2.0, 3.0] and 0.1
elsewhere. The system also requires more time to attain near-equilibrium close to the critical temperature,
so the number of single time steps M taken to reach
equilibrium was of 1000 for T [2.0, 3.0] and 100
elsewhere. Having 1000 time steps only in this inter-
Figure 1: Spin configuration of a 20 x 20 lattice at temperature T = 4.0 [J/kB ] after 100 single time steps. Black
squares represent spin down whereas white squares correspond to spin up. As expected, the spins are randomly
aligned above Tc .
0.5
Data
Onsager Analytic Solution
0.9
sation vs. temperature graph approaches zero magnetization more smoothly than the theoretical prediction
(figure 4), so the critical temperature could only be
estimated as Tc = 2.3 0.1[J/kB ]. Onsagers critical
temperature is within this interval.
-0.5
-1
10
20
30
40
50
60
70
80
90
100
0.6
0.5
0.4
0.3
0.2
0
1.4
1.6
1.8
2.2
2.4
2.6
2.8
Temperature [J/kB]
3.2
3.4
3.6
Uniform
Random
0.7
0.1
1.5
0.8
0.5
0
-0.5
-0.6
-1
-0.8
0
10
20
30
40
50
60
70
80
90
100
-1.5
-1
-1.2
-1.4
-1.6
-1.8
-2
1.4
1.6
1.8
2.2
2.4
2.6
2.8
Temperature [J/kB]
3.2
3.4
3.6
The heat capacity C was measured via two different methods. The graph C vs. T obtained by calculating the discrete derivative dE/dT was far less
clear than the one obtained from the FluctuationDissipation Theorem due to the random errors in the
simulation (figure 6). Nevertheless, the best graph
does allow to make a better estimate of Tc , since the
heat capacity peaks at this temperature: for N = 30,
Tc = 2.3 0.05 (figure 7). The heat capacity is expected to diverge according to Onsagers model, but
such divergence is not observed in lattices of finite
size.
2500
2000
1500
1000
1.2
0
1.4
1.6
1.8
2.2
2.4
2.6
2.8
Temperature [J/kB]
3.2
3.4
500
3.6
1
0.8
0.6
0.4
0.2
0
1.4
1.8
2.2
2.4
2.6
2.8
Temperature [J/kB]
3.2
3.4
3.6
2200
2000
1800
1600
1.6
1400
1200
1000
800
600
400
200
0
1.4
1.6
1.8
2.2
2.4
2.6
2.8
Temperature [J/kB]
3.2
3.4
3.6
N
10
15
20
25
30
Tc [J/kB ]
2.35 0.03
2.30 0.02
2.299 0.019
2.286 0.004
2.277 0.018
0.7 0.3
0.40 0.15
0.17 0.06
0.11 0.06
0.09 0.02
Onsagers prediction
of the critical temperature,
2.38
2.36
2.34
Tc
2.32
2.3
2.28
2.26
2.24
0.002
0.004
0.006
0.008
1/N2
0.01
4.2
0.5
When a non-zero magnetic field was applied, a nonzero magnetisation was found above the critical temperature. The magnetisation has the same sign as the
applied field, that is, if the sign of the field is switched,
the sign of the magnetisation changes as well. In addition, the magnetisation tends to increase with the
applied field. Figure 11 illustrates these observations.
-0.5
-1
1.4
1.6
1.8
2.2
2.4
2.6
2.8
Temperature [J/kB]
3.2
3.4
3.6
Below the critical temperature, there is now a single stable equilibrium state. By considering the same
initial configurations as in figure 4, for an applied field
H = 1.0 [J/] both lattices reach the same equilibrium state, contrary to previous observations. The application of the magnetic field explicitly breaks the
symmetry of the system under the switch of all spins.
Hence, there is now a preferred direction, so one of
the uniform states is raised in energy while the other
is lowered.
1.5
H = 1.0
H = 0.5
H = 0.1
H = 0.5
REFERENCES
[1] L. Onsager, Crystal statistics. i. a twodimensional model with an order-disorder transition, Phys. Rev., vol. 65, pp. 117149, Feb 1944.
0.5
0
-0.5
-1
-1.5
100
200
300
400
500
600
700
800
900
1000
CONCLUSIONS
A Monte Carlo method using the Metropolis algorithm was developed to study the properties of a
two-dimensional lattice of spins. A continuous phase
transition was identified at a critical temperature.
Magnetisation, energy and heat capacity were observed to have the same temperature dependence for
different values of N. Below this temperature, spins
tend to align, whereas above it spins are randomly
oriented at equilibrium. The critical temperature
was found to decrease with 1/N 2 and was estimated
as Tc = 2.272 0.004 in the thermodynamic limit
N . The universal exponent was determined
as = 0.109 0.018. When a magnetic field
was applied, only one stable equilibrium state was
found below the critical temperature. Above this
temperature, the magnetisation was determined to be
non-zero and dependent on the magnitude and sign
of the field.
6.1 Matrix.h
// Class of matrices
class Matrix
{
private:
std::vector<double> m_data;
int
m_rows;
int
m_cols;
public:
Matrix( int n_rows, int n_cols, double init = 0.0 )
: m_data( n_rows * n_cols, init ),
m_rows( n_rows ), m_cols( n_cols ) { }
Matrix(){}
double& operator() ( int i, int j )
{
return m_data[i * m_cols + j];
}
};
6.2 ising_bm442.cc
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
#include <iostream>
#include
#include
#include
#include
#include
#include
#include
#include
#include
<iomanip>
<cmath>
<ctime>
<cstdlib>
<cstdio>
<fstream>
"gsl/gsl_rng.h"
<vector>
"Matrix.h"
// Boltzmann Constant
// Function that calculates the product of spins for nearest neighbours of one site
double nearest_neighbours( Matrix& lattice, int row, int col, int N)
{
double nn_sum = 0.0;
int a, b, c, d;
// Periodic Boundary Conditions
if ( col - 1 < 0)
{
a = N - 1;
}
else
{
a = col - 1;
}
if ( col + 1 > N - 1)
{
b = 0;
}
else
{
b = col + 1;
}
if ( row - 1 < 0)
{
c = N - 1;
}
else
{
c = row - 1;
}
if ( row + 1 > N - 1)
{
d = 0;
}
else
{
d = row + 1;
}
// 4 nearest neighbours
nn_sum
nn_sum
nn_sum
nn_sum
=
=
=
=
nn_sum
nn_sum
nn_sum
nn_sum
+
+
+
+
((double)lattice(
((double)lattice(
((double)lattice(
((double)lattice(
row,
row,
row,
row,
col
col
col
col
))
))
))
))
*
*
*
*
((double)lattice(
((double)lattice(
((double)lattice(
((double)lattice(
row, a
row, b
c, col
d, col
));
));
));
));
return nn_sum;
}
10
// Function that returns a random number between 0 and 1 using the GSL function gsl_rng.
double random_generator( unsigned long int seed = 0)
{
static gsl_rng* rng = 0;
if ( rng == 0 ) rng = gsl_rng_alloc( gsl_rng_default );
if ( seed != 0 ) gsl_rng_set( rng, seed );
return gsl_rng_uniform( rng );
}
= 1.0;
// Metropolis Algorithm
void Metropolis( Matrix& lattice, int row, int col, int N, double T, double H )
{
// Creating new microstate with one spin flipped at ( row, col )
Matrix new_microstate( N, N );
for (int i = 0; i < N; i++ )
{
for (int j = 0; j < N; j++ )
{
new_microstate( i, j ) = lattice( i, j );
}
}
11
12
}
}
<<
<<
<<
<<
<<
<<
"t = 1 \n";
"show grid\n";
"set term x11 persist \n";
"set palette defined (-1 \"black\", 1 \"white\")" << "\n";
"set xrange [1:" << N << "] \n";
"set yrange [1:" << N << "] \n";
13
14
double
double
double
double
double
double
double
double
double
double
double
double
double
double
double
double
double
magnetisation_sum
energy_sum
squared_magnetisation_sum
squared_energy_sum
mean_magnetisation
mean_energy
mean_energy_per_site
mean_squared_magnetisation
mean_squared_energy
squared_std_magnetisation
std_magnetisation
squared_std_energy
std_energy
heat_capacity_1
heat_capacity_2
mean_energy_previous
T_previous
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
0.0;
std::ofstream j("output");
while ( T < 3.5 )
{
// More Monte Carlo Steps required to attain equilibrium close to transition
if ( T == T_0 )
{
M = 100;
}
else
{
M = 1000;
}
// Reaching equilibrium
for ( int i = 0; i < M; i++ )
{
single_Monte_Carlo_step_regular( lattice, N, T, H );
}
// Performing calculations of properties of ensemble
for ( int j = 0; j < M; j++ )
{
single_Monte_Carlo_step_regular( lattice, N, T, H );
magnetisation_sum = magnetisation_sum + magnetisation( lattice, N );
15
// Heat Capacity = dE/dT, but we require two values of T, so it has to wait for 2nd loop
if( T > T_0 )
{
heat_capacity_1 = (mean_energy - mean_energy_previous) / (T - T_previous);
}
// Heat Capacity from Fluctuation-Dissipation Theorem
heat_capacity_2 = squared_std_energy / pow( T, 2 );
// Printing to file
j << T << " " << fabs(mean_magnetisation) << " " << mean_energy_per_site << " ";
j << std_magnetisation << " " << std_energy << " ";
j << heat_capacity_1 << " " << heat_capacity_2 << "\n";
// Previous Values of T and <E> are required to compute Heat Capacity = dE/dT
mean_energy_previous = mean_energy;
16
T_previous = T;
// Reinitialization of Summing Variables
energy_sum = 0.0;
magnetisation_sum = 0.0;
squared_energy_sum = 0.0;
squared_magnetisation_sum = 0.0;
N = 10;
M = 1000;
lattice( N, N );
T_0 = 1.5;
H_0 = 0.0;
mode;
17
//
//
//
//
//
//
18