func Test_serial02(tst *testing.T) { //verbose() chk.PrintTitle("serial02") A := [][][]float64{ {{1, 3, 4}, {6}, {232, 23, 292, 2023}, {2, 3}}, {{0}, {1}, {0}}, {{0, 5, 6, 8, 3, 0}}, } // serialize PrintDeep3("A", A) I, P, S := Deep3Serialize(A) Deep3GetInfo(I, P, S, true) // check serialization chk.Ints(tst, "I", I, []int{0, 0, 0, 0, 1, 1, 1, 2}) chk.Ints(tst, "P", P, []int{0, 3, 4, 8, 10, 11, 12, 13, 19}) chk.Vector(tst, "S", 1e-16, S, []float64{1, 3, 4, 6, 232, 23, 292, 2023, 2, 3, 0, 1, 0, 0, 5, 6, 8, 3, 0}) // deserialize B := Deep3Deserialize(I, P, S, false) PrintDeep3("B", B) // check deserialization chk.Deep3(tst, "A", 1e-16, A, B) }
func Test_intordmut01(tst *testing.T) { //verbose() chk.PrintTitle("intordmut01") var ops OpsData ops.SetDefault() ops.Pm = 1 rnd.Init(0) a := []int{1, 2, 3, 4, 5, 6, 7, 8} io.Pforan("before: a = %v\n", a) ops.OrdSti = []int{2, 5, 4} IntOrdMutation(a, 0, &ops) io.Pfcyan("after: a = %v\n", a) chk.Ints(tst, "a", a, []int{1, 2, 6, 7, 3, 4, 5, 8}) nums := utl.IntRange2(1, 9) sort.Ints(a) chk.Ints(tst, "asorted = 12345678", a, nums) a = []int{1, 2, 3, 4, 5, 6, 7, 8} io.Pforan("\nbefore: a = %v\n", a) ops.OrdSti = nil IntOrdMutation(a, 0, &ops) io.Pfcyan("after: a = %v\n", a) sort.Ints(a) chk.Ints(tst, "asorted = 12345678", a, nums) }
func checkinput(tst *testing.T, m *Mesh, nverts, ncells int, X [][]float64, vtags, ctags, parts []int, types []string, V [][]int, etags, ftags [][]int) { if len(m.Verts) != nverts { tst.Errorf("nverts is incorrect: %d != %d", len(m.Verts), nverts) return } if len(m.Cells) != ncells { tst.Errorf("ncells is incorrect: %d != %d", len(m.Cells), ncells) return } io.Pfyel("\nvertices:\n") for i, v := range m.Verts { io.Pf("%+v\n", v) chk.Vector(tst, io.Sf("vertex %2d: X", v.Id), 1e-15, v.X, X[v.Id]) if v.Tag != vtags[i] { tst.Errorf("vtag is incorrect: %d != %d", v.Tag, vtags[i]) return } } io.Pfyel("\ncells:\n") for i, c := range m.Cells { io.Pf("%+v\n", c) if c.Tag != ctags[i] { tst.Errorf("ctag is incorrect: %d != %d", c.Tag, ctags[i]) return } if c.Part != parts[i] { tst.Errorf("part is incorrect: %d != %d", c.Part, parts[i]) return } chk.String(tst, types[i], c.Type) chk.Ints(tst, io.Sf("cell %2d : V", c.Id), c.V, V[c.Id]) chk.Ints(tst, io.Sf("cell %2d : edgetags", c.Id), c.EdgeTags, etags[c.Id]) } }
func TestMyLab03b(tst *testing.T) { //verbose() chk.PrintTitle("mylab03b") a := []int{1, 2, 3, -1, -2, 0, 8, -3} b := IntFilter(a, func(i int) bool { if a[i] < 0 { return true } return false }) c := IntNegOut(a) io.Pf("a = %v\n", a) io.Pf("b = %v\n", b) io.Pf("c = %v\n", c) chk.Ints(tst, "b", b, []int{1, 2, 3, 0, 8}) chk.Ints(tst, "c", c, []int{1, 2, 3, 0, 8}) A := []float64{1, 2, 3, -1, -2, 0, 8, -3} s := DblSum(A) mi, ma := DblMinMax(A) io.Pf("A = %v\n", A) io.Pf("sum(A) = %v\n", s) io.Pf("min(A) = %v\n", mi) io.Pf("max(A) = %v\n", ma) chk.Scalar(tst, "sum(A)", 1e-17, s, 8) chk.Scalar(tst, "min(A)", 1e-17, mi, -3) chk.Scalar(tst, "max(A)", 1e-17, ma, 8) }
func Test_serial01(tst *testing.T) { //verbose() chk.PrintTitle("serial01") A := [][][]float64{ {{100, 101, 102}, {103}, {104, 105}}, {{106}, {107}}, {{108}, {109, 110}}, {{111}}, {{112, 113, 114, 115}, {116}, {117, 118}, {119, 120, 121}}, } // serialize PrintDeep3("A", A) I, P, S := Deep3Serialize(A) Deep3GetInfo(I, P, S, true) // check serialization chk.Ints(tst, "I", I, []int{0, 0, 0, 1, 1, 2, 2, 3, 4, 4, 4, 4}) chk.Ints(tst, "P", P, []int{0, 3, 4, 6, 7, 8, 9, 11, 12, 16, 17, 19, 22}) Scor := LinSpace(100, 121, 22) io.Pf("Scor = %v\n", Scor) chk.Vector(tst, "S", 1e-16, S, Scor) // deserialize B := Deep3Deserialize(I, P, S, false) PrintDeep3("B", B) // check deserialization chk.Deep3(tst, "A", 1e-16, A, B) }
func Test_munkres04(tst *testing.T) { //verbose() chk.PrintTitle("munkres04. row and column matrices") C := [][]float64{ {1.0}, {2.0}, {0.5}, {3.0}, {4.0}, } var mnk Munkres mnk.Init(len(C), len(C[0])) mnk.SetCostMatrix(C) mnk.Run() io.Pforan("links = %v\n", mnk.Links) io.Pforan("cost = %v (13938)\n", mnk.Cost) chk.Ints(tst, "links", mnk.Links, []int{-1, -1, 0, -1, -1}) chk.Scalar(tst, "cost", 1e-17, mnk.Cost, 0.5) C = [][]float64{ {1.0, 2.0, 0.5, 3.0, 4.0}, } mnk.Init(len(C), len(C[0])) mnk.SetCostMatrix(C) mnk.Run() io.Pforan("links = %v\n", mnk.Links) io.Pforan("cost = %v (13938)\n", mnk.Cost) chk.Ints(tst, "links", mnk.Links, []int{2}) chk.Scalar(tst, "cost", 1e-17, mnk.Cost, 0.5) }
func Test_ind02(tst *testing.T) { //verbose() chk.PrintTitle("ind02. copy into") rnd.Init(0) nbases := 1 A := get_individual(0, nbases) B := get_individual(1, nbases) fmts := map[string][]string{ "int": {"%2d", "%4d", "%5d"}, // ints "flt": {"%6g", "%6g", "%5g"}, // floats "str": {"%4s", "%2s", "%2s"}, // strings "key": {"%3x", "%3x", "%3x"}, // keys "byt": {"%4s", "%4s", "%4s"}, // bytes "fun": {"%3s", "%3s", "%3s"}, // funcs } io.Pfpink("A = %v\n", A.Output(fmts, false)) io.Pfcyan("B = %v\n", B.Output(fmts, false)) var ops OpsData ops.SetDefault() ops.Pc = 1.0 ops.Cuts = []int{1, 2} ops.Xrange = [][]float64{{0, 1}, {-20, 20}, {-300, 300}} a := A.GetCopy() b := A.GetCopy() IndCrossover(a, b, A, B, 0, &ops) io.Pforan("a = %v\n", a.Output(fmts, false)) io.Pfblue2("b = %v\n", b.Output(fmts, false)) chk.Ints(tst, "a.Ints ", a.Ints, []int{1, -20, 300}) chk.Ints(tst, "b.Ints ", b.Ints, []int{-1, 20, -300}) chk.Strings(tst, "a.Strings", a.Strings, []string{"abc", "Y", "c"}) chk.Strings(tst, "b.Strings", b.Strings, []string{"X", "b", "Z"}) // TODO: add other tests here io.Pf("\n") x := get_individual(0, nbases) x.Ovas = []float64{0, 0} x.Oors = []float64{0, 0, 0} io.Pfblue2("x = %v\n", x.Output(fmts, false)) B.CopyInto(x) chk.Scalar(tst, "ova0", 1e-17, x.Ovas[0], 200) chk.Scalar(tst, "ova1", 1e-17, x.Ovas[1], 100) chk.Scalar(tst, "oor0", 1e-17, x.Oors[0], 15) chk.Scalar(tst, "oor1", 1e-17, x.Oors[1], 25) chk.Scalar(tst, "oor2", 1e-17, x.Oors[2], 35) io.Pforan("x = %v\n", x.Output(fmts, false)) chk.String(tst, x.Output(fmts, false), B.Output(fmts, false)) }
func Test_bins02(tst *testing.T) { //verbose() chk.PrintTitle("bins02. find along line (2D)") // bins var bins Bins bins.Init([]float64{-0.2, -0.2}, []float64{0.8, 1.8}, 5) // fill bins structure maxit := 5 // number of entries ID := make([]int, maxit) for k := 0; k < maxit; k++ { x := float64(k) / float64(maxit) ID[k] = k err := bins.Append([]float64{x, 2*x + 0.2}, ID[k]) if err != nil { chk.Panic(err.Error()) } } // add more points to bins for i := 0; i < 5; i++ { err := bins.Append([]float64{float64(i) * 0.1, 1.8}, 100+i) if err != nil { chk.Panic(err.Error()) } } // message for _, bin := range bins.All { if bin != nil { io.Pf("%v\n", bin) } } // find points along diagonal ids := bins.FindAlongSegment([]float64{0.0, 0.2}, []float64{0.8, 1.8}, 1e-8) io.Pforan("ids = %v\n", ids) chk.Ints(tst, "ids", ids, ID) // find additional points ids = bins.FindAlongSegment([]float64{-0.2, 1.8}, []float64{0.8, 1.8}, 1e-8) io.Pfcyan("ids = %v\n", ids) chk.Ints(tst, "ids", ids, []int{100, 101, 102, 103, 104, 4}) // draw if chk.Verbose { plt.SetForPng(1, 500, 150) bins.Draw2d(true, true, true, true, map[int]bool{8: true, 9: true, 10: true}) plt.SetXnticks(15) plt.SetYnticks(15) plt.SaveD("/tmp/gosl/gm", "test_bins02.png") } }
func Test_sort07(tst *testing.T) { //verbose() chk.PrintTitle("sort07. sort 3 ints") x := []int{0, 10, 1, 3} IntSort3(&x[0], &x[1], &x[2]) chk.Ints(tst, "sort3(x)", x, []int{0, 1, 10, 3}) x = []int{0, 10, 1, 3} IntSort4(&x[0], &x[1], &x[2], &x[3]) chk.Ints(tst, "sort4(x)", x, []int{0, 1, 3, 10}) }
func Test_sort02(tst *testing.T) { //verbose() chk.PrintTitle("sort02") i := []int{33, 0, 7, 8} x := []float64{1000.33, 0, -77.7, 88.8} y := []float64{1e-5, 1e-7, 1e-2, 1e-9} z := []float64{-8000, -7000, 0, -1} io.Pforan("by 'i'\n") I, X, Y, Z, err := SortQuadruples(i, x, y, z, "i") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{0, 7, 8, 33}) chk.Vector(tst, "x", 1e-16, X, []float64{0, -77.7, 88.8, 1000.33}) chk.Vector(tst, "y", 1e-16, Y, []float64{1e-7, 1e-2, 1e-9, 1e-5}) chk.Vector(tst, "z", 1e-16, Z, []float64{-7000, 0, -1, -8000}) io.Pforan("by 'x'\n") I, X, Y, Z, err = SortQuadruples(i, x, y, z, "x") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{7, 0, 8, 33}) chk.Vector(tst, "x", 1e-16, X, []float64{-77.7, 0.0, 88.8, 1000.33}) chk.Vector(tst, "y", 1e-16, Y, []float64{1e-2, 1e-7, 1e-9, 1e-5}) chk.Vector(tst, "z", 1e-16, Z, []float64{0, -7000, -1, -8000}) io.Pforan("by 'y'\n") I, X, Y, Z, err = SortQuadruples(i, x, y, z, "y") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{8, 0, 33, 7}) chk.Vector(tst, "x", 1e-16, X, []float64{88.8, 0, 1000.33, -77.7}) chk.Vector(tst, "y", 1e-16, Y, []float64{1e-9, 1e-7, 1e-5, 1e-2}) chk.Vector(tst, "z", 1e-16, Z, []float64{-1, -7000, -8000, 0}) io.Pforan("by 'z'\n") I, X, Y, Z, err = SortQuadruples(i, x, y, z, "z") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{33, 0, 8, 7}) chk.Vector(tst, "x", 1e-16, X, []float64{1000.33, 0, 88.8, -77.7}) chk.Vector(tst, "y", 1e-16, Y, []float64{1e-5, 1e-7, 1e-9, 1e-2}) chk.Vector(tst, "z", 1e-16, Z, []float64{-8000, -7000, -1, 0}) }
func Test_sort01(tst *testing.T) { //verbose() chk.PrintTitle("sort01") i := []int{33, 0, 7, 8} x := []float64{1000.33, 0, -77.7, 88.8} io.Pforan("by 'i'\n") I, X, _, _, err := SortQuadruples(i, x, nil, nil, "i") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{0, 7, 8, 33}) chk.Vector(tst, "x", 1e-16, X, []float64{0, -77.7, 88.8, 1000.33}) io.Pforan("by 'x'\n") I, X, _, _, err = SortQuadruples(i, x, nil, nil, "x") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{7, 0, 8, 33}) chk.Vector(tst, "x", 1e-16, X, []float64{-77.7, 0.0, 88.8, 1000.33}) x = []float64{1000.33, 0, -77.7, 88.8} DblSort4(&x[0], &x[1], &x[2], &x[3]) io.Pforan("x = %v\n", x) chk.Vector(tst, "x", 1e-16, x, []float64{-77.7, 0.0, 88.8, 1000.33}) x = []float64{1, 10.33, 0, -8.7} DblSort4(&x[0], &x[1], &x[2], &x[3]) io.Pforan("x = %v\n", x) chk.Vector(tst, "x", 1e-16, x, []float64{-8.7, 0, 1, 10.33}) x = []float64{100.33, 10, -77.7, 8.8} DblSort4(&x[0], &x[1], &x[2], &x[3]) io.Pforan("x = %v\n", x) chk.Vector(tst, "x", 1e-16, x, []float64{-77.7, 8.8, 10, 100.33}) x = []float64{-10.33, 0, 7.7, -8.8} DblSort4(&x[0], &x[1], &x[2], &x[3]) io.Pforan("x = %v\n", x) chk.Vector(tst, "x", 1e-16, x, []float64{-10.33, -8.8, 0, 7.7}) x = []float64{-1000.33, 8, -177.7, 0.8} DblSort4(&x[0], &x[1], &x[2], &x[3]) io.Pforan("x = %v\n", x) chk.Vector(tst, "x", 1e-16, x, []float64{-1000.33, -177.7, 0.8, 8}) }
// Test for function FindAlongLine (2D) func Test_bins02(tst *testing.T) { //verbose() chk.PrintTitle("bins02") var bins Bins bins.Init([]float64{0, 0}, []float64{1, 1}, 10) // fill bins structure maxit := 10 // number of entries ID := make([]int, maxit) for k := 0; k < maxit; k++ { x := float64(k) / float64(maxit) ID[k] = k * 11 err := bins.Append([]float64{x, x}, ID[k]) if err != nil { chk.Panic(err.Error()) } } ids := bins.FindAlongLine([]float64{0, 0}, []float64{10, 10}, 0.0000001) io.Pforan("ids = %v\n", ids) chk.Ints(tst, "check FindAlongLine", ID, ids) }
func Test_bins03(tst *testing.T) { //verbose() chk.PrintTitle("bins03. find along line (3D)") // bins var bins Bins bins.Init([]float64{0, 0, 0}, []float64{10, 10, 10}, 10) // fill bins structure maxit := 10 // number of entries ID := make([]int, maxit) var err error for k := 0; k < maxit; k++ { x := float64(k) / float64(maxit) * 10 ID[k] = k * 11 err = bins.Append([]float64{x, x, x}, ID[k]) if err != nil { chk.Panic(err.Error()) } } // find points along diagonal ids := bins.FindAlongSegment([]float64{0, 0, 0}, []float64{10, 10, 10}, 0.0000001) io.Pforan("ids = %v\n", ids) chk.Ints(tst, "ids", ID, ids) }
func main() { mpi.Start(false) defer func() { mpi.Stop(false) }() if mpi.Rank() == 0 { io.PfYel("\nTest MPI 03\n") } if mpi.Size() != 3 { chk.Panic("this test needs 3 processors") } x := []int{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} n := len(x) id, sz := mpi.Rank(), mpi.Size() start, endp1 := (id*n)/sz, ((id+1)*n)/sz for i := start; i < endp1; i++ { x[i] = i } //io.Pforan("x = %v\n", x) // IntAllReduceMax w := make([]int, n) mpi.IntAllReduceMax(x, w) var tst testing.T chk.Ints(&tst, fmt.Sprintf("IntAllReduceMax: x @ proc # %d", id), x, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) //io.Pfred("x = %v\n", x) }
func Test_fourlayers01(tst *testing.T) { //verbose() chk.PrintTitle("fourlayers01") analysis := NewFEM("data/fourlayers.sim", "", true, false, false, false, chk.Verbose, 0) doms := NewDomains(analysis.Sim, analysis.DynCfs, analysis.HydSta, 0, 1, false) if len(doms) == 0 { tst.Errorf("NewDomains failed\n") return } dom := doms[0] io.Pforan("stage # 0\n") err := dom.SetStage(0) if err != nil { tst.Errorf("SetStage # 0 failed\n%v", err) return } nids, eqs := get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{1, 2, 14, 12, 0, 10}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 12, 2, 3, 4, 5, 6, 7, 13, 8, 9, 10, 11}) io.Pforan("stage # 1\n") err = dom.SetStage(1) if err != nil { tst.Errorf("SetStage # 1 failed\n%v", err) return } nids, eqs = get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{10, 12, 9, 6, 1, 2, 14, 0, 8}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 2, 3, 19, 4, 5, 20, 6, 7, 8, 9, 18, 10, 11, 12, 13, 14, 15, 16, 17}) io.Pforan("stage # 2\n") err = dom.SetStage(2) if err != nil { tst.Errorf("SetStage # 2 failed\n%v", err) return } nids, eqs = get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{10, 12, 9, 6, 1, 2, 14, 0, 7, 11, 8, 13}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 2, 3, 25, 4, 5, 26, 6, 7, 8, 9, 24, 10, 11, 12, 13, 14, 15, 16, 17, 27, 18, 19, 20, 21, 22, 23}) io.Pforan("stage # 3\n") err = dom.SetStage(3) if err != nil { tst.Errorf("SetStage # 3 failed\n%v", err) return } nids, eqs = get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{7, 13, 5, 4, 10, 12, 9, 6, 1, 2, 14, 11, 3, 0, 8}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 33, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 31, 12, 13, 32, 14, 15, 16, 17, 30, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}) }
func Test_delaunay01(tst *testing.T) { //verbose() chk.PrintTitle("delaunay01") // points X := []float64{0, 1, 1, 0, 0.5} Y := []float64{0, 0, 1, 1, 0.5} // generate V, C, err := Delaunay(X, Y, chk.Verbose) if err != nil { tst.Errorf("%v\n", err) return } // check xout := make([]float64, len(V)) yout := make([]float64, len(V)) for i, v := range V { io.Pforan("vert %2d : coords = %v\n", i, v) xout[i] = v[0] yout[i] = v[1] } chk.Vector(tst, "X", 1e-15, xout, X) chk.Vector(tst, "Y", 1e-15, yout, Y) for i, c := range C { io.Pforan("cell %2d : verts = %v\n", i, c) } chk.Ints(tst, "verts of cell 0", C[0], []int{3, 0, 4}) chk.Ints(tst, "verts of cell 1", C[1], []int{4, 1, 2}) chk.Ints(tst, "verts of cell 2", C[2], []int{1, 4, 0}) chk.Ints(tst, "verts of cell 3", C[3], []int{4, 2, 3}) // plot if chk.Verbose { plt.SetForPng(1, 300, 150) Draw(V, C, nil) plt.Equal() plt.AxisRange(-0.1, 1.1, -0.1, 1.1) plt.Gll("x", "y", "") plt.SaveD("/tmp/gosl/tri", "delaunay01.png") } }
func Test_sort06(tst *testing.T) { //verbose() chk.PrintTitle("sort06. int => ??? maps") a := map[int]bool{100: true, 101: false, 102: true, 10: false, 9: true, 8: false, 0: true} k := IntBoolMapSort(a) io.Pforan("sorted_keys(a) = %v\n", k) chk.Ints(tst, "k", k, []int{0, 8, 9, 10, 100, 101, 102}) }
func Test_nurbs04(tst *testing.T) { //verbose() chk.PrintTitle("nurbs04") // NURBS a := FactoryNurbs2dPlateHole() b := a.KrefineN(2, false) c := a.KrefineN(4, false) // tolerace for normalised space comparisons tol := 1e-7 // tags a_vt := tag_verts(a, tol) a_ct := map[string]int{ "0_0": -1, "0_1": -2, } b_vt := tag_verts(b, tol) c_vt := tag_verts(c, tol) // write .msh files WriteMshD("/tmp/gosl/gm", "m_nurbs04a", []*Nurbs{a}, a_vt, a_ct, tol) WriteMshD("/tmp/gosl/gm", "m_nurbs04b", []*Nurbs{b}, b_vt, nil, tol) WriteMshD("/tmp/gosl/gm", "m_nurbs04c", []*Nurbs{c}, c_vt, nil, tol) // read .msh file back and check a_read := ReadMsh("/tmp/gosl/gm/m_nurbs04a")[0] chk.IntAssert(a_read.gnd, a.gnd) chk.Ints(tst, "p", a.p, a_read.p) chk.Ints(tst, "n", a.n, a_read.n) chk.Deep4(tst, "Q", 1.0e-17, a.Q, a_read.Q) chk.IntMat(tst, "l2i", a.l2i, a_read.l2i) // plot if chk.Verbose { PlotNurbs("/tmp/gosl/gm", "nurbs04a.png", a_read, 41, true, nil) PlotTwoNurbs("/tmp/gosl/gm", "nurbs04b.png", a, b, 41, true, nil) PlotTwoNurbs("/tmp/gosl/gm", "nurbs04c.png", a, c, 41, true, nil) } }
func Test_hist01(tst *testing.T) { //verbose() chk.PrintTitle("hist01") lims := []float64{0, 1, 2, 3, 4, 5} hist := Histogram{Stations: lims} idx := hist.FindBin(-3.3) chk.IntAssert(idx, -1) idx = hist.FindBin(7.0) chk.IntAssert(idx, -1) for i, x := range lims { idx = hist.FindBin(x) io.Pforan("x=%g idx=%d\n", x, idx) if i < len(lims)-1 { chk.IntAssert(idx, i) } else { chk.IntAssert(idx, -1) } } idx = hist.FindBin(0.5) chk.IntAssert(idx, 0) idx = hist.FindBin(1.5) chk.IntAssert(idx, 1) idx = hist.FindBin(2.5) chk.IntAssert(idx, 2) idx = hist.FindBin(3.99999999999999) chk.IntAssert(idx, 3) idx = hist.FindBin(4.999999) chk.IntAssert(idx, 4) hist.Count([]float64{ 0, 0.1, 0.2, 0.3, 0.9, // 5 1, 1, 1, 1.2, 1.3, 1.4, 1.5, 1.99, // 8 2, 2.5, // 2 3, 3.5, // 2 4.1, 4.5, 4.9, // 3 -3, -2, -1, 5, 6, 7, 8, }, true) io.Pforan("counts = %v\n", hist.Counts) chk.Ints(tst, "counts", hist.Counts, []int{5, 8, 2, 2, 3}) labels := hist.GenLabels("%g") io.Pforan("labels = %v\n", labels) }
func Test_fourlayers01(tst *testing.T) { chk.PrintTitle("fourlayers01") if !Start("data/fourlayers.sim", true, chk.Verbose) { tst.Errorf("test failed\n") } defer End() distr := false dom := NewDomain(Global.Sim.Regions[0], distr) if dom == nil { tst.Errorf("test failed\n") return } io.Pforan("stage # 0\n") if !dom.SetStage(0, Global.Sim.Stages[0], distr) { tst.Errorf("test failed\n") return } nids, eqs := get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{1, 2, 14, 12, 0, 10}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 12, 2, 3, 4, 5, 6, 7, 13, 8, 9, 10, 11}) io.Pforan("stage # 1\n") if !dom.SetStage(1, Global.Sim.Stages[1], distr) { tst.Errorf("test failed\n") return } nids, eqs = get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{10, 12, 9, 6, 1, 2, 14, 0, 8}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 2, 3, 19, 4, 5, 20, 6, 7, 8, 9, 18, 10, 11, 12, 13, 14, 15, 16, 17}) io.Pforan("stage # 2\n") if !dom.SetStage(2, Global.Sim.Stages[2], distr) { tst.Errorf("test failed\n") return } nids, eqs = get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{10, 12, 9, 6, 1, 2, 14, 0, 7, 11, 8, 13}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 2, 3, 25, 4, 5, 26, 6, 7, 8, 9, 24, 10, 11, 12, 13, 14, 15, 16, 17, 27, 18, 19, 20, 21, 22, 23}) io.Pforan("stage # 3\n") if !dom.SetStage(3, Global.Sim.Stages[3], distr) { tst.Errorf("test failed\n") return } nids, eqs = get_nids_eqs(dom) chk.Ints(tst, "nids", nids, []int{7, 13, 5, 4, 10, 12, 9, 6, 1, 2, 14, 11, 3, 0, 8}) chk.Ints(tst, "eqs", eqs, []int{0, 1, 33, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 31, 12, 13, 32, 14, 15, 16, 17, 30, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}) }
func Test_nurbs04(tst *testing.T) { //verbose() chk.PrintTitle("nurbs04") ori := get_nurbs_A() nurbs := ori.KrefineN(3, false) if false { gm.PlotNurbs("/tmp/gofem", "tst_nurbs04", nurbs, 21, false, nil) } faces := nurbs.ExtractSurfaces() spans := nurbs.Elements() shape0 := GetShapeNurbs(nurbs, faces, spans[0]) chk.Ints(tst, "V0_0", shape0.FaceLocalVerts[0], []int{0, 1, 2}) chk.Ints(tst, "V0_1", shape0.FaceLocalVerts[1], []int{2, 5}) chk.Ints(tst, "V0_2", shape0.FaceLocalVerts[2], []int{3, 4, 5}) chk.Ints(tst, "V0_3", shape0.FaceLocalVerts[3], []int{0, 3}) }
func Test_nurbs03(tst *testing.T) { //verbose() chk.PrintTitle("nurbs03") // NURBS b := FactoryNurbs1dCurveA() elems := b.Elements() nbasis := b.GetElemNumBasis() io.Pforan("nbasis = %v\n", nbasis) chk.IntAssert(nbasis, 4) // orders := (3,) => nbasis = (3+1) = 4 // check basis and elements chk.Ints(tst, "elem[0]", elems[0], []int{3, 4}) chk.Ints(tst, "elem[1]", elems[1], []int{4, 5}) chk.Ints(tst, "elem[2]", elems[2], []int{5, 6}) chk.Ints(tst, "ibasis0", b.IndBasis(elems[0]), []int{0, 1, 2, 3}) chk.Ints(tst, "ibasis1", b.IndBasis(elems[1]), []int{1, 2, 3, 4}) chk.Ints(tst, "ibasis2", b.IndBasis(elems[2]), []int{2, 3, 4, 5}) // refine NURBS c := b.Krefine([][]float64{ {0.15, 0.5, 0.85}, }) // plot if chk.Verbose { PlotNurbs("/tmp/gosl/gm", "nurbs03a.png", b, 41, true, nil) PlotTwoNurbs("/tmp/gosl/gm", "nurbs03b.png", b, c, 41, true, nil) } }
func Test_pairs01(tst *testing.T) { //verbose() chk.PrintTitle("pairs01") selinds := []int{11, 9, 1, 10, 0, 8, 7, 7, 3, 5, 4, 2, 6, 6, 6, 12} ninds := len(selinds) A := make([]int, ninds/2) B := make([]int, ninds/2) FilterPairs(A, B, selinds) m, n := B[3], B[6] io.Pforan("A = %v\n", A) io.Pforan("B = %v\n", B) chk.Ints(tst, "A", A, []int{11, 1, 0, 7, 3, 4, 6, 6}) chk.Ints(tst, "B", B, []int{9, 10, 8, m, 5, 2, n, 12}) for i, a := range A { if B[i] == a { tst.Errorf("there are repeated values in A and B: a=%d, b=%d", a, B[i]) return } } }
func Test_GOshuffleInts01(tst *testing.T) { //verbose() chk.PrintTitle("GOshuffleInts01") Init(0) n := 10 nums := utl.IntRange(n) io.Pfgreen("before = %v\n", nums) IntShuffle(nums) io.Pfcyan("after = %v\n", nums) sort.Ints(nums) io.Pforan("sorted = %v\n", nums) chk.Ints(tst, "nums", nums, utl.IntRange(n)) shufled := IntGetShuffled(nums) io.Pfyel("shufled = %v\n", shufled) sort.Ints(shufled) chk.Ints(tst, "shufled", shufled, utl.IntRange(n)) }
func Test_frees01a(tst *testing.T) { //verbose() chk.PrintTitle("frees01a") // start simulation analysis := NewFEM("data/frees01.sim", "", true, false, false, false, chk.Verbose, 0) // set stage err := analysis.SetStage(0) if err != nil { tst.Errorf("SetStage failed:\n%v", err) return } // initialise solution vectros err = analysis.ZeroStage(0, true) if err != nil { tst.Errorf("ZeroStage failed:\n%v", err) return } // domain dom := analysis.Domains[0] // nodes and elements chk.IntAssert(len(dom.Nodes), 62) chk.IntAssert(len(dom.Elems), 15) // vertices with "fl" seepverts := map[int]bool{3: true, 45: true, 7: true, 49: true, 11: true, 53: true, 15: true, 57: true, 19: true, 61: true, 23: true} // check dofs var seepeqs []int for _, nod := range dom.Nodes { if seepverts[nod.Vert.Id] { chk.IntAssert(len(nod.Dofs), 2) seepeqs = append(seepeqs, nod.Dofs[1].Eq) } else { chk.IntAssert(len(nod.Dofs), 1) } } sort.Ints(seepeqs) io.Pforan("seepeqs = %v\n", seepeqs) chk.Ints(tst, "seepeqs", seepeqs, []int{14, 16, 19, 30, 32, 43, 45, 56, 58, 69, 71}) // check Fmap e2 := dom.Elems[2].(*ElemP) chk.Ints(tst, "e2.Fmap", e2.Fmap, []int{14, 16, 19}) e5 := dom.Elems[5].(*ElemP) chk.Ints(tst, "e5.Fmap", e5.Fmap, []int{16, 30, 32}) e8 := dom.Elems[8].(*ElemP) chk.Ints(tst, "e8.Fmap", e8.Fmap, []int{30, 43, 45}) e11 := dom.Elems[11].(*ElemP) chk.Ints(tst, "e11.Fmap", e11.Fmap, []int{43, 56, 58}) e14 := dom.Elems[14].(*ElemP) chk.Ints(tst, "e14.Fmap", e14.Fmap, []int{56, 69, 71}) }
func Test_frees01a(tst *testing.T) { // finalise analysis process and catch errors defer End() //verbose() chk.PrintTitle("frees01a") // start simulation if !Start("data/frees01.sim", true, chk.Verbose) { chk.Panic("cannot start FE simulation") } // domain distr := false dom := NewDomain(Global.Sim.Regions[0], distr) if dom == nil { chk.Panic("cannot run FE simulation") } // set stage if !dom.SetStage(0, Global.Sim.Stages[0], distr) { chk.Panic("cannot set stage\n") } // nodes and elements chk.IntAssert(len(dom.Nodes), 62) chk.IntAssert(len(dom.Elems), 15) // vertices with "fl" seepverts := map[int]bool{3: true, 45: true, 7: true, 49: true, 11: true, 53: true, 15: true, 57: true, 19: true, 61: true, 23: true} // check dofs var seepeqs []int for _, nod := range dom.Nodes { if seepverts[nod.Vert.Id] { chk.IntAssert(len(nod.Dofs), 2) seepeqs = append(seepeqs, nod.Dofs[1].Eq) } else { chk.IntAssert(len(nod.Dofs), 1) } } sort.Ints(seepeqs) io.Pforan("seepeqs = %v\n", seepeqs) chk.Ints(tst, "seepeqs", seepeqs, []int{14, 16, 19, 30, 32, 43, 45, 56, 58, 69, 71}) // check Fmap e2 := dom.Elems[2].(*ElemP) chk.Ints(tst, "e2.Fmap", e2.Fmap, []int{14, 16, 19}) e5 := dom.Elems[5].(*ElemP) chk.Ints(tst, "e5.Fmap", e5.Fmap, []int{16, 30, 32}) e8 := dom.Elems[8].(*ElemP) chk.Ints(tst, "e8.Fmap", e8.Fmap, []int{30, 43, 45}) e11 := dom.Elems[11].(*ElemP) chk.Ints(tst, "e11.Fmap", e11.Fmap, []int{43, 56, 58}) e14 := dom.Elems[14].(*ElemP) chk.Ints(tst, "e14.Fmap", e14.Fmap, []int{56, 69, 71}) }
func Test_parsing07(tst *testing.T) { //verbose() chk.PrintTitle("parsing07. float64 fields") str := "1.0 1111.11 2.0 3.0" res := SplitFloats(str) Pforan("floats = %v\n", res) chk.Vector(tst, "res", 1e-17, res, []float64{1, 1111.11, 2, 3}) str = "1 1111 2 3" ints := SplitInts(str) Pforan("ints = %v\n", ints) chk.Ints(tst, "res", ints, []int{1, 1111, 2, 3}) }
func Test_nurbs05(tst *testing.T) { //verbose() chk.PrintTitle("nurbs05") b := get_nurbs_A() elems := b.Elements() solE := [][]int{{2, 3, 1, 2}, {3, 4, 1, 2}, {4, 5, 1, 2}} solL := [][]int{{0, 1, 2, 5, 6, 7}, {1, 2, 3, 6, 7, 8}, {2, 3, 4, 7, 8, 9}} for k, e := range elems { L := b.IndBasis(e) io.Pforan("e=%v: L=%v\n", e, L) chk.Ints(tst, "span", e, solE[k]) chk.Ints(tst, "L", L, solL[k]) } if T_NURBS_SAVE { plt.SetForEps(0.7, 300) b.DrawCtrl2D(true) b.DrawElems2D(21, true, "", "") plt.Equal() plt.SaveD("/tmp/gosl", "t_nurbs05.eps") } }
func Test_sort01(tst *testing.T) { //verbose() chk.PrintTitle("sort01") i := []int{33, 0, 7, 8} x := []float64{1000.33, 0, -77.7, 88.8} io.Pforan("by 'i'\n") I, X, _, _, err := SortQuadruples(i, x, nil, nil, "i") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{0, 7, 8, 33}) chk.Vector(tst, "x", 1e-16, X, []float64{0, -77.7, 88.8, 1000.33}) io.Pforan("by 'x'\n") I, X, _, _, err = SortQuadruples(i, x, nil, nil, "x") if err != nil { tst.Errorf("%v\n", err) } chk.Ints(tst, "i", I, []int{7, 0, 8, 33}) chk.Vector(tst, "x", 1e-16, X, []float64{-77.7, 0.0, 88.8, 1000.33}) }
func Test_MTshuffleInts01(tst *testing.T) { //verbose() chk.PrintTitle("MTshuffleInts01. Mersenne Twister") Init(0) n := 10 nums := utl.IntRange(n) io.Pfgreen("before = %v\n", nums) MTintShuffle(nums) io.Pfcyan("after = %v\n", nums) sort.Ints(nums) io.Pforan("sorted = %v\n", nums) chk.Ints(tst, "nums", nums, utl.IntRange(n)) }