Skip to content
Browse files

grid iteration operation; skect of cluster analysis

  • Loading branch information...
1 parent 876d554 commit 7b960d0a2b7a4853f7e09ae6a4c56448e5f327eb @tflovorn committed
Showing with 75 additions and 19 deletions.
  1. +4 −0 README.md
  2. +1 −0 src/Makefile
  3. +35 −18 src/grid.go
  4. +19 −1 src/grid_test.go
  5. +16 −0 src/small_clusters.go
View
4 README.md
@@ -5,6 +5,10 @@ gsl-bin
libgsl0ldbl
libgsl0-dev
+To build on Fedora, requires:
+gsl
+gsl-devel
+
__Description of the model__
Ground state: atoms are all dimerized, which prevents long-range hopping.
View
1 src/Makefile
@@ -10,6 +10,7 @@ GOFILES=\
point.go\
point_set.go\
random.go\
+ small_clusters.go\
vector_sort.go
CGOFILES=\
matrix.go\
View
53 src/grid.go
@@ -104,6 +104,41 @@ func (g *Grid) Ly() int {
return len(g.data[0])
}
+// Get the grid value at (x, y). Panic if (x, y) is out of bounds.
+func (g *Grid) Get(p Point) bool {
+ g.CheckBounds(p)
+ return g.data[p.X()][p.Y()]
+}
+
+// Set the grid value at (x, y). Panic if (x, y) is out of bounds.
+func (g *Grid) Set(p Point, value bool) {
+ g.CheckBounds(p)
+ g.data[p.X()][p.Y()] = value
+}
+
+// Flip the grid value at (x, y). Panic if (x, y) is out of bounds.
+func (g *Grid) Toggle(p Point) {
+ g.CheckBounds(p)
+ g.Set(p, !g.Get(p))
+}
+
+// Turn this grid into the next one in sequence.
+func (g *Grid) NextGrid() os.Error {
+ p := Point{0, 0}
+ for p.y = 0; p.y < g.Ly(); p.y++ {
+ for p.x = 0; p.x < g.Lx(); p.x++ {
+ if !g.Get(p) {
+ g.Toggle(p)
+ return nil
+ } else {
+ g.Toggle(p)
+ }
+ }
+ }
+ // only get here if all points are true
+ return os.NewError("Grid iteration finished")
+}
+
// Return true if the point (x, y) is within the grid boundaries; return false
// otherwise.
func (g *Grid) InBounds(p Point) bool {
@@ -123,24 +158,6 @@ func (g *Grid) CheckBounds(p Point) bool {
return true
}
-// Get the grid value at (x, y). Panic if (x, y) is out of bounds.
-func (g *Grid) Get(p Point) bool {
- g.CheckBounds(p)
- return g.data[p.X()][p.Y()]
-}
-
-// Set the grid value at (x, y). Panic if (x, y) is out of bounds.
-func (g *Grid) Set(p Point, value bool) {
- g.CheckBounds(p)
- g.data[p.X()][p.Y()] = value
-}
-
-// Flip the grid value at (x, y). Panic if (x, y) is out of bounds.
-func (g *Grid) Toggle(p Point) {
- g.CheckBounds(p)
- g.Set(p, !g.Get(p))
-}
-
// Iterate over g, calling f at each site.
func (g *Grid) Iterate(f GridCallback) {
for x := 0; x < g.Lx(); x++ {
View
20 src/grid_test.go
@@ -2,8 +2,8 @@ package percolation
import (
"testing"
- /* for performance test
"math"
+ /* for performance test
"time"
"fmt"
*/
@@ -99,6 +99,24 @@ func TestRandomConstrainedGridCreation(t *testing.T) {
}
}
+// Does NextGrid produce the correct number of grids?
+func TestNextGridNumber(t *testing.T) {
+ L := 3
+ expectedNumGrids := int(math.Pow(2.0, float64(L*L)))
+ numGrids := 0
+ g := NewGridWithDims(L, L)
+ for {
+ err := g.NextGrid()
+ numGrids++
+ if err != nil {
+ break
+ }
+ }
+ if numGrids != expectedNumGrids {
+ t.Fatalf("g.NextGrid() did not produce the expected number of unique grids")
+ }
+}
+
/*
// The performance of AllClusters should scale linearly with the number of
// sites in the grid. Does it?
View
16 src/small_clusters.go
@@ -0,0 +1,16 @@
+package percolation
+
+func AnalyzeClusters(gridLength int, outputFilePath string) {
+ g := NewGridWithDims(gridLength, gridLength)
+ for {
+ // do grid analysis
+
+ // export analysis
+
+ // iterate grid
+ err := g.NextGrid()
+ if err != nil {
+ break
+ }
+ }
+}

0 comments on commit 7b960d0

Please sign in to comment.
Something went wrong with that request. Please try again.