from visual import * from random import * from math import * ##lattice length L=10 # create a list spin=[] for i in range(0,L): # add a new list for each element of original list # allows us to create a 2D lattice or array of spins spin.append([]) for j in range(0,L): # i and j now give lattice coordinates of spin object spin[i].append(sphere(pos=vector(i-L/2,j-L/2,0), radius=0.2,color=color.red,state=1)) ## set ratio of energy to thermal energy kT T=3.0 MAXITS=1000 ## code for loop over T goes in here ## remember to indent all following code after adding the T loop. for its in range(0,MAXITS): # simulation code to update configuration of spins using Monte Carlo # algorithm for i in range (0,L): for j in range (0,L): rate(200) #using periodic boundary conditions in 2D deltaE=(2.0/T)*spin[i][j].state*( spin[i][(j+1)%L].state+ spin[i][(j-1+L)%L].state+ spin[(i+1)%L][j].state+ spin[(i+L-1)%L][j].state ) if (exp(-deltaE)>random()): spin[i][j].state=-spin[i][j].state if (spin[i][j].state==1): spin[i][j].color=color.red else: spin[i][j].color=color.blue # end simulation part of code