Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Images/MCS_diif_L.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions InitEnergy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def Ener(ising,L,J):
E=0
M=0
for i in range (L):
for j in range (L):
a,b,c,d=i+1,i-1,j+1,j-1
if i==L-1:
a=0
if i==0:
b=L-1
if j==L-1:
c=0
if j==0:
d=L-1

M+=ising[i][j]
E=E-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d]))
return (M,E)
35 changes: 35 additions & 0 deletions LatticeLen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
import matplotlib.pyplot as plt
from RandomSpin import randomIsing
from InitEnergy import Ener
from Montecarlo import MCS
T=1.4
J=1
Len=[]
for L in range(10,40,10):
ising=randomIsing(L)
M,E=Ener(ising,L,J)
print(M,E)
E*=0.5
N=100000
# ener=[]
mag=[]
for n in range(N):
ising,E,M=MCS(ising,L,T,J,E,M)
# enspin=E/(L*L)
Mspin=M/(L*L)

# ener.append(enspin)
mag.append(Mspin)

Len.append(mag)

num=np.arange(0,n+1,1)
plt.plot(num,Len[0],color='r',label='L=10')
plt.plot(num,Len[1],color='g',label='L=20')
plt.plot(num,Len[2],color='b',label='L=30')
plt.title('M/N vs MCS')
plt.xlabel('MCS')
plt.ylabel('M/N')
plt.legend()
plt.show()
36 changes: 36 additions & 0 deletions Montecarlo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
def MCS(ising,L,T,J,E,M):
for k in range(L):
for l in range (L):
r=np.random.uniform(0,1)
i=int(r*(L-1))
t=np.random.uniform(0,1)
j=int(t*(L-1))
a,b,c,d=i+1,i-1,j+1,j-1
if i==L-1:
a=0
if i==0:
b=L-1
if j==L-1:
c=0
if j==0:
d=L-1
Ei=-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d]))
ising[i][j]=-ising[i][j]
Ef=-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d]))
dE=Ef-Ei

if(dE<=0.0):
E+=dE
M+=(2.0*float(ising[i][j]))
else:
u=np.exp(-dE/T)
h=np.random.uniform(0,1)
if(h<u):
E+=dE
M+=(2.0*float(ising[i][j]))

else:
ising[i][j]=-ising[i][j]

return(ising,E,M)
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
# Ising Model
Ising model is a mathematical model to used to understant Ferromagnetism an its phase transition to paramagnetic behavior above critical temperature. This model consists
of a N fixed lattice sites arranged to form a n(n=1,2,3) dimensional array. Each of the lattice sites has a spin $S_i$ associated with it, which can take values +1 or -1.
of a N fixed lattice sites arranged to form a n(n=1,2,3) dimensional array. Each of the lattice sites has a spin $S_i$ associated with it, which can take values +1 or -1.
The entire configuration of spin { $S_i$ } can be used to determine the energy of the system which is given by the hamiltonian:

![Alt text](Images/Screenshot%20from%202024-02-06%2017-21-36-modified.png)

Here $\epsilon_{ij}$ is the interaction energy between nearest neighbour spin and H is the external magnetic field. We can simplify the problem by considering an isotropic interaction with a constant $\epsilon$. The hamiltonian becomes:

![Alt text](Images/Screenshot%20from%202024-02-06%2017-21-57-modified.png)

Given the energy we can find all the thermodynamic variables by finding the partition function given by:

![Alt text](Images/Screenshot%20from%202024-02-06%2017-21-57-modified%20(1).png)

The following thermodynamic quantities are to be found to understand the phase transitions from ferromagnetic to paramagnetic transition:

![Alt text](Images/Screenshot%20from%202024-02-06%2017-21-57-modified%20(3).png)

# Phase Transitions

The ferromagnetic to paramagnetic phase transition is a second order phase transition. When the temperature T
approaches the Curie temperature T,the magnetization M(T),which is the order parameter of the transition, continuously goes to zero. Above Tc, the spins point in different directions and their magnetic fields are canceled. This disordered configuration is
caused by the random thermal movement of the spins. The higher the temperature, the more difficult it is for any orderly arrangement of spins to be maintained.
But there is still interactions with the neighbours unlike a paramagnetic material. But when the temperature is lowered below critical temperature ( $T_c$ )the interactions become stronger then thermal
fluctuations and the spins align
spontaneously. Instead of canceling each other out, the
individual magnetic fields are added, producing a macroscopic
magnetic field.
13 changes: 13 additions & 0 deletions RandomSpin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np

def randomIsing(L):
ising=np.zeros((L,L),dtype=float)
for i in range(L):
for j in range(L):
p=np.random.uniform(0,1)
if (p<0.5):
ising[i][j]=-1
else:
ising[i][j]=1
return (ising)

Binary file added __pycache__/InitEnergy.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/Montecarlo.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/RandomSpin.cpython-38.pyc
Binary file not shown.
75 changes: 8 additions & 67 deletions montecarlo.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,27 @@
import numpy as np
import matplotlib.pyplot as plt
L=5
T=1
ising=np.zeros((L,L),dtype=float)

for i in range(L):
for j in range(L):
p=np.random.uniform(0,1)
if (p<0.5):
ising[i][j]=-1
else:
ising[i][j]=1

from RandomSpin import randomIsing
from InitEnergy import Ener
from Montecarlo import MCS
L=20
T=2.1
ising=randomIsing(L)
J=1
E=0
M=0
for i in range (L):
for j in range (L):
a,b,c,d=i+1,i-1,j+1,j-1
if i==L-1:
a=0
if i==0:
b=L-1
if j==L-1:
c=0
if j==0:
d=L-1

M+=ising[i][j]
E=E-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d]))
M,E=Ener(ising,L,J)
print(M,E)

E*=0.5

N=100000
ener=[]
mag=[]
for n in range(N):


for k in range(L):
for l in range (L):

r=np.random.uniform(0,1)
i=int(r*(L-1))
t=np.random.uniform(0,1)
j=int(t*(L-1))
a,b,c,d=i+1,i-1,j+1,j-1
if i==L-1:
a=0
if i==0:
b=L-1
if j==L-1:
c=0
if j==0:
d=L-1
Ei=-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d]))
ising[i][j]=-ising[i][j]
Ef=-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d]))
dE=Ef-Ei

if(dE<=0.0):
E+=dE
M+=(2.0*float(ising[i][j]))
else:
u=np.exp(-dE/T)
h=np.random.uniform(0,1)
if(h<u):
E+=dE
M+=(2.0*float(ising[i][j]))

else:
ising[i][j]=-ising[i][j]

ising,E,M=MCS(ising,L,T,J,E,M)
enspin=E/(L*L)
Mspin=M/(L*L)

ener.append(enspin)
mag.append(Mspin)
num=np.arange(0,n+1,1)
plt.plot(num,mag,linewidth=1)
# plt.plot(num,ener,linewidth=1)
plt.show()


Expand Down
1 change: 0 additions & 1 deletion pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
count=0
pi_value=[]
x_value=np.arange(0,iterations,1)

for i in range(iterations):
x1=x[i]
y1=y[i]
Expand Down
60 changes: 0 additions & 60 deletions test.py

This file was deleted.

43 changes: 0 additions & 43 deletions test2.py

This file was deleted.

49 changes: 0 additions & 49 deletions test3.py

This file was deleted.