1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import math
import time
import random
import itertools
#produit scalaire
def prodscal(A,B):
if len(A)==2: #Si vecteur dans le plan, on rajoute la composante z
A+=[0]
if len(B)==2: #Si vecteur dans le plan, on rajoute la composante z
B+=[0]
return A[0]*B[0]+A[1]*B[1]+A[2]*B[2]
def convert(S):
if S[2]==0: #spins dans le plan => Angle en degres
return round(math.degrees(math.atan2(S[1],S[0])),2)
elif S[2]>0: #spins hors du plan => +1 si mz positive, -1 sinon
return +1
else:
return -1
###################################################################
# Calculs d'energie
##############################################################
def EnerInteracDip(P1,P2,val1,val2):
dr=[P1[0]-P2[0],P1[1]-P2[1]]
r=math.sqrt(dr[0]**2+dr[1]**2)
return -(3*prodscal(val1,dr)*prodscal(val2,dr)/r**5-prodscal(val1,val2)/r**3)
def MatInterDip(SpinValues,Points):
q=len(SpinValues)
nb_spin=len(Points)
#Creation de la matrice de couplage
Mat=[[[[ 0 for i in range(q)] for j in range(q)] for k in range(nb_spin)] for l in range(nb_spin)]
for i in range(nb_spin):
for j in range(nb_spin):
if i!=j:
for k in range(q):
for l in range(q):
Mat[i][j][k][l]=EnerInteracDip(Points[i],Points[j],SpinValues[k],SpinValues[l])
return Mat
def Energie(MatCoup,Config,SpinValues,Points):
"Calcul de l'energie de la Config (energie par spin)"
nb_spin=len(Points)
E=0
for i in range(nb_spin):
for j in range(i):
E+=MatCoup[i][j][Config[i]][Config[j]]
return E/nb_spin
#Definition du reseau
Points=[ [0,0], [0,1], [1,1], [1,0], [0.5,(math.sqrt(3)/2)+1], [0.5,-(math.sqrt(3)/2)] ]
#Definition du type de spins
SpinValues =[ [0,0,1], [0,0,-1] ]
#Liste des configurations
cl = list(itertools.product([0,1],repeat=6))
#Creation d'une matrice qui permet ensuite de calculer l'energie
Matrice=MatInterDip(SpinValues,Points)
for C in cl:
cv = [convert(SpinValues[val]) for val in C]
E = [Energie(Matrice,C,SpinValues,Points)]
print("Configuration=", cv,"\tEnergie=",E) |
Partager