Sie sind auf Seite 1von 11

Ising Model of a 2D magnetic solid

-
September 3, 2014
Abstract
Isings model of a magnetic solid in two dimensions was recreated in
python and studied at varius temperatures around the critical tempera-
ture T
c
= 2.269. The magnetization and energy vs iteration steps plots
shoved us, that the system could randomly ip itself back and forth be-
tween magnetization equel to 1 and -1 at T
c
. The grafs of the temperature
dependency of magnetization, magnetic susceptibility, and heat capacity
showed approximately an divergence at T
c
but with an substantiel statis-
tical variance.
1 Introduction
The purpose of this project is to study Isings model of a magnetic solid in two
dimensions. The model is a mathmatical model of ferromagnetism in statistical
mechanics and describes how the discrete variables of atomic magnetic dipoles,
which can be described as being in one of two states 1 or -1, interact with
each other on a given lattice. These states of the atomic magnetic dipole are
also known as magnetic spin and is commonly called spin up for 1 or down
for -1. The goal is to study the behaviour of varius physical properties and
their temperature dependency, such as heat capacity, magnetism, and magnetic
susceptibility in the system which we model in python.
2 Theory
2.1 Energy
In our 2D square lattice which we used the energy can be calculated through
use of a central spin and its four neighboring spins. The interaction betweeen
two neighboring spins can mathmatically described as:

ij
= JS
i
S
j
Where is the interaction energy, S is the spin, which is either up or down
or 1 or -1, and J is the interaction constant. To get the overall energy of the
system we therefor have to calculate the sum of all unique pairs of neighboring
magnetic spins:
E
total
=
neighbours

ij

ij
= J
neighbours

ij
S
i
S
j
1
Figure 1: A) A color coded representation of the two dimensional lattice. B)
A model of the up and down spin. If two neighboring spins face the same way
then their interaction energy equels -J while it equels J if they are each others
opposite. C) An example of the four possible neighbors of a spin from which
the energy interaction is calculated.
The lowest energy of a system such as the one described above occurs when
or if all spins in the system achieve the same value and the J value is set to
J 0. This state is known as ferro magnetism and we can say that the spins
have alligned with each other. To achieve a greater degree of realism we will use
periodic boundary conditions on our energy calculations such that it will more
closely resemble a lattice of a magnetic solid. With this the boundarys will be
connected with each other and a spin in the lower left corner will calculate its
resulting energy from the two spins around it and the spins in the upper left
and the lower right corners.
2.2 The Metropolis-Hastings algorithm
The model is simulated through a Monte Carlo algorithm known as the Metropolis-
Hasting algorithm. This algorithm is used to caculate the Boltsmann distrubu-
tion of our representation of the two dimensional Ising model. The princip of
the algorithm is that if our model starts out in an unperturbated state then a
random Monte Carlo step will perturb the system into a new state by ipping
precisely on random spin on the lattice. This new state will naturally have a
new total energy and we can nd the energy dierence of these two states as
E = E
n+1
E
n
, where E
n+1
is the new energy and E
n
is the old. If E < 0
ie. the energy of the system has benn decreased, then the new state is more
stable then the old and is therefor accepted. The probability can therefor be de-
scribed as P = 1 for this case. If on the other hand E > 0 then the acceptance
is dependent on the Boltsmann distribution:
P = min
_
1, exp
_

E
k
B
T
__
In this case where E > 0 the algorithm will nd a random number and
if the value is equel or greater than the Boltsmann distribution, then the new
state is also accepted, just as when E < 0. After accepting or declining a
change in the spin of the lattice the algorithm will continue with a new random
ip thereby continuing the loop for however long we want.
2
2.3 Physical constants
A Boltsmann distribution of the energy is achieved by running the described
algorithm with as many steps as possible. The distribution can be described
analytically as:
N
i
N
=
1
Z
G
i
exp
_
E
i
k
B
T
_
Where
N
i
N
is the probability to detect the g
i
degenerate energy state E
i
, while
Z is the partition function of the model. The interaction constant J used for the
energy calculation and Boltsmanns constant K
B
are both dened in this project
to equel one, such that all energies and temperatures are given respectively in
units of J and units of K
B
. This is done to increase the simplicity of our model
and the perceptibility of our grafs. Another important constant in this model is
the critical temperature T
c
= 2.269 which is the highest temperature at which
there theoretically can be a non zero magnetization. There will therefore be
some kind of transition from ordered to disordered state around this critical
temperature which we will study closer in the Results and Discussion section.
2.4 Overall magnetization, magnetic susceptibility, and
Heat capacity
The overall magnetization is dened as the average spin:
M =
1
L
2

i
S
i
Where L is the width and length of the square lattice while S
i
is the con-
tribution from each individuel spin components. To study the temperature
dependence of our model we can for example look at the magnetic susceptibility
:
=
J
k
B
T
_

M
2
_
M
2
_
Where

M
2
_
is the average of the squares of the magnetization at a given
temperature, while M
2
is the square of the averages of the magnetization.
Because the only way to raise the probability that an energy increase is allowed
in the system is to raise the temperature, we can expect that the overall mag-
netization at low temperature is either 1 or -1, equilivant to having all the spins
alligned in either an up or down direction. Contralily we get that the spins must
all be totally random at higher temperatures and that the overall magnetization
must be about 0 here. The temperature dependence of the energy can best be
described as the heat capacity which in our model is dened as:
C
v
=
_
J
k
B
T
_
2 _

E
2
_
E
2
_
where E is the energy of a single spin: E =
E
total
L
2
and L is the width of
the square lattice. As before

E
2
_
and E
2
are respectively the average of the
squares and the squares of the averages.
3
3 Implementation of the python code
The python code of the simulation, is structered in varius parts. First we have
the section in which we import necesary external functions into our program.
These were the packages that were used: numpy, math, random, and mat-
plotlib.pyplot. Next section consists of the denition of two global constants
which are therefor applicable everywhere, as well as a switch which can choose
between two dierent types of plots to simulate. The ones which shows the
temperature dependences of the physical properties of the system, and the ones
who dont.
1 ME plots = False
2 T plots = True
3
4 if ME plots:
5 L = 20.0
6 ...
7
8 if T plots:
9 L = 256.0
10 ...
The next thing we do is to dene varius functions that we can use in our
simulation. This program consists of six dierent functions. Two functions
to calculate the energy, one to calculate the heat capacity, one to calculate
the magnetic susceptibility, one to calculate the dierence in the magnetization
between steps, and one to perform the Metropolis-Hastings algorithm. The two
algorithms that calculate the energy runs under the same basic principle. The
dierence is that one of them calculates the energy for the entire grid while
the other only calculates for one spin and its neighbors. This way we achieve
a higher speed because we only have to nd the energy for the whole grid
once, and can afterwards just calculate the part which changes, with a spin ip.
The energy is calculated by a double for loop in which we incorperate periodic
boundary conditions. The example given below will calculate for the entire grid,
to calculate for a step extended boundary conditions and energy summations is
required:
1 def calc energy(lattice):
2 energy = 0.0
3
4 for x in range(len(lattice)):
5 for y in range(len(lattice)):
6
7 xplus = x+1
8 if xplus > len(lattice)-1:
9 xplus = 0
10
11 ymin = y-1
12 if ymin < 0:
13 ymin = len(lattice)-1
4
14 ...
15
16 energy += -J*lattice[x][y]*lattice[x][ymin]
17 energy += -J*lattice[x][y]*lattice[xplus][y]
18 ...
19
20 return energy
The functions for the calculations of the heat capacity and magnetic sus-
ceptibility are just simple formular and does not require further complicated
coding. To calculate the dierence of the magnetization between two steps in
the simulation, we check with an If statement wheter the spin was changed to
1 or -1, and then denes and returns a value which can be used to correct the
system.
1 def mag(lattice,x,y):
2
3 if lattice[x][y] == 1:
4 dM = 2.0/L**2
5
6 if lattice[x][y] == -1:
7 dM = -2.0/L**2
8
9 return dM
The Metropolis-Hastings algorithm is a for loop that starts out with gener-
ating a random x,y koordinate. The spin value of our lattice which we have as
input for the algorithm is then ipped. This is then used to calculate the en-
ergy step and the magnetization step with the function we dened above. If the
energy step is below zero then the change is accepted and after a burn-in period
of half of all our steps we save our new varibles in lists ready for plotting. If
the energy change on the otherhand is positive og equel to zero then the change
is accepted depending on the Boltsmann distribution. In the cases where the
changes are denied we have an else statement which ip the spin back to its
original state.
1 def MH(lattice, e old, M):
2
4 for n in range(n steps):
5
6 x = np.random.randint(L)
7 y = np.random.randint(L)
8
9 lattice[x][y] *= -1.0
10
11 dM = mag(lattice,x,y)
12 Ee = calc energy step(lattice,x,y)
13 dE = Ee*2
14
15 if dE < 0:
5
16 e old += dE
17 M += dM
18
19 if n >= n steps/2:
20
21 E list.append(e old/L**2)
22 ...
23
24 elif np.exp(-dE/(kB*T)) >= random.random():
25
26 ...
27
28 else:
29 lattice[x][y] *= -1.0
30
31 return MH
Before the start of the nal loop which runs through a list of temperatures we
create some empty lists for our temperature plots and initialise the calculation
of the grids total energy. Within the temperature loop we initialise a couple of
empty list of the energy and magnetization for use in the Metropolis-Hastings
algorithm, which we initialise after calculating the total magnetization of the
system. After running through the MH algorithm we calculate heat capacity
and magnetic susceptibility and appends them and our magnetization to the
empty lists created for the temperature plots.
1 for T in T list:
2 E list = []
3 ...
4
5 M = (np.sum(lattice))/L**2
6
7 MH = MH(lattice, e old, M)
8
9 Cv = heat capacity(E list, Esq list)
10 X = magsus(M list, Msq list)
11
12 MT list.append(M)
13 Cv list.append(Cv)
14 X list.append(X)
The last section of our code is split in two and creates our plots. It checks
with an If statement, which graf to plot as was detemined by our switch in the
beginning of our code.
4 Results and Discussion
The size of the grid, the length of the simulation, and the burn in period we
wait before actually saving our data is very important to take into consideration
6
Figure 2: A plot of the magnetization versus the iteration steps, at the temper-
ature: T = 1.0
to ensure the precission of our model. Logically we can conclude that we have
to run the simulation much longer on a bigger grid compared to a smaller one,
if want want to ensure that the correct values are achieved. This is because of
the fact that each iteration step only ip one random spin component around
each iteration and that the simulation therefor must run longer to achieve the
right distribution.
In the beginning of our simulation the lattice will be dened as completely
random. But such a random system does not tell us any usefull information
about the physical system of the two dimensional magnetic solid which we are
modelling. We therefor must wait a burn-in period such that the system can
achieve some sort of stability before we begin measurering it. Naturally the
burn-in period will depend on both the size of the lattice and in some small
part on the used temperature which determines the acceptance-behavior of the
changes in the system. It is hence quite hard to determine an appropiate burn-
in period for the system because of the random factor. But there is no harm
in just overshooting and choose a higher burn-in period then necesary, as long
as our simulation runs long enough after the end of the period to achieve the
correct distribution and thereby the correct mean of the physical properties
which we are studying. The only limit here is the speed in which we can run
our simulation.
We rst ran our simulation at three dierent temperatures around the crit-
ical one: T = 1.0, T
c
= 2.269, and T = 3.5 to observe the behaviour of both
the magnetization versus the iteration steps and the energy versus the iteration
steps. As seen in the Figures 2 to 7. The grafs show that the behavior of the
magnitization follows the one theorised in the theory section. For the low tem-
perature case of T = 1 we see that the magnitization stabilises at approximately
-1, while it strongly uctuates around the value of 0 in the high temperature
case of T = 3.5. These uctuations areroughly equel on either side of 0 and
the mean value is therefor approximately 0. In the critical temperature case of
T
c
= 2.269 we can observe that the magnetization of the spins randomly ips
from -1 to 1 and back again. This is a characteristic property of the critical
temperature and is due to the system having just enough extra energy through
7
Figure 3: A plot of the magnetization versus the iteration steps, at the temper-
ature: T = 2.269
Figure 4: A plot of the magnetization versus the iteration steps, at the temper-
ature: T = 3.5
Figure 5: A plot of the energy versus the iteration steps, at the temperature: T
= 1.0
8
Figure 6: A plot of the energy versus the iteration steps, at the critical temper-
ature: T
c
= 2.269
Figure 7: A plot of the energy versus the iteration steps, at the temperature: T
= 3.5
9
Figure 8: A plot of the heat capacity as a function of the temperature.
Figure 9: A plot of the magnetization as a function of the temperature.
the temperature, to being able to ip the magnetization, but not enough to
be capable of ignoring the more stable state of aligned spin. This is reected
through the energy plots, which shows that the average energy levels for the
critical temperature lies approximately between the two other cases.
The plots of the physical properties shows approximately the anticipated
behavior around the critical temperature. The best result we got in the lim-
ited amount of times we ran the simulation is probably the graf of the mag-
netizations tempareture dependency, which immediately after crossing the T
c
approaches zero from its origion at -1. The graf of the heat capacity tops at
approximately the right critical temperature, but the peak is far from sharp
enough to conclude anything more from that, other than the fact that we seem
to have a substantial statistical variation in our simulation. The graf of the
magnetic susceptibility is likewise far from ideal. It seems to start increasing at
T
c
and then peak at about 0.5 T above the T
c
.
10
Figure 10: A plot of the magnetic susceptibility as a function of the temperature.
5 Conclusion
Isings model of a magnetic solid was succesfully simulated in python. The tem-
pareture dependence of the magnetization, the heat capacity, and the magnetic
susceptibility was studied through analysis of the plots from our simulation. It
was found that the graf approximately showed a divergence around the criti-
cal temperature t
c
=2.269 but with an substantial variance. The study of the
magnetization/energy versus iteration step plot illustrated how it is possible at
the critical temperature to ip back and forth between values of 1 to -1 mag-
netization. The next step in an eventuel continuation of this project could be
to extend the model to three or more dimensions and or incorperate some real
models for solid crystal lattices.
11

Das könnte Ihnen auch gefallen