示例#1
0
func randomSweep(im IsingModel, g mcrand.Generator, sweeps int) {
	for j := 0; j < sweeps; j++ {
		for i := 0; i < int(im.Sites()); i++ {
			site := uint32(float64(im.Sites()) * g.Next())
			im.TryToFlip(site, g)
		}
		im.EnergyHistogram().AddFloat(im.TotalEnergy())
	}
}
示例#2
0
func (g *Grid2D) TryToFlip(site uint32, gen mcrand.Generator) bool {
	E := g.intEnergy(site)
	dE := -2.0 * float64(E)

	if dE < 0 || gen.Next() < g.precalcTable[-E] {
		g.cells[site] = !g.cells[site]
		g.totalEnergy += dE
		if g.cells[site] {
			g.totalMag += 2.0
		} else {
			g.totalMag -= 2.0
		}
		return true
	}
	return false
}