Ejemplo n.º 1
0
func Test_conv06(tst *testing.T) {

	//verbose()
	chk.PrintTitle("conv06")

	a := [][]float64{
		{1, 2, 3},
		{4, 5, 6},
		{7, 8, 9},
		{10, 11, 12},
	}
	a_ := MatAlloc(4, 3)
	am := MatToColMaj(a)
	aa := ColMajToMatNew(am, 4, 3)
	ColMajToMat(a_, am)
	io.Pforan("a  = %v\n", a)
	io.Pforan("am = %v\n", am)
	io.Pforan("aa = %v\n", aa)
	chk.Vector(tst, "a => am", 1e-17, am, []float64{1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12})
	chk.Matrix(tst, "am => a", 1e-17, aa, a)
	chk.Matrix(tst, "am => a", 1e-17, a_, a)

	b := [][]float64{
		{1, 2, 3, 4},
		{5, 6, 7, 8},
		{9, 0, -1, -2},
	}
	bm := MatToColMaj(b)
	bb := ColMajToMatNew(bm, 3, 4)
	io.Pforan("b  = %v\n", b)
	io.Pforan("bm = %v\n", bm)
	io.Pforan("bb = %v\n", bb)
	chk.Vector(tst, "b => bm", 1e-15, bm, []float64{1, 5, 9, 2, 6, 0, 3, 7, -1, 4, 8, -2})
	chk.Matrix(tst, "bm => b", 1e-15, bb, b)
}
Ejemplo n.º 2
0
func Test_mylab08(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mylab08. dot and cross products")

	u := []float64{3, -3, 1}
	v := []float64{4, 9, 2}
	w := make([]float64, 3)
	s := Dot3d(u, v)
	Cross3d(w, u, v) // w := u cross v
	chk.Scalar(tst, "s = u dot v", 1e-17, s, -13)
	chk.Vector(tst, "w = u cross v", 1e-17, w, []float64{-15, -2, 39})

	u = []float64{3, -3, 1}
	v = []float64{-12, 12, -4}
	s = Dot3d(u, v)
	Cross3d(w, u, v) // w := u cross v
	chk.Scalar(tst, "s = u dot v", 1e-17, s, -76)
	chk.Vector(tst, "w = u cross v", 1e-17, w, []float64{0, 0, 0})

	u = []float64{3, 2, -2}
	v = []float64{1, 0, -5}
	s = Dot3d(u, v)
	Cross3d(w, u, v) // w := u cross v
	chk.Scalar(tst, "s = u dot v", 1e-17, s, 13)
	chk.Vector(tst, "w = u cross v", 1e-17, w, []float64{-10, 13, -2})
}
Ejemplo n.º 3
0
func Test_mylab07(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mylab07. get column")

	v := [][]float64{
		{1, 2, 3, 4},
		{-1, 2, 3, 0},
		{-1, 2, 1, 4},
		{1, -2, 3, 8},
		{1, 1, -3, 4},
		{0, 2, 9, -4},
	}

	x := DblsGetColumn(0, v)
	chk.Vector(tst, "v[:,0]", 1e-17, x, []float64{1, -1, -1, 1, 1, 0})

	x = DblsGetColumn(1, v)
	chk.Vector(tst, "v[:,1]", 1e-17, x, []float64{2, 2, 2, -2, 1, 2})

	x = DblsGetColumn(2, v)
	chk.Vector(tst, "v[:,2]", 1e-17, x, []float64{3, 3, 1, 3, -3, 9})

	x = DblsGetColumn(3, v)
	chk.Vector(tst, "v[:,3]", 1e-17, x, []float64{4, 0, 4, 8, 4, -4})
}
Ejemplo n.º 4
0
func TestSPDsolve02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("TestSPDsolve 02")

	a := [][]float64{
		{2, 1, 1, 3, 2},
		{1, 2, 2, 1, 1},
		{1, 2, 9, 1, 5},
		{3, 1, 1, 7, 1},
		{2, 1, 5, 1, 8},
	}
	b := []float64{-2, 4, 3, -5, 1}
	B := []float64{24, 29, 110, 12, 102}
	x := make([]float64, 5)
	X := make([]float64, 5)
	SPDsolve2(x, X, a, b, B)
	CheckResidR(tst, 1e-14, a, x, b)
	CheckResidR(tst, 1e-14, a, X, B)
	chk.Vector(tst, "x = inv(a) * b", 1e-13, x, []float64{
		-629.0 / 98.0,
		237.0 / 49.0,
		-53.0 / 49.0,
		62.0 / 49.0,
		23.0 / 14.0,
	})
	chk.Vector(tst, "X = inv(a) * B", 1e-13, X, []float64{0, 4, 7, -1, 8})
}
Ejemplo n.º 5
0
func Test_basicgeom05(tst *testing.T) {

	//verbose()
	chk.PrintTitle("basicgeom05")

	zero := 1e-1
	told := 1e-9
	tolin := 1e-3

	o := &Point{0, 0, 0}
	a := &Point{0.5, 0.5, 0.5}
	b := &Point{0.1, 0.5, 0.8}
	c := &Point{1, 1, 1}
	cmin, cmax := PointsLims([]*Point{o, a, b, c})
	chk.Vector(tst, "cmin", 1e-17, cmin, []float64{0, 0, 0})
	chk.Vector(tst, "cmax", 1e-17, cmax, []float64{1, 1, 1})
	if !IsPointIn(a, cmin, cmax, zero) {
		chk.Panic("a=%v must be in box")
	}
	if !IsPointIn(b, cmin, cmax, zero) {
		chk.Panic("b=%v must be in box")
	}
	if !IsPointIn(c, cmin, cmax, zero) {
		chk.Panic("c=%v must be in box")
	}

	p := &Point{0.5, 0.5, 0.5}
	q := &Point{1.5, 1.5, 1.5}
	if !IsPointInLine(p, o, c, zero, told, tolin) {
		chk.Panic("p=%v must be in line")
	}
	if IsPointInLine(q, o, c, zero, told, tolin) {
		chk.Panic("q=%v must not be in line")
	}
}
Ejemplo n.º 6
0
func Test_mvMul01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mvMul01. MatrixVector multiplication")

	a := [][]float64{
		{10.0, 20.0, 30.0, 40.0, 50.0},
		{1.0, 20.0, 3.0, 40.0, 5.0},
		{10.0, 2.0, 30.0, 4.0, 50.0},
	}
	u := []float64{0.5, 0.4, 0.3, 0.2, 0.1}
	r := []float64{0.5, 0.4, 0.3}
	z := []float64{1000, 1000, 1000}
	w := []float64{1000, 2000, 3000, 4000, 5000}
	au := make([]float64, 3)
	atr := make([]float64, 5)
	au_cor := []float64{35, 17.9, 20.6}
	atr_cor := []float64{8.4, 18.6, 25.2, 37.2, 42}
	zpau_cor := []float64{1035, 1017.9, 1020.6}
	wpar_cor := []float64{1008.4, 2018.6, 3025.2, 4037.2, 5042}
	MatVecMul(au, 1, a, u)     // au  = 1*a*u
	MatTrVecMul(atr, 1, a, r)  // atr = 1*transp(a)*r
	MatVecMulAdd(z, 1, a, u)   // z  += 1*a*u
	MatTrVecMulAdd(w, 1, a, r) // w  += 1*transp(a)*r
	chk.Vector(tst, "au", 1.0e-17, au, au_cor)
	chk.Vector(tst, "atr", 1.0e-17, atr, atr_cor)
	chk.Vector(tst, "zpau", 1.0e-12, z, zpau_cor)
	chk.Vector(tst, "wpar", 1.0e-12, w, wpar_cor)
}
Ejemplo n.º 7
0
func TestMyLab04(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mylab04")

	n := 5
	a := LinSpace(2.0, 3.0, n)
	δ := (3.0 - 2.0) / float64(n-1)
	r := make([]float64, n)
	for i := 0; i < n; i++ {
		r[i] = 2.0 + float64(i)*δ
	}
	io.Pf("δ = %v\n", δ)
	io.Pf("a = %v\n", a)
	io.Pf("r = %v\n", r)
	chk.Vector(tst, "linspace(2,3,5)", 1e-17, a, []float64{2.0, 2.25, 2.5, 2.75, 3.0})

	b := LinSpaceOpen(2.0, 3.0, n)
	Δ := (3.0 - 2.0) / float64(n)
	R := make([]float64, n)
	for i := 0; i < n; i++ {
		R[i] = 2.0 + float64(i)*Δ
	}
	io.Pf("Δ = %v\n", Δ)
	io.Pf("b = %v\n", b)
	io.Pf("R = %v\n", R)
	chk.Vector(tst, "linspace(2,3,5,open)", 1e-17, b, []float64{2.0, 2.2, 2.4, 2.6, 2.8})

	c := LinSpace(2.0, 3.0, 1)
	io.Pf("c = %v\n", c)
	chk.Vector(tst, "linspace(2,3,1)", 1e-17, c, []float64{2.0})

}
Ejemplo n.º 8
0
func Test_fileio01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fileio01")

	// start
	analysis := NewFEM("data/bh16.sim", "", true, false, false, false, chk.Verbose, 0)

	// domain A
	domsA := NewDomains(analysis.Sim, analysis.DynCfs, analysis.HydSta, 0, 1, false)
	if len(domsA) == 0 {
		tst.Errorf("NewDomains failed\n")
		return
	}
	domA := domsA[0]
	err := domA.SetStage(0)
	if err != nil {
		tst.Errorf("SetStage failed\n%v", err)
		return
	}
	for i, _ := range domA.Sol.Y {
		domA.Sol.Y[i] = float64(i)
	}
	io.Pforan("domA.Sol.Y = %v\n", domA.Sol.Y)

	// write file
	tidx := 123
	err = domA.SaveSol(tidx, true)
	if err != nil {
		tst.Errorf("SaveSol failed:\n%v", err)
		return
	}

	// domain B
	domsB := NewDomains(analysis.Sim, analysis.DynCfs, analysis.HydSta, 0, 1, false)
	if len(domsB) == 0 {
		tst.Errorf("NewDomains failed\n")
		return
	}
	domB := domsB[0]
	err = domB.SetStage(0)
	if err != nil {
		tst.Errorf("SetStage failed\n%v", err)
		return
	}
	io.Pfpink("domB.Sol.Y (before) = %v\n", domB.Sol.Y)

	// read file
	err = domB.ReadSol(analysis.Sim.DirOut, analysis.Sim.Key, analysis.Sim.EncType, tidx)
	if err != nil {
		tst.Errorf("ReadSol failed:\n%v", err)
		return
	}
	io.Pfgreen("domB.Sol.Y (after) = %v\n", domB.Sol.Y)

	// check
	chk.Vector(tst, "Y", 1e-17, domA.Sol.Y, domB.Sol.Y)
	chk.Vector(tst, "dy/dt", 1e-17, domA.Sol.Dydt, domB.Sol.Dydt)
	chk.Vector(tst, "d²y/dt²", 1e-17, domA.Sol.D2ydt2, domB.Sol.D2ydt2)
}
Ejemplo n.º 9
0
func Test_mylab01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mylab01")

	I := make([]int, 5)
	IntFill(I, 666)
	J := IntVals(5, 666)
	Js := StrVals(5, "666")
	M := IntsAlloc(3, 4)
	N := DblsAlloc(3, 4)
	S := StrsAlloc(2, 3)
	A := IntRange(-1)
	a := IntRange2(0, 0)
	b := IntRange2(0, 1)
	c := IntRange2(0, 5)
	C := IntRange3(0, -5, -1)
	d := IntRange2(2, 5)
	D := IntRange2(-2, 5)
	e := IntAddScalar(D, 2)
	f := DblOnes(5)
	ff := DblVals(5, 666)
	g := []int{1, 2, 3, 4, 3, 4, 2, 1, 1, 2, 3, 4, 4, 2, 3, 7, 8, 3, 8, 3, 9, 0, 11, 23, 1, 2, 32, 12, 4, 32, 4, 11, 37}
	h := IntUnique(g)
	G := []int{1, 2, 3, 38, 3, 5, 3, 1, 2, 15, 38, 1, 11}
	H := IntUnique(D, C, G, []int{16, 39})
	X, Y := MeshGrid2D(3, 6, 10, 20, 4, 3)
	P := [][]int{
		{1, 2, 3, 4, 5},
		{-1, -2, -3, -4, -5},
		{6, 7, 8, 9, 10},
	}
	Pc := IntsClone(P)
	chk.Ints(tst, "I", I, []int{666, 666, 666, 666, 666})
	chk.Ints(tst, "J", J, []int{666, 666, 666, 666, 666})
	chk.Strings(tst, "Js", Js, []string{"666", "666", "666", "666", "666"})
	chk.Ints(tst, "A", A, []int{})
	chk.Ints(tst, "a", a, []int{})
	chk.Ints(tst, "b", b, []int{0})
	chk.Ints(tst, "c", c, []int{0, 1, 2, 3, 4})
	chk.Ints(tst, "C", C, []int{0, -1, -2, -3, -4})
	chk.Ints(tst, "d", d, []int{2, 3, 4})
	chk.Ints(tst, "D", D, []int{-2, -1, 0, 1, 2, 3, 4})
	chk.Ints(tst, "e", e, []int{0, 1, 2, 3, 4, 5, 6})
	chk.Vector(tst, "f", 1e-16, f, []float64{1, 1, 1, 1, 1})
	chk.Vector(tst, "ff", 1e-16, ff, []float64{666, 666, 666, 666, 666})
	chk.Ints(tst, "h", h, []int{0, 1, 2, 3, 4, 7, 8, 9, 11, 12, 23, 32, 37})
	chk.Ints(tst, "H", H, []int{-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 11, 15, 16, 38, 39})
	chk.IntMat(tst, "M", M, [][]int{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}})
	chk.Matrix(tst, "N", 1e-17, N, [][]float64{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}})
	chk.Matrix(tst, "X", 1e-17, X, [][]float64{{3, 4, 5, 6}, {3, 4, 5, 6}, {3, 4, 5, 6}})
	chk.Matrix(tst, "Y", 1e-17, Y, [][]float64{{10, 10, 10, 10}, {15, 15, 15, 15}, {20, 20, 20, 20}})
	chk.StrMat(tst, "S", S, [][]string{{"", "", ""}, {"", "", ""}})
	chk.IntMat(tst, "Pc", Pc, P)
}
Ejemplo n.º 10
0
func Test_fileio01(tst *testing.T) {

	chk.PrintTitle("fileio01")

	// start
	if !Start("data/bh16.sim", true, chk.Verbose) {
		tst.Errorf("test failed\n")
	}
	defer End()

	// domain A
	distr := false
	domA := NewDomain(Global.Sim.Regions[0], distr)
	if domA == nil {
		tst.Errorf("test failed\n")
	}
	if !domA.SetStage(0, Global.Sim.Stages[0], distr) {
		tst.Errorf("test failed\n")
	}
	for i, _ := range domA.Sol.Y {
		domA.Sol.Y[i] = float64(i)
	}
	io.Pforan("domA.Sol.Y = %v\n", domA.Sol.Y)

	// write file
	tidx := 123
	if !domA.SaveSol(tidx) {
		tst.Errorf("test failed")
		return
	}
	dir, fnk := Global.Dirout, Global.Fnkey
	io.Pfblue2("file %v written\n", out_nod_path(dir, fnk, tidx, Global.Rank))

	// domain B
	domB := NewDomain(Global.Sim.Regions[0], distr)
	if domB == nil {
		tst.Errorf("test failed\n")
	}
	if !domB.SetStage(0, Global.Sim.Stages[0], distr) {
		tst.Errorf("test failed")
	}
	io.Pfpink("domB.Sol.Y (before) = %v\n", domB.Sol.Y)

	// read file
	if !domB.ReadSol(dir, fnk, tidx) {
		tst.Errorf("test failed")
		return
	}
	io.Pfgreen("domB.Sol.Y (after) = %v\n", domB.Sol.Y)

	// check
	chk.Vector(tst, "Y", 1e-17, domA.Sol.Y, domB.Sol.Y)
	chk.Vector(tst, "dy/dt", 1e-17, domA.Sol.Dydt, domB.Sol.Dydt)
	chk.Vector(tst, "d²y/dt²", 1e-17, domA.Sol.D2ydt2, domB.Sol.D2ydt2)
}
Ejemplo n.º 11
0
func Test_eigenp00(tst *testing.T) {

	//verbose()
	chk.PrintTitle("eigenp00")

	ncp := 6
	P := M_AllocEigenprojs(ncp)
	chk.Vector(tst, "P0", 1e-17, P[0], []float64{0, 0, 0, 0, 0, 0})
	chk.Vector(tst, "P1", 1e-17, P[1], []float64{0, 0, 0, 0, 0, 0})
	chk.Vector(tst, "P2", 1e-17, P[2], []float64{0, 0, 0, 0, 0, 0})
}
Ejemplo n.º 12
0
func TestReadTable01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("ReadTable 01")

	keys, res := ReadTableOrPanic("data/table01.dat")

	chk.Strings(tst, "keys", keys, []string{"a", "b", "c", "d"})
	chk.Vector(tst, "a", 1.0e-17, res["a"], []float64{1, 4, 7})
	chk.Vector(tst, "b", 1.0e-17, res["b"], []float64{2, 5, 8})
	chk.Vector(tst, "c", 1.0e-17, res["c"], []float64{3, 6, 9})
	chk.Vector(tst, "d", 1.0e-17, res["d"], []float64{666, 777, 641})
}
Ejemplo n.º 13
0
func Test_sigini01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("sigini01")

	// start simulation
	if !Start("data/sigini01.sim", true, chk.Verbose) {
		tst.Errorf("test failed\n")
		return
	}
	defer End()

	// run simulation
	if !Run() {
		tst.Errorf("test failed\n")
		return
	}

	// allocate domain
	distr := false
	d := NewDomain(Global.Sim.Regions[0], distr)
	if !d.SetStage(0, Global.Sim.Stages[0], distr) {
		tst.Errorf("SetStage failed\n")
		return
	}

	// check displacements
	tolu := 1e-16
	for _, n := range d.Nodes {
		eqx := n.GetEq("ux")
		eqy := n.GetEq("uy")
		u := []float64{d.Sol.Y[eqx], d.Sol.Y[eqy]}
		chk.Vector(tst, "u", tolu, u, nil)
	}

	// analytical solution
	qnV, qnH := -100.0, -50.0
	ν := 0.25
	σx, σy := qnH, qnV
	σz := ν * (σx + σy)
	σref := []float64{σx, σy, σz, 0}

	// check stresses
	e := d.Elems[0].(*ElemU)
	tols := 1e-13
	for idx, _ := range e.IpsElem {
		σ := e.States[idx].Sig
		io.Pforan("σ = %v\n", σ)
		chk.Vector(tst, "σ", tols, σ, σref)
	}
}
Ejemplo n.º 14
0
func Test_conv07(tst *testing.T) {

	//verbose()
	chk.PrintTitle("conv07")

	r := []float64{1, 2, 3, 4, 5, 6}
	c := []float64{0.1, 0.2, 0.3, 0.4, 0.5, 0.6}
	rc := RCtoComplex(r, c)
	chk.VectorC(tst, "rc", 1e-17, rc, []complex128{1 + 0.1i, 2 + 0.2i, 3 + 0.3i, 4 + 0.4i, 5 + 0.5i, 6 + 0.6i})

	R, C := ComplexToRC(rc)
	chk.Vector(tst, "r", 1e-17, R, r)
	chk.Vector(tst, "c", 1e-17, C, c)
}
Ejemplo n.º 15
0
func Test_sigini01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("sigini01. zero displacements. initial stresses")

	// fem
	analysis := NewFEM("data/sigini01.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 vectors
	err = analysis.ZeroStage(0, true)
	if err != nil {
		tst.Errorf("ZeroStage failed:\n%v", err)
		return
	}

	// domain
	dom := analysis.Domains[0]

	// check displacements
	tolu := 1e-16
	for _, n := range dom.Nodes {
		eqx := n.GetEq("ux")
		eqy := n.GetEq("uy")
		u := []float64{dom.Sol.Y[eqx], dom.Sol.Y[eqy]}
		chk.Vector(tst, "u", tolu, u, nil)
	}

	// analytical solution
	qnV, qnH := -100.0, -50.0
	ν := 0.25
	σx, σy := qnH, qnV
	σz := ν * (σx + σy)
	σref := []float64{σx, σy, σz, 0}

	// check stresses
	e := dom.Elems[0].(*ElemU)
	tols := 1e-13
	for idx, _ := range e.IpsElem {
		σ := e.States[idx].Sig
		io.Pforan("σ = %v\n", σ)
		chk.Vector(tst, "σ", tols, σ, σref)
	}
}
Ejemplo n.º 16
0
func Test_state01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("state01")

	nsig, nalp, large, nle := 4, 1, false, true
	state0 := NewState(nsig, nalp, large, nle)
	io.Pforan("state0 = %+v\n", state0)
	chk.Vector(tst, "sig", 1.0e-17, state0.Sig, []float64{0, 0, 0, 0})
	chk.Vector(tst, "alp", 1.0e-17, state0.Alp, []float64{0})
	chk.Vector(tst, "epsE", 1.0e-17, state0.EpsE, []float64{0, 0, 0, 0})

	state0.Sig[0] = 10.0
	state0.Sig[1] = 11.0
	state0.Sig[2] = 12.0
	state0.Sig[3] = 13.0
	state0.Alp[0] = 20.0

	state1 := NewState(nsig, nalp, large, nle)
	state1.Set(state0)
	io.Pforan("state1 = %+v\n", state1)
	chk.Vector(tst, "sig", 1.0e-17, state1.Sig, []float64{10, 11, 12, 13})
	chk.Vector(tst, "alp", 1.0e-17, state1.Alp, []float64{20})

	state2 := state1.GetCopy()
	io.Pforan("state2 = %+v\n", state2)
	chk.Vector(tst, "sig", 1.0e-17, state2.Sig, []float64{10, 11, 12, 13})
	chk.Vector(tst, "alp", 1.0e-17, state2.Alp, []float64{20})
	chk.Vector(tst, "epsE", 1.0e-17, state2.EpsE, []float64{0, 0, 0, 0})
}
Ejemplo n.º 17
0
func Test_smpinvs01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("smpinvs01")

	a, b, β, ϵ := -1.0, 0.5, 1e-3, 1e-3

	L := []float64{-8.0, -8.0, -8.0}
	N := make([]float64, 3)
	n := make([]float64, 3)
	m := SmpDirector(N, L, a, b, β, ϵ)
	SmpUnitDirector(n, m, N)
	io.Pforan("L = %v\n", L)
	io.Pforan("N = %v\n", N)
	io.Pforan("m = %v\n", m)
	io.Pforan("n = %v\n", n)
	chk.Vector(tst, "n", 1e-15, n, []float64{a / SQ3, a / SQ3, a / SQ3})

	p, q, err := GenInvs(L, n, a)
	if err != nil {
		chk.Panic("GenInvs failed:\n%v", err.Error())
	}
	io.Pforan("p = %v\n", p)
	io.Pforan("q = %v\n", q)
	if q < 0.0 || q > GENINVSQEPS {
		chk.Panic("q=%g is incorrect", q)
	}
	if math.Abs(p-a*L[0]) > 1e-14 {
		chk.Panic("p=%g is incorrect. err = %g", p, math.Abs(p-a*L[0]))
	}
}
Ejemplo n.º 18
0
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)
}
Ejemplo n.º 19
0
func TestSparseLA10(tst *testing.T) {

	//verbose()
	chk.PrintTitle("TestSparse LA10: SpTriMatTrVecMul")

	var a Triplet
	a.Init(3, 5, 15)
	a.Put(0, 0, 10.0)
	a.Put(0, 1, 20.0)
	a.Put(0, 2, 30.0)
	a.Put(0, 3, 40.0)
	a.Put(0, 4, 50.0)
	a.Put(1, 0, 1.0)
	a.Put(1, 1, 20.0)
	a.Put(1, 2, 3.0)
	a.Put(1, 3, 40.0)
	a.Put(1, 4, 5.0)
	a.Put(2, 0, 10.0)
	a.Put(2, 1, 2.0)
	a.Put(2, 2, 30.0)
	a.Put(2, 3, 4.0)
	a.Put(2, 4, 50.0)

	x := []float64{0.5, 0.4, 0.3}
	y := make([]float64, 5)
	SpTriMatTrVecMul(y, &a, x) // y := transpose(a) * x

	chk.Vector(tst, "y=Tr(a)*x", 1e-17, y, []float64{8.4, 18.6, 25.2, 37.2, 42})
}
Ejemplo n.º 20
0
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)
}
Ejemplo n.º 21
0
func TestReadTable01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("ReadTable 01")

	keys, res, err := ReadTable("data/table01.dat")
	if err != nil {
		tst.Errorf("file cannot be read:\n%v\n", err.Error())
	}

	chk.Strings(tst, "keys", keys, []string{"a", "b", "c", "d"})
	chk.Vector(tst, "a", 1.0e-17, res["a"], []float64{1, 4, 7})
	chk.Vector(tst, "b", 1.0e-17, res["b"], []float64{2, 5, 8})
	chk.Vector(tst, "c", 1.0e-17, res["c"], []float64{3, 6, 9})
	chk.Vector(tst, "d", 1.0e-17, res["d"], []float64{666, 777, 641})
}
Ejemplo n.º 22
0
func Test_jacobi01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("jacobi01")

	A := [][]float64{
		{1, 2, 3},
		{2, 3, 2},
		{3, 2, 2},
	}
	Q := MatAlloc(3, 3)
	v := make([]float64, 3)
	nit, err := Jacobi(Q, v, A)
	if err != nil {
		chk.Panic("Jacobi failed:\n%v", err)
	}
	io.Pforan("number of iterations = %v\n", nit)
	PrintMat("A", A, "%13.8f", false)
	PrintMat("Q", Q, "%13.8f", false)
	PrintVec("v", v, "%13.8f", false)

	chk.Matrix(tst, "Q", 1e-17, Q, [][]float64{
		{7.81993314738381295e-01, 5.26633230856907386e-01, 3.33382506832158143e-01},
		{-7.14394870018381645e-02, 6.07084171793832561e-01, -7.91419742017035133e-01},
		{-6.19179178753124115e-01, 5.95068272145819699e-01, 5.12358171676802088e-01},
	})
	chk.Vector(tst, "v", 1e-17, v, []float64{-1.55809924785903786e+00, 6.69537390404459476e+00, 8.62725343814443657e-01})
}
Ejemplo n.º 23
0
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])
	}
}
Ejemplo n.º 24
0
func Test_sort03(tst *testing.T) {

	//verbose()
	chk.PrintTitle("sort03")

	a, b, c := 8.0, -5.5, 4.0
	DblSort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{-5.5, 4, 8})
	DblDsort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{8, 4, -5.5})

	a, b, c = -18.0, -5.5, 4.0
	DblSort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{-18, -5.5, 4})
	DblDsort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{4, -5.5, -18})

	a, b, c = 1.0, 2.0, 3.0
	DblSort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{1, 2, 3})
	DblDsort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{3, 2, 1})

	a, b, c = 1.0, 3.0, 2.0
	DblSort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{1, 2, 3})
	DblDsort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{3, 2, 1})

	a, b, c = 3.0, 2.0, 1.0
	DblSort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{1, 2, 3})
	DblDsort3(&a, &b, &c)
	io.Pforan("a b c = %v %v %v\n", a, b, c)
	chk.Vector(tst, "a b c", 1e-16, []float64{a, b, c}, []float64{3, 2, 1})
}
Ejemplo n.º 25
0
func Test_split01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("split01")

	r := DblSplit(" 1e4 1 3   8   88   ")
	io.Pfblue2("r = %v\n", r)
	chk.Vector(tst, "r", 1e-16, r, []float64{1e4, 1, 3, 8, 88})
}
Ejemplo n.º 26
0
func Test_sort04(tst *testing.T) {

	//verbose()
	chk.PrintTitle("sort04")

	a := []float64{-3, -7, 8, 11, 3, 0, -11, 8}
	b := DblGetSorted(a)
	chk.Vector(tst, "a(sorted)", 1e-16, b, []float64{-11, -7, -3, 0, 3, 8, 8, 11})
}
Ejemplo n.º 27
0
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")
	}
}
Ejemplo n.º 28
0
func Test_copy01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("copy01")

	v := []float64{1, 2, 3, 4, 4, 5, 5, 6, 6, 6}
	w := DblCopy(v)
	io.Pfblue2("v = %v\n", v)
	chk.Vector(tst, "w==v", 1e-16, w, v)
}
Ejemplo n.º 29
0
func Test_conversions01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("conversions01")

	v := []float64{2.48140019424242e-08, 0.0014621532754275238, 5.558773630697262e-09, 3.0581358492226644e-08, 0.001096211253647636}
	s := Dbl2Str(v, "%.17e")
	w := Str2Dbl(s)
	chk.Vector(tst, "v => s => w", 1e-17, v, w)
}
Ejemplo n.º 30
0
func Test_basicgeom02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("basicgeom02. Vector")

	u := []float64{1, 2, 3}
	v := []float64{4, 5, 6}
	s := VecDot(u, v)
	r := VecNew(2, u)
	w := VecNewAdd(2, u, -3, v)
	io.Pforan("u = %v  norm = %g\n", u, VecNorm(u))
	io.Pforan("v = %v  norm = %g\n", v, VecNorm(v))
	io.Pforan("w = %v  norm = %g\n", w, VecNorm(w))
	io.Pforan("u.v = %v\n", s)
	chk.Scalar(tst, "u.v", 1e-17, s, 32.0)
	chk.Scalar(tst, "norm(u)", 1e-17, VecNorm(u), math.Sqrt(14.0))
	chk.Scalar(tst, "norm(v)", 1e-17, VecNorm(v), math.Sqrt(77.0))
	chk.Vector(tst, "r", 1e-17, r, []float64{2, 4, 6})
	chk.Vector(tst, "w", 1e-17, w, []float64{-10, -11, -12})
}