当前位置: 首页>>代码示例>>Golang>>正文


Golang chk.Vector函数代码示例

本文整理汇总了Golang中github.com/cpmech/gosl/chk.Vector函数的典型用法代码示例。如果您正苦于以下问题:Golang Vector函数的具体用法?Golang Vector怎么用?Golang Vector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Vector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Test_conv06

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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:35,代码来源:t_conversions_test.go

示例2: Test_mylab08

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})
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:27,代码来源:t_mylab_test.go

示例3: Test_mylab07

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})
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:26,代码来源:t_mylab_test.go

示例4: TestSPDsolve02

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})
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:28,代码来源:t_densesol_test.go

示例5: Test_basicgeom05

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")
	}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:35,代码来源:t_basicgeom_test.go

示例6: Test_mvMul01

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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:29,代码来源:t_matvecmul_test.go

示例7: TestMyLab04

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})

}
开发者ID:PatrickSchm,项目名称:gosl,代码行数:33,代码来源:t_mylab_test.go

示例8: Test_fileio01

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)
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:60,代码来源:t_fileio_test.go

示例9: Test_mylab01

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)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:55,代码来源:t_mylab_test.go

示例10: Test_fileio01

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)
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:55,代码来源:t_fileio_test.go

示例11: Test_eigenp00

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})
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:11,代码来源:t_eigenprojs_test.go

示例12: TestReadTable01

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})
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:13,代码来源:t_readtable_test.go

示例13: Test_sigini01

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)
	}
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:51,代码来源:t_u_test.go

示例14: Test_conv07

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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:14,代码来源:t_conversions_test.go

示例15: Test_sigini01

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)
	}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:50,代码来源:t_u_test.go


注:本文中的github.com/cpmech/gosl/chk.Vector函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。