Пример #1
0
func main() {
	// Temperature-dependent curves:

	t := table.NewOutTable("Temp", "Energy", "Magnetization", "C", "Chi")
	im := ising.New(ising.Grid2DType, 16)

	t0 := time.Now()
	for temp := 0.0; temp < 5.0; temp += 0.1 {
		ising.Equilibriate(im, temp, 100)

		es := make([]float64, 100)
		ms := make([]float64, 100)

		for i := 0; i < len(es); i++ {
			ising.Equilibriate(im, temp, 1000/len(es))
			es[i] = ising.AverageEnergy(im)
			ms[i] = math.Abs(ising.AverageMag(im))
		}
		t.AddRow(temp, avg(es), avg(ms),
			16*16*variance(es)/temp/temp,
			16*16*variance(ms)/temp)
	}
	t1 := time.Now()

	t.Write(table.KeepHeader, "temp.table")
	println("ising seconds:", sec(t0, t1))

	// Hysteresis loop:

	t = table.NewOutTable("h", "Magnetization")
	temp := 2.15

	t2 := time.Now()

	im = ising.New(ising.Grid2DType, 32)

	update := func(mag float64) {
		im.SetMag(mag)
		ising.Equilibriate(im, temp, 20)
		t.AddRow(mag, ising.AverageMag(im), ising.AverageEnergy(im),
			ising.SpecificHeat(im), ising.Chi(im))
	}

	for mag := -1.5; mag <= 1.5; mag += 0.03 {
		update(mag)
	}
	for mag := 1.5; mag >= -1.5; mag -= 0.03 {
		update(mag)
	}

	t3 := time.Now()
	println("hysteresis seconds:", sec(t2, t3))

	t.Write(table.KeepHeader, "mag.table")
}
Пример #2
0
func main() {
	t := table.NewOutTable("Time Step", "C Correlation", "X Correlation")

	info := &ising.SweepInfo{
		ising.New(ising.Grid2DType, widthPow),
		ising.RandomSweep,
		mcrand.New(mcrand.GoCrypto, int64(time.Now().UnixNano())),
		temp,
	}

	stats := ising.SweepStatistics(info, initialSweeps, trials)

	fCs, _ := ising.Tau(stats.EHistory)
	fMags, _ := ising.Tau(stats.MagHistory)

	if len(fCs) < len(fMags) {
		for 0 < len(fMags)-len(fCs) {
			fCs = append(fCs, 0.0)
		}
	} else {
		for 0 < len(fCs)-len(fMags) {
			fMags = append(fMags, 0.0)
		}
	}

	info.Im.Print()

	println("Total steps:", len(fMags))

	for i := 0; i < len(fMags); i++ {
		t.AddRow(float64(i), fCs[i], fMags[i])
	}

	t.Write(table.KeepHeader, "tau.table")
}
Пример #3
0
func main() {
	fmt.Println("Run statistics:")
	fmt.Printf("  %15s %5d\n", "Grid Width", 1<<widthPow)
	fmt.Printf("  %15s %5d\n", "Initial Sweeps", initialSweeps)
	fmt.Printf("  %15s %5d\n", "Trial Sweeps", trials)
	fmt.Printf("  %15s %5d\n", "Runs", runs)
	fmt.Printf("  %15s %5d\n", "Plot Points", int(points))

	t0 := float64(time.Now().UnixNano())

	infos := make([]*ising.SweepInfo, runs)
	for i := 0; i < runs; i++ {
		infos[i] = &ising.SweepInfo{
			ising.New(ising.Grid2DType, widthPow),
			ising.RandomSweep,
			mcrand.New(mcrand.Xorshift, int64(time.Now().Nanosecond())),
			minTemp,
		}
	}

	t := table.NewOutTable("Temp", "Energy", "Mag", "S. Heat", "Chi")
	stats := make([]*ising.SweepStats, runs)

	print("Running simulation")
	for point := 0.0; point < points; point++ {
		print(".")

		for i, info := range infos {
			info.Temp = minTemp + (maxTemp-minTemp)*point/points
			stats[i] = ising.SweepStatistics(info, initialSweeps, trials)
		}

		stat := ising.AvgSweepStats(stats)

		t.AddRow(infos[0].Temp, stat.E, stat.Mag, stat.C, stat.X)
	}
	println()

	t.Write(table.KeepHeader, fmt.Sprintf("temp%d.table", 1<<widthPow))

	t1 := float64(time.Now().UnixNano())
	fmt.Printf("Run time: %.3gs\n", (t1-t0)/1e9)
}
Пример #4
0
// This is too monolithic and should be pruned.
func main() {
	sampleTemp := minSampleTemp

	maximumTable := table.NewOutTable("L", "1/L",
		"Critical Temperature", "Max Specific Heat", "Max Specific Heat Per Site")
	maximumTable.SetHeader(fmt.Sprintf("Created with %g trials per grid.",
		math.Pow(10, maxTrialsPow)))

	for widthPow := minPow; widthPow <= maxPow; widthPow++ {
		cols := make([]string, 1+2*(maxTrialsPow-minTrialsPow+1))
		cols[0] = "Temperature"

		fcols := make([][]float64, int((maxTemp-minTemp)/tempStep))
		for i := 0; i < len(fcols); i++ {
			fcols[i] = make([]float64, 1+2*(maxTrialsPow-minTrialsPow+1))
		}

		secs1 := 0.0
		secs2 := 0.0

		fmt.Printf("\n%d-Width Grid:\n", 1<<widthPow)
		for i := 0; i <= maxTrialsPow-minTrialsPow; i++ {
			trials := int(math.Pow(10, float64(minTrialsPow+i)))
			fmt.Printf("  Running %d trial suite\n", trials)

			cols[2*i+1] = fmt.Sprintf("E (%d)", trials)
			cols[2*i+2] = fmt.Sprintf("C (%d)", trials)

			info := &ising.SweepInfo{
				ising.New(ising.Grid2DType, uint32(widthPow)),
				ising.IterSweep,
				mcrand.New(mcrand.Xorshift, int64(time.Now().UnixNano())),
				sampleTemp,
			}

			t0 := time.Now().UnixNano()
			ising.SweepStatistics(info, initialSweeps, trials)
			t1 := time.Now().UnixNano()
			secs1 += float64(t1-t0) / 1e9

			h := info.Im.EnergyHistogram()

			minValidTemp, maxValidTemp := maxTemp, minTemp
			for j := 0; j < len(fcols); j++ {
				temp := minTemp + float64(j)*tempStep

				E := h.Energy(sampleTemp, temp)
				C := h.SpecificHeat(sampleTemp, temp)

				if !math.IsNaN(C) && !math.IsInf(C, 0) {
					if temp > maxValidTemp {
						maxValidTemp = temp
					}
					if temp < minValidTemp {
						minValidTemp = temp
					}
				}

				fcols[j][2*i+1] = E / float64(info.Im.Sites())
				fcols[j][2*i+2] = C / float64(info.Im.Sites())
			}

			if i+minTrialsPow == maxTrialsPow {
				tCrit := h.CriticalTemp(sampleTemp, minValidTemp, maxValidTemp)
				cCrit := h.SpecificHeat(sampleTemp, tCrit)
				maximumTable.AddRow(float64(int(1<<widthPow)),
					1.0/float64(int(1<<widthPow)), tCrit,
					cCrit, cCrit/float64(info.Im.Sites()))

				sampleTemp = tCrit
			}

			t2 := time.Now().UnixNano()
			secs2 += float64(t2-t1) / 1e9
		}

		headerString := fmt.Sprintf(
			"%16s: %g\n%16s: %d\n%16s: %d\n"+
				"%16s: %s\n%16s: %s\n%16s: %g\n%20s: %g",
			"Sample Temperature", sampleTemp,
			"Initial Sweeps", initialSweeps,
			"Width", 1<<widthPow,
			"Generator", "Xorshift",
			"Sweep Pattern", "IterSweep",
			"Total Sweep Time", secs1,
			"Total Histogram Time", secs2)

		t := table.NewOutTable(cols...)

		t.SetHeader(headerString)

		for i := 0; i < len(fcols); i++ {
			if !math.IsNaN(fcols[i][1]) {
				fcols[i][0] = minTemp + tempStep*float64(i)
				t.AddRow(fcols[i]...)
			}
		}

		t.Write(table.KeepHeader,
			fmt.Sprintf("tables/iter/hist-temp%d.table", 1<<widthPow))
	}

	maximumTable.Write(table.KeepHeader, "tables/iter/hist-maximum.table")
}