def __init__(self,beta,L): self.L = L self.beta = beta # Init exponential map self.exp_table = dict() for E in range(-4,5,2): self.exp_table[E] = math.exp(2*beta*E) # Init random spin configuration self.spins = [ [2*self.randint(2)-1 for j in range(L)] for i in range(L) ] # Init observables self.energy = alpsalea.RealObservable('E') self.magnetization = alpsalea.RealObservable('m') self.abs_magnetization = alpsalea.RealObservable('|m|')
def __init__(self, beta, L, model=None): # Init size and temp self.L = L self.beta = beta # Init random spin configuration self.spins = [[ spin.Spin(sx=0.0, sy=0.0, sz=2 * self.randint(2) - 1) for j in range(L) ] for i in range(L)] # Init observables self.energy = alpsalea.RealObservable('E') self.magnetization = alpsalea.RealObservable('m') self.abs_magnetization = alpsalea.RealObservable('|m|') self.magnetization_2 = alpsalea.RealObservable('m^2') self.magnetization_4 = alpsalea.RealObservable('m^4') self.accepted = 0 #============================================================================== # HAMILTONIANS #============================================================================== def isingH(spin, i, j): e = self.spins[(i-1+self.L)%self.L][j].sz +\ self.spins[(i+1)%self.L][j].sz +\ self.spins[i][(j-1+self.L)%self.L].sz +\ self.spins[i][(j+1)%self.L].sz e *= -spin.sz return e def antiIsingH(spin, i, j): e = self.spins[(i-1+self.L)%self.L][j].sz +\ self.spins[(i+1)%self.L][j].sz +\ self.spins[i][(j-1+self.L)%self.L].sz +\ self.spins[i][(j+1)%self.L].sz e *= spin.sz return e # currently not long-range. def dipoledipoleH(spin, i, j): rCutOff = 3 e = 0 for dx in range(-1, 2, 2): for dy in range(-1, 2, 2): if (dx * dx + dy * dy > rCutOff * rCutOff): #hard code for now. r = math.sqrt(dx * dx + dy * dy) rvec = spin.Spin(sx=dx, sy=dy, sz=0.0) e += self.spins[i][j].dot( self.spins[(i + dx) % self.L][(j + dy) % self.L]) e += (self.spins[i][j].dot(rvec)) * (self.spins[ (i + dx) % self.L][(j + dy) % self.L].dot(rvec)) e *= 1.0 / (r * r * r) return e #============================================================================== # SPIN MOVE / FLIP TYPES #============================================================================== def flip180(spinToFlip): return spin.Spin(sx=spinToFlip.sx, sy=spinToFlip.sy, sz=-spinToFlip.sz) self.Potts6LookUp = [[0, 0, 1], [0, 0, -1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]] def flipPotts6(spinToFlip): whichVector = self.randint(len(self.Potts6LookUp)) sx = self.Potts6LookUp[whichVector][0] sy = self.Potts6LookUp[whichVector][1] sz = self.Potts6LookUp[whichVector][2] return spin.Spin(sx=sx, sy=sy, sz=sz) if model == 'Ising': self.energyLocal = isingH self.flip = flip180 elif model == 'AntiFerroIsing': self.energyLocal = antiIsingH self.flip = flip180 elif model == 'dipole-dipole6': self.energyLocal = dipoledipoleH self.flip = flipPotts6