Skip to content
Snippets Groups Projects
Commit 70367f69 authored by Angie Nicole Hernández Durán's avatar Angie Nicole Hernández Durán
Browse files

adding scripts

parent 73bdc71a
No related branches found
No related tags found
No related merge requests found
.ipynb_checkpoints/
__pycache__/
This diff is collapsed.
main.py 0 → 100644
import numpy as np
from timeit import default_timer as timer
#from parameters import *
from observables import *
#from metropolis import *
from sampling import *
T = np.linspace(t_min, t_max, nt)
Ns = np.array(Ns)
for N in Ns:
start = timer()
result = finite_ising(N,mcSteps,eqSteps,T)
end = timer()
print('Time the code takes to run for a lattice sice of ' + str(N) + ': ' + str((end - start) / 60) + ' minutes.')
np.savetxt("data/data_ising_" + str(N) + ".csv" , result.T, delimiter=",")
\ No newline at end of file
import numpy as np
def pi_0(N):
Pi_0 = 2*np.random.randint(2 , size = (N,N)) - 1
return Pi_0
def MC_metropolis(arreglo, beta, N):
for i in range(0, 2 * N**2):
a, b = np.random.randint(0,N), np.random.randint(0,N)
rand_spin = arreglo[a, b]
vecinos = arreglo[(a+1)%N, b] + arreglo[a, (b+1)%N] + arreglo[(a-1)%N, b] + arreglo[a, (b-1)%N]
delta_energia = 2 * rand_spin * vecinos
if delta_energia < 0:
arreglo[a,b] *= -1
elif np.random.uniform(0,1) < np.exp(-delta_energia*beta):
arreglo[a,b] *= -1
return arreglo
\ No newline at end of file
import numpy as np
def energia(arreglo, N):
energia = 0
for i in range(0,N):
for j in range(0,N):
spin = arreglo[i,j]
vecinos = arreglo[(i+1)%N, j] + arreglo[i, (j+1)%N] + arreglo[(i-1)%N, j] + arreglo[i, (j-1)%N]
energia += - spin * vecinos
return energia / 2
def magnetizacion(arreglo):
magnetizacion = np.sum(arreglo)
return abs(magnetizacion)
\ No newline at end of file
t_min = 1.0
t_max = 7.0
nt = 100
eqSteps = 100000
mcSteps = 10000
Ns = [5, 10, 20, 30]
\ No newline at end of file
import numpy as np
from parameters import *
from observables import *
from metropolis import *
def finite_ising(N,mcSteps,eqSteps,T):
nt = len(T)
E,M,C,X,U = np.zeros(nt), np.zeros(nt), np.zeros(nt), np.zeros(nt), np.zeros(nt)#, np.zeros(nt)
N2 = N*N
for t in range(nt):
E1 = M1 = E2 = M2 = M4 = 0
beta = 1.0/T[t]
arreglo = pi_0(N)
if t > 1.5 and t < 4.5:
eqSteps_p = 5*eqSteps
for i in range(eqSteps_p): # esto es supuestamente para llevarlo al equilibrio
arreglo = MC_metropolis(arreglo, beta, N)
#magn = magnetizacion(arreglo)
#energ = energia(arreglo)
#full_M.append(magn/N2)
#full_E.append(energ)
else:
for i in range(eqSteps): # esto es supuestamente para llevarlo al equilibrio
arreglo = MC_metropolis(arreglo, beta, N)
#magn = magnetizacion(arreglo)
#energ = energia(arreglo)
#full_M.append(magn/N2)
#full_E.append(energ)
for i in range(mcSteps): # y aquí supuestamente el sistema se está desenvolviendo en el equilibrio
arreglo = MC_metropolis(arreglo,beta, N)
energ = energia(arreglo, N)
magn = magnetizacion(arreglo)
E1 += energ
E2 += energ*energ
M1 += magn
M2 += magn*magn
M4 += magn*magn*magn*magn
#calculo de las cantidades promedio
E1_mean = E1 / mcSteps
E2_mean = E2 / mcSteps
M1_mean = M1 / mcSteps
M2_mean = M2 / mcSteps
M4_mean = M4 / mcSteps
# cálculo de las cantidades específicas
E[t] = E1_mean / N2
M[t] = M1_mean / N2
X[t] = beta * (M2_mean - M1_mean**2) / N2
C[t] = beta**2 * (E2_mean - E1_mean**2) / N2
# cálculo del cumulante
U[t] = 1 - M4_mean / (3 * M2_mean**2)
return np.array([T,E,M,X,C,U])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment