Professional Documents
Culture Documents
VSOP19 Thanh p2
VSOP19 Thanh p2
VSOP19 Thanh p2
Lecture notes
PDF files : http://iop.vast.ac.vn/~nvthanh/cours/vsop/
Example code : http://iop.vast.ac.vn/~nvthanh/cours/vsop/code/
II.1. The spin models
Introduction
Spin model = spin kind + lattice structure (with including the dimension)
Spin kinds :
Ising
XY
Heisenberg
Lattice structure :
Simple cubic (SC)
Body center cubic (BCC)
Face center cubic (FCC)
Stacked triangular (hexagonal)
…
n : number of conponent
n = 0 : The Self-Avoiding Walks
n = 1 : Ising model
n = 2 : XY model
n = 3 : Heisenberg model
exchange interaction J
: Ferromagnetic interaction
: Antiferromagnetic interaction
: Spin glass
The sum is taken over
nearest neighbours spin pair
next nearest neighbours spin pair …
Ising spin model
The hamiltonian
(2.2)
(2.3)
The energy
(2.4)
XY spin model
This is the special case of the n-vector model, for n = 2
The hamiltonian
(2.5)
(2.7)
Heisenberg spin model
This is the special case of the n-vector model, for n = 3
The hamiltonian with
(2.8)
(2.10)
(2.11)
II.2. Boundary conditions
Periodic boundary condition (PBC)
Free boundary condition
Using for a thin-film geometry
Applying the free boundary condition on z-direction only
Use PBC on (x, y) plane
film thickness
II.3. Simple sampling Monte Carlo methods
Comparisons of methods for numerical integration of given functions:
Simple methods
Consider a definite integral
(2.12)
(2.13)
0
a b x
Crude method
choose N values of x randomly, then calculate f(x)
(2.14)
Intelligent methods :
control variate method
(2.15)
where
(2.16)
(2.17)
N0 : the initial number of nuclei, related to the ‘half-life’ of the system
Simulation
Dividing the time into discrete intervals
during the time interval, test for decay of each undecayed nucleus
Determine the number of undecayed nuclei
Increasing the time step, then repeat the process
Program structure
N = N0 ; NP = N0
LOOP from (t = dt) to Tmax , step dt
LOOP from 1 to NP ! Loop over each remaining parent nucleus
R = uniform_RandomNumber()
! 0 R 1
IF ( R < λ dt ) THEN
N = N-1
END IF
END LOOP over nuclei
NP = N
Record t, N
END LOOP over time
Source : radioactive_decay.f90
PROGRAM RADIOACTIVE_DECAY
IMPLICIT NONE
REAL :: t,tmax,dt,r,lambda
INTEGER :: n,n0,np,nt,i
!
CALL RANDOM_SEED()
n0 = 1000; tmax = 50.0
dt = 0.1; lambda = 0.1
n = n0; t = 0.0
DO WHILE (t <= tmax .AND. n > 0)
t = t + dt
np = n
DO i = 1,np
CALL RANDOM_NUMBER(r)
IF (r < lambda*dt) n = n - 1
END DO
nt = NINT(n0*exp(-t*lambda))
print*,t,n,nt
END DO
END PROGRAM RADIOACTIVE_DECAY
Finding the groundstate of a hamiltonian
Consider a system of Ising spins
Algorithm
Randomly chosen an initial state of the system
Choose a random site on the lattice
Try to overturn the spin, determining the change in energy
if the energy is lowered, then accept the overturn of the spin
otherwise it is left unchanged, go to the next site.
(2.18)
: critical exponent
: non-universal constants
: correction to scaling exponent
The partition function
(2.19)
: an effective coordination number
Random walks (RW)
used for the description of diffusion phenomena
the end-to-end distance
(2.20)
DO i = 1 to ns ! number-of-samples
x = 0; y = 0 ! initial position
xp = 0; yp = 0 ! previous position
DO j = 1 to N ! number of step
repeat
xt = x; yt = y ! template position
generate-one-step (x; y)
until ((x xp) or (y yp))
xp = xt
yp = yt
ENDDO
accumulate-results
ENDDO
Source : nr_randomwalk.f90
PROGRAM NR_RANDOM_WALKS
IMPLICIT NONE
INTEGER, PARAMETER :: ns = 1000,n = 100
INTEGER :: i,j,x,y,id,xp,yp,xt,yt
REAL :: r,d,d2,temp
LOGICAL :: test
!
CALL RANDOM_SEED()
d = 0.0; d2 = 0.0
CALL NRRW() ! non-reversal random walks
d = d/float(ns); d2 = d2/float(ns)
print*,ns,n,d,d2
CONTAINS
SUBROUTINE NRRW
…
END SUBROUTINE NRRW
END PROGRAM NR_RANDOM_WALKS
SUBROUTINE NRRW
DO i=1,ns
x = 0; y = 0; xp = x; yp = y
DO j = 1,N
xt = x; yt = y; test = .FALSE.
DO WHILE(.NOT.test)
CALL RANDOM_NUMBER(r)
id = INT(r*4.0)
IF (id == 0) THEN
x = xt + 1; y = yt
ELSEIF (id == 1) THEN
x = xt - 1; y = yt
ELSEIF (id == 2) THEN
y = yt + 1; x = xt
ELSEIF (id == 3) THEN
y = yt - 1; x = xt
ENDIF
IF ((x .NE. xp).OR.(y .NE.yp)) test =.TRUE.
ENDDO
xp = xt; yp = yt
ENDDO
temp = float(x**2+y**2)
d = d + sqrt(temp); d2 = d2 + temp
ENDDO
END SUBROUTINE NRRW
Self-avoiding walks (SAW)
Used to probe the configurations of flexible
macromolecules in the solvents
The walker dies when attempting to intersect
a portion of the already completed walk
Simulations
Picking a starting point
Generating a random number to the different possible choices for the next
step
If the new site is one which already contains a portion of the walk, then
the process is terminated at the Nth step.
effective exponent
(2.21)
For , the effective exponent is then related to the true value
(2.22)
the current estimates for
(2.23)
(2.25)
Algorithm of Self-avoiding walks
integer lattice(-N:N;-N:N);
do sample = 1 to n-of-samples
step = 0;
x = 0; y = 0; xc = 0; yc = 0;
repeat
repeat
generate-one-step(xnew, ynew);
until lattice(xnew, ynew) sample + 1;
if lattice(xnew, ynew) = sample then
terminate = true
else
lattice(x, y) = sample;
x = xc; y = yc;
lattice(x, y) = sample + 1;
xc = xnew; yc = ynew;
step = step + 1;
endif
until (terminate or step = N);
accumulate-results
enddo
Source: sa_walk.f90
PROGRAM SELF_AVOIDING_WALKS
IMPLICIT NONE
INTEGER, PARAMETER :: ns = 100,n = 100
INTEGER, DIMENSION(-n:n,-n:n) :: lattice
INTEGER :: i,x,y,xt,yt,id,step,nn
REAL :: r,d,d2,temp
LOGICAL :: terminate,newsite
!
CALL RANDOM_SEED()
d = 0.0; d2 = 0.0
CALL SAW() ! self avoiding walks
d = d/float(ns); d2 = d2/float(ns)
print*,ns,n,d,d2
!
CONTAINS
SUBROUTINE SAW
…
END SUBROUTINE SAW
!
END PROGRAM SELF_AVOIDING_WALKS
SUBROUTINE SAW
DO i = 1,ns
lattice = 0
x = 0; y = 0
step = 0; terminate = .FALSE.
DO WHILE ((.NOT. terminate) .AND. (step <= n))
xt = x; yt = y
nn = lattice(x+1,y) + lattice(x-1,y) &
+ lattice(x,y+1) + lattice(x,y-1)
IF (nn == 4) THEN
terminate = .TRUE.
ELSE
newsite = .FALSE.
DO WHILE (.NOT. newsite)
CALL RANDOM_NUMBER(r)
id = INT(r*4.0)
IF (id == 0) THEN
x = xt + 1; y = yt
ELSEIF (id == 1) THEN
x = xt - 1; y = yt
ELSEIF (id == 2) THEN
y = yt + 1; x = xt
ELSEIF (id == 3) THEN
y = yt - 1; x = xt
ENDIF
IF (lattice(x,y) == 0) newsite = .TRUE.
ENDDO
step = step + 1
lattice(x,y) = 1
ENDIF
ENDDO
temp = float(x**2+y**2)
d = d + sqrt(temp)
d2 = d2 + temp
ENDDO
END SUBROUTINE SAW
Thermal Averages by the Simple Sampling Method
The model
Consider a polymer chain,
: attractive energy between two nearest neighbor monomers
Defination
The distribution
(2.26)
(2.27)
(2.28)
(2.29)
(2.30)
(2.31)
II.4. Importance sampling Monte Carlo methods
Introduction
used for the study of phase transitions at finite temperature
Consider a spin model, the Hamiltonian is given by
(2.32)
the averages
(2.33)
(2.34)
probability density
(2.35)
integrates Eq. (2.34) over all states with their proper weights
(2.36)
(2.37)
simple average
(2.38)
Algorithm (Metropolis method)
The configurations are generated from a previous state using a transition
probability which depends on the energy difference between the initial
and final states
The master equation of probability of the system
that is in the state n at time t
(2.39)
We have
(2.40)
The probability of the nth state occurring in a classical system
(2.41)
(2.42)
(2.43)
Ising model
SUBROUTINE monte_carlo_step
generate-one-sweep
END SUBROUTINE
Source : ising_2dsl.f90
Fortran code (ferromagnetic Ising spin model on 2D square lattice)
PROGRAM ISING_2D_SL
IMPLICIT NONE
INTEGER, PARAMETER :: n = 10,nms = n*n,nt = 20
REAL,DIMENSION(n,n) :: S
INTEGER :: i,j,ip,im,jp,jm,ie,ia,ms,it,neq,nav
REAL :: r,tmin,tmax,t,dt,e1,e2,temp
REAL :: ener,magn
!
CALL RANDOM_SEED()
neq = 2000
nav = 4000
tmin = 0.5; tmax = 4.0
dt = (tmax-tmin)/float(nt-1)
t = tmin
!
DO it = 1,nt
CALL spin_conf() ! initial configuration
CALL equilibrating() ! equilibrating process
ener = 0.0
magn = 0.0
CALL averaging() ! averaging process
ener = ener/float(nav)
magn = magn/float(nav)
print*, t,ener,magn
t = t + dt
ENDDO
CONTAINS ! list of subroutines/functions
…
END PROGRAM ISING_2D_SL
CONTAINS ! list of subroutines/functions
!
SUBROUTINE spin_conf
CALL RANDOM_NUMBER(S)
DO i = 1,n
DO j = 1,n
IF (S(i,j) > 0.5) THEN
S(i,j) = 1.0
ELSE
S(i,j) = -1.0
ENDIF
ENDDO
ENDDO
END SUBROUTINE spin_conf
!
SUBROUTINE equilibrating
DO ie = 1, neq
CALL monte_carlo_step()
ENDDO
END SUBROUTINE equilibrating
SUBROUTINE averaging
DO ia = 1, nav
CALL monte_carlo_step()
! Calculate the average energy per spin
temp = 0.0
DO i = 1,n
ip = i + 1; im = i - 1
IF (ip > n) ip = 1
IF (im < 1) im = n
DO j = 1,n
jp = j + 1; jm = j - 1
IF (jp > n) jp = 1
IF (jm < 1) jm = n
temp = temp -S(i,j)*&
(S(ip,j)+S(im,j)+S(i,jp)+S(i,jm))
ENDDO
ENDDO
ener = ener + 0.5*temp/float(n*n)
! Calculate the average magnetization per spin
temp = 0.0
DO i = 1,n
DO j = 1,n
temp = temp + S(i,j)
ENDDO
ENDDO
magn = magn + abs(temp)/float(n*n)
ENDDO
END SUBROUTINE averaging
SUBROUTINE monte_carlo_step
DO ms = 1,nms ! number of Monte Carlo step
CALL RANDOM_NUMBER(r)
i = INT(r*float(n))+1
CALL RANDOM_NUMBER(r)
j = INT(r*float(n))+1
! periodic boundary condition
ip = i + 1; im = i - 1
jp = j + 1; jm = j - 1
IF (ip > n) ip = 1
IF (im < 1) im = n
IF (jp > n) jp = 1
IF (jm < 1) jm = n
! calculate the different energy
e1 = -S(i,j)*(S(ip,j)+S(im,j)+S(i,jp)+S(i,jm))
e2 = -e1
CALL RANDOM_NUMBER(r)
IF (r < exp(-(e2-e1)/t)) S(i,j) = -S(i,j)
ENDDO
END SUBROUTINE monte_carlo_step
Ferromagnetic Ising spin model on square lattice
cv = float(n*n)*(ener2 – ener*ener)/t/t
chi = float(n*n)*(magn2 – magn*magn)/t
For the case of three dimensions simple cubic lattice
Local energy :
e1 = -S(i,j,k)*(S(ip,j,k)+S(im,j,k)+S(i,jp,k)+S(i,jm,k)
+S(i,j,kp)+S(i,j,km))
Ferromagnetic Ising spin model on square lattice
e1 = -SX(i,j)*(SX(ip,j)+SX(im,j)+SX(i,jp)+SX(i,jm))
-SY(i,j)*(SY(ip,j)+SY(im,j)+SY(i,jp)+SY(i,jm))
Generate a new XY spin with random orientation
CALL RANDOM_NUMBER(r)
PHI = 2.0*3.14159260*r ! orientation
SXN = COS(PHI)
SYN = SIN(PHI)
Source : xy_2dsl.f90
Fortran code (ferromagnetic XY spin model on square lattice)
PROGRAM XY_2D_SL
IMPLICIT NONE
REAL,PARAMETER:: pi2 = 2.0*3.1415926
INTEGER, PARAMETER :: n = 10,nms = n*n,nt = 20
REAL,DIMENSION(n,n) :: sx,sy
INTEGER :: i,j,ip,im,jp,jm,ie,ia,ms,it,neq,nav
REAL :: r,tmin,tmax,t,dt,e1,e2,si,phi,sxn,syn,temp
REAL :: sxt,syt,ener,magn
!
CALL RANDOM_SEED()
neq = 20000
nav = 40000
tmin = 0.1; tmax = 2.0
dt = (tmax-tmin)/float(nt-1)
t = tmin
!
DO it = 1,nt
CALL spin_conf() ! initial configuration
CALL equilibrating()
ener = 0.0; magn = 0.0
CALL averaging()
ener = ener/float(nav)
magn = magn/float(nav)
print*, t,ener,magn
t = t + dt
ENDDO
e1 = -SX(i,j)*(SX(ip,j)+SX(im,j)+SX(i,jp)+SX(i,jm))
-SY(i,j)*(SY(ip,j)+SY(im,j)+SY(i,jp)+SY(i,jm))
-SZ(i,j)*(SZ(ip,j)+SZ(im,j)+SZ(i,jp)+SZ(i,jm))
Generate a new Heisenberg spin with random module and orientation
CALL RANDOM_NUMBER(r)
PHI = 2.0*3.14159260*r ! orientation
CALL RANDOM_NUMBER(r)
SZN = 2.0*r-1.0 ! projection of SZ
SI = SQRT(1-SZN*SZN)
SXN = SI*COS(PHI)
SYN = SI*SIN(PHI)
For two dimensions triangular lattice