Exemplo n.º 1
0
func Test_fun08(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun08. exc2")

	fun, err := New("exc2", []*Prm{
		&Prm{N: "ta", V: 5},
		&Prm{N: "a", V: 3},
		&Prm{N: "b", V: 0.2},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 7.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "exc2.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-10
	dtol := 1e-10
	dtol2 := 1e-10
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 2
0
func Test_fun10(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun10. rmp")

	fun, err := New("rmp", []*Prm{
		&Prm{N: "ta", V: 1},
		&Prm{N: "tb", V: 2},
		&Prm{N: "ca", V: 0.5},
		&Prm{N: "cb", V: -1.5},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 3.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "rmp.png", tmin, tmax, xcte, 4, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-10
	dtol := 1e-12
	dtol2 := 1e-17
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 3
0
func Test_fun06c(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun06c. pts")

	fun, err := New("pts", []*Prm{
		// T =                     0 0.05 0.1 0.2 0.3 0.5  0.75 1
		&Prm{N: "y=dt", Extra: "0.05 0.05 0.1 0.1 0.2 0.25 0.25 0"},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 1.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "ptsC.png", tmin, tmax, xcte, 8, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	tmin = 0.01
	tmax = 0.99
	sktol := 1e-10
	dtol := 1e-10
	dtol2 := 1e-10
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 10, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 4
0
func Test_fun06b(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun06b. pts")

	fun, err := New("pts", []*Prm{
		&Prm{N: "t0", V: 0.0}, {N: "y0", V: 0.50},
		&Prm{N: "dy", Extra: "-0.3  0  -0.15  -0.04  -0.01"},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 1.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "ptsB.png", tmin, tmax, xcte, 8, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	tmin = 0.01
	tmax = 0.99
	sktol := 1e-10
	dtol := 1e-10
	dtol2 := 1e-10
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 5
0
func Test_fun06a(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun06a. pts")

	fun, err := New("pts", []*Prm{
		&Prm{N: "t", V: 0.00}, {N: "y", V: 0.50},
		&Prm{N: "t", V: 1.00}, {N: "y", V: 0.20},
		&Prm{N: "t", V: 2.00}, {N: "y", V: 0.20},
		&Prm{N: "t", V: 3.00}, {N: "y", V: 0.05},
		&Prm{N: "t", V: 4.00}, {N: "y", V: 0.01},
		&Prm{N: "t", V: 5.00}, {N: "y", V: 0.00},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := -1.0
	tmax := 6.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "pts.png", tmin, tmax, xcte, 8, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	tmin = 0.01
	tmax = 4.99
	sktol := 1e-10
	dtol := 1e-10
	dtol2 := 1e-10
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 6
0
func Test_fun11(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun11. ref-inc-rl1")

	fun, err := New("ref-inc-rl1", []*Prm{
		&Prm{N: "lam0", V: 0.001},
		&Prm{N: "lam1", V: 1.2},
		&Prm{N: "alp", V: 0.01},
		&Prm{N: "bet", V: 10},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 1.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "ref-inc-rl1.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-10
	dtol := 1e-10
	dtol2 := 1e-10
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 7
0
func Test_fun13(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun13. pulse")

	pulse, err := New("pulse", []*Prm{
		&Prm{N: "ca", V: 0.2},
		&Prm{N: "cb", V: 2.0},
		&Prm{N: "ta", V: 1.0},
		&Prm{N: "tb", V: 2.5},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 5.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(pulse, "/tmp/gosl/fun", "pulse.png", tmin, tmax, xcte, 61, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-17
	dtol := 1e-10
	dtol2 := 1e-10
	ver := chk.Verbose
	tskip := []float64{1, 4}
	CheckDerivT(tst, pulse, tmin, tmax, xcte, 11, tskip, sktol, dtol, dtol2, ver)
}
Exemplo n.º 8
0
func main() {

	// options
	verbose := false

	// start analysis process
	out.Start("spo754.sim", 0, 0)

	// all nodes
	out.Define("all nodes", out.AllNodes())
	out.Define("A", out.At{0, 5})

	// load results
	out.LoadResults(nil)

	// check
	skipK := true
	tolK := 1e-17
	tolu := 1e-11
	tols := 1e-04

	var tst testing.T
	fem.TestingCompareResultsU(&tst, "spo754.sim", "spo754.cmp", "", tolK, tolu, tols, skipK, verbose)

	// save
	plt.SetForPng(0.8, 400, 200)
	out.Splot("Plot")
	out.Plot("uy", "t", "A", plt.Fmt{C: "r", M: "o"}, -1)
	out.Draw("/tmp", "spo754.png", false, nil)
}
Exemplo n.º 9
0
func main() {

	// filename
	filename, fnkey := io.ArgToFilename(0, "rjoint01", ".sim", true)

	// results
	out.Start(filename, 0, 0)
	out.Define("p0", out.P{{-3, 0}}) // -3=tag, first ip
	out.Define("p1", out.P{{-3, 1}}) // -3=tag, second ip
	out.Define("p2", out.P{{-3, 2}}) // -3=tag, third ip
	out.LoadResults(nil)
	mtau0 := out.GetRes("tau", "p0", -1)
	mtau1 := out.GetRes("tau", "p1", -1)
	mtau2 := out.GetRes("tau", "p2", -1)
	for i := 0; i < len(out.Times); i++ {
		mtau0[i] *= -1
		mtau1[i] *= -1
		mtau2[i] *= -1
	}

	// plot FEM results
	out.Plot("ompb", mtau0, "p0", plt.Fmt{C: "r", Ls: "-", M: "."}, -1)
	out.Plot("ompb", mtau1, "p1", plt.Fmt{C: "g", Ls: "-", M: "."}, -1)
	out.Plot("ompb", mtau2, "p2", plt.Fmt{C: "b", Ls: "-", M: "."}, -1)
	out.Csplot.Ylbl = "$-\\tau$"

	// save
	plt.SetForPng(0.8, 400, 200)
	out.Draw("/tmp", fnkey+".png", false, nil)
}
Exemplo n.º 10
0
// PlotTwoNurbs plots two NURBS for comparison
func PlotTwoNurbs(dirout, fn string, b, c *Nurbs, npts int, ids bool, extra func()) {
	plt.Reset()
	if io.FnExt(fn) == ".eps" {
		plt.SetForEps(1.5, 500)
	} else {
		plt.SetForPng(1.5, 500, 150)
	}

	plt.Subplot(3, 1, 1)
	b.DrawCtrl2d(ids, "", "")
	b.DrawElems2d(npts, ids, "", "")
	if extra != nil {
		extra()
	}
	plt.Equal()

	plt.Subplot(3, 1, 2)
	c.DrawCtrl2d(ids, "", "")
	c.DrawElems2d(npts, ids, "", "")
	plt.Equal()

	plt.Subplot(3, 1, 3)
	b.DrawElems2d(npts, ids, ", lw=3", "")
	c.DrawElems2d(npts, ids, ", color='red', marker='+', markevery=10", "color='green', size=7, va='bottom'")
	plt.Equal()

	plt.SaveD(dirout, fn)
}
Exemplo n.º 11
0
func Test_fun16(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun16. cut-sin; test cut negative values.")

	fun, err := New("cut-sin", []*Prm{
		&Prm{N: "a", V: 10},
		&Prm{N: "b", V: math.Pi},
		&Prm{N: "c", V: 1.0},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 2.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(fun, "/tmp/gosl/fun", "cut-sin-negative.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-10
	dtol := 1e-8
	dtol2 := 1e-7
	ver := chk.Verbose
	CheckDerivT(tst, fun, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
}
Exemplo n.º 12
0
func Test_tri01(tst *testing.T) {

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

	V := [][]float64{
		{0.0, 0.0},
		{1.0, 0.0},
		{1.0, 1.0},
		{0.0, 1.0},
		{0.5, 0.5},
	}

	C := [][]int{
		{0, 1, 4},
		{1, 2, 4},
		{2, 3, 4},
		{3, 0, 4},
	}

	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", "tri01.png")
	}
}
Exemplo n.º 13
0
func main() {

	// filename
	filename, fnkey := io.ArgToFilename(0, "sg111", ".sim", true)

	// results
	out.Start(filename, 0, 0)
	out.Define("tip", out.N{1})
	out.LoadResults(nil)

	// plot FEM results
	out.Plot("t", "uy", "tip", plt.Fmt{C: "r", Ls: "None", M: ".", L: "gofem"}, -1)

	// analytical solution
	tAna := utl.LinSpace(0, 5, 101)
	uyAna := make([]float64, len(tAna))
	for i, t := range tAna {
		uyAna[i] = solution_uy(t, 1.0)
	}

	// save
	plt.SetForPng(0.8, 400, 200)
	out.Draw("/tmp", fnkey+".png", false, func(i, j, n int) {
		plt.Plot(tAna, uyAna, "'g-', clip_on=0, label='analytical'")
	})
}
Exemplo n.º 14
0
func main() {

	// filename
	filename, fnkey := io.ArgToFilename(0, "sg111", ".sim", true)

	// fem
	if !fem.Start(filename, false, false, false) {
		io.PfRed("Start failed\n")
		return
	}
	dom, sum, ok := fem.AllocSetAndInit(0, true, true)
	if !ok {
		io.PfRed("AllocSetAndInit failed\n")
		return
	}

	// selected node and dof index
	nidx := 1
	didx := 1

	// gofem
	ntout := len(sum.OutTimes)
	uy := make([]float64, ntout)
	for tidx, _ := range sum.OutTimes {

		// read results from file
		if !dom.In(sum, tidx, true) {
			io.PfRed("plot_spo751: cannot read solution\n")
			return
		}

		// collect results for load versus time plot
		nod := dom.Nodes[nidx]
		eq := nod.Dofs[didx].Eq
		uy[tidx] = dom.Sol.Y[eq]

		// check
		if math.Abs(dom.Sol.T-sum.OutTimes[tidx]) > 1e-14 {
			io.PfRed("output times do not match time in solution array\n")
			return
		}
	}

	// plot fem results
	plt.SetForPng(0.8, 400, 200)
	plt.Plot(sum.OutTimes, uy, "'ro-', clip_on=0, label='gofem'")

	// analytical solution
	tAna := utl.LinSpace(0, 5, 101)
	uyAna := make([]float64, len(tAna))
	for i, t := range tAna {
		uyAna[i] = solution_uy(t, 1.0)
	}
	plt.Plot(tAna, uyAna, "'g-', clip_on=0, label='analytical'")

	// save
	plt.Gll("$t$", "$u_y$", "")
	plt.SaveD("/tmp", fnkey+".png")
}
Exemplo n.º 15
0
func main() {

	// input data
	fn, fnk := io.ArgToFilename(0, "nurbs01", ".msh", true)
	ctrl := io.ArgToBool(1, true)
	ids := io.ArgToBool(2, true)
	useminmax := io.ArgToBool(3, false)
	axisequal := io.ArgToBool(4, true)
	xmin := io.ArgToFloat(5, 0)
	xmax := io.ArgToFloat(6, 0)
	ymin := io.ArgToFloat(7, 0)
	ymax := io.ArgToFloat(8, 0)
	eps := io.ArgToBool(9, false)
	npts := io.ArgToInt(10, 41)

	// print input table
	io.Pf("\n%s\n", io.ArgsTable("INPUT ARGUMENTS",
		"mesh filename", "fn", fn,
		"show control points", "ctrl", ctrl,
		"show ids", "ids", ids,
		"use xmin,xmax,ymin,ymax", "useminmax", useminmax,
		"enforce axis.equal", "axisequal", axisequal,
		"min(x)", "xmin", xmin,
		"max(x)", "xmax", xmax,
		"min(y)", "ymin", ymin,
		"max(y)", "ymax", ymax,
		"generate eps instead of png", "eps", eps,
		"number of divisions", "npts", npts,
	))

	// load nurbss
	B := gm.ReadMsh(fnk)

	// plot
	if eps {
		plt.SetForEps(0.75, 500)
	} else {
		plt.SetForPng(0.75, 500, 150)
	}
	for _, b := range B {
		if ctrl {
			b.DrawCtrl2d(ids, "", "")
		}
		b.DrawElems2d(npts, ids, "", "")
	}
	if axisequal {
		plt.Equal()
	}
	if useminmax {
		plt.AxisRange(xmin, xmax, ymin, ymax)
	}
	ext := ".png"
	if eps {
		ext = ".eps"
	}
	plt.Save(fnk + ext)
}
Exemplo n.º 16
0
func Test_bspline01(tst *testing.T) {

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

	var s1 Bspline
	T1 := []float64{0, 0, 0, 1, 1, 1}
	s1.Init(T1, 2)
	s1.SetControl([][]float64{{0, 0}, {0.5, 1}, {1, 0}})

	var s2 Bspline
	T2 := []float64{0, 0, 0, 0.5, 1, 1, 1}
	s2.Init(T2, 2)
	s2.SetControl([][]float64{{0, 0}, {0.25, 0.5}, {0.75, 0.5}, {1, 0}})

	if chk.Verbose {
		npts := 201
		plt.SetForPng(1.5, 600, 150)
		plt.SplotGap(0.2, 0.4)

		str0 := ",lw=2"
		str1 := ",ls='none',marker='+',color='cyan',markevery=10"
		str2 := ",ls='none',marker='x',markevery=10"
		str3 := ",ls='none',marker='+',markevery=10"
		str4 := ",ls='none',marker='4',markevery=10"

		plt.Subplot(3, 2, 1)
		s1.Draw2d(str0, "", npts, 0) // 0 => CalcBasis
		s1.Draw2d(str1, "", npts, 1) // 1 => RecursiveBasis

		plt.Subplot(3, 2, 2)
		plt.SetAxis(0, 1, 0, 1)
		s2.Draw2d(str0, "", npts, 0) // 0 => CalcBasis
		s2.Draw2d(str1, "", npts, 1) // 1 => RecursiveBasis

		plt.Subplot(3, 2, 3)
		s1.PlotBasis("", npts, 0)   // 0 => CalcBasis
		s1.PlotBasis(str2, npts, 1) // 1 => CalcBasisAndDerivs
		s1.PlotBasis(str3, npts, 2) // 2 => RecursiveBasis

		plt.Subplot(3, 2, 4)
		s2.PlotBasis("", npts, 0)   // 0 => CalcBasis
		s2.PlotBasis(str2, npts, 1) // 1 => CalcBasisAndDerivs
		s2.PlotBasis(str3, npts, 2) // 2 => RecursiveBasis

		plt.Subplot(3, 2, 5)
		s1.PlotDerivs("", npts, 0)   // 0 => CalcBasisAndDerivs
		s1.PlotDerivs(str4, npts, 1) // 1 => NumericalDeriv

		plt.Subplot(3, 2, 6)
		s2.PlotDerivs("", npts, 0)   // 0 => CalcBasisAndDerivs
		s2.PlotDerivs(str4, npts, 1) // 1 => NumericalDeriv

		plt.SaveD("/tmp/gosl/gm", "bspline01.png")
	}
}
Exemplo n.º 17
0
func Test_fun03(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun03. add, cte, srmps")

	cte, err := New("cte", []*Prm{&Prm{N: "c", V: 30}})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	srmps, err := New("srmps", []*Prm{
		&Prm{N: "ca", V: 0},
		&Prm{N: "cb", V: 1},
		&Prm{N: "ta", V: 0},
		&Prm{N: "tb", V: 1},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	add, err := New("add", []*Prm{
		&Prm{N: "a", V: 1},
		&Prm{N: "b", V: 1},
		&Prm{N: "fa", Fcn: cte},
		&Prm{N: "fb", Fcn: srmps},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 1.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(cte, "/tmp/gosl/fun", "cte.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
		plt.Clf()
		PlotT(srmps, "/tmp/gosl/fun", "srmps.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
		plt.Clf()
		PlotT(add, "/tmp/gosl/fun", "add.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-10
	dtol := 1e-10
	dtol2 := 1e-9
	ver := chk.Verbose
	tskip := []float64{tmin, tmax}
	CheckDerivT(tst, cte, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
	io.Pf("\n")
	CheckDerivT(tst, srmps, tmin, tmax, xcte, 11, tskip, sktol, dtol, dtol2, ver)
	io.Pf("\n")
	CheckDerivT(tst, add, tmin, tmax, xcte, 11, tskip, sktol, dtol, dtol2, ver)
}
Exemplo n.º 18
0
func Test_fun12(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun12. mul")

	cos, err := New("cos", []*Prm{
		&Prm{N: "a", V: 1},
		&Prm{N: "b/pi", V: 2},
		&Prm{N: "c", V: 1},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	lin, err := New("lin", []*Prm{
		&Prm{N: "m", V: 0.5},
		&Prm{N: "ts", V: 0},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	mul, err := New("mul", []*Prm{
		&Prm{N: "fa", Fcn: cos},
		&Prm{N: "fb", Fcn: lin},
	})
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	tmin := 0.0
	tmax := 1.0
	xcte := []float64{0, 0, 0}
	if chk.Verbose {
		plt.SetForPng(1.2, 400, 150)
		PlotT(cos, "/tmp/gosl/fun", "cosB.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
		plt.Clf()
		PlotT(lin, "/tmp/gosl/fun", "linB.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
		plt.Clf()
		PlotT(mul, "/tmp/gosl/fun", "mul.png", tmin, tmax, xcte, 41, "", "", "", "", "label='f'", "label='g'", "label='h'")
	}

	sktol := 1e-10
	dtol := 1e-9
	dtol2 := 1e-8
	ver := chk.Verbose
	tskip := []float64{tmin, tmax}
	CheckDerivT(tst, cos, tmin, tmax, xcte, 11, nil, sktol, dtol, dtol2, ver)
	io.Pf("\n")
	CheckDerivT(tst, lin, tmin, tmax, xcte, 11, tskip, sktol, dtol, dtol2, ver)
	io.Pf("\n")
	CheckDerivT(tst, mul, tmin, tmax, xcte, 11, tskip, sktol, dtol, dtol2, ver)
}
Exemplo n.º 19
0
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")
	}
}
Exemplo n.º 20
0
func main() {

	// filename
	filename, fnkey := io.ArgToFilename(0, "rjoint01", ".sim", true)

	// fem
	if !fem.Start(filename, false, false, false) {
		io.PfRed("Start failed\n")
		return
	}
	dom, sum, ok := fem.AllocSetAndInit(0, true, true)
	if !ok {
		io.PfRed("AllocSetAndInit failed\n")
		return
	}

	// rjoint element
	eid := 2
	ele := dom.Elems[eid].(*fem.Rjoint)
	ipd := ele.OutIpsData()

	// load results from file
	n := len(sum.OutTimes)
	mtau0 := make([]float64, n)
	mtau1 := make([]float64, n)
	mtau2 := make([]float64, n)
	ompb0 := make([]float64, n)
	ompb1 := make([]float64, n)
	ompb2 := make([]float64, n)
	for i, _ := range sum.OutTimes {
		if !dom.In(sum, i, true) {
			io.PfRed("cannot read solution\n")
			return
		}
		res0 := ipd[0].Calc(dom.Sol)
		res1 := ipd[1].Calc(dom.Sol)
		res2 := ipd[2].Calc(dom.Sol)
		mtau0[i] = -res0["tau"]
		mtau1[i] = -res1["tau"]
		mtau2[i] = -res2["tau"]
		ompb0[i] = res0["ompb"]
		ompb1[i] = res1["ompb"]
		ompb2[i] = res2["ompb"]
	}

	// plot
	plt.SetForPng(0.8, 400, 200)
	plt.Plot(ompb0, mtau0, "'r-', marker='.', label='p0', clip_on=0")
	plt.Plot(ompb1, mtau1, "'g-', marker='.', label='p1', clip_on=0")
	plt.Plot(ompb2, mtau2, "'b-', marker='.', label='p2', clip_on=0")
	plt.Gll("$\\bar{\\omega}_p$", "$-\\tau$", "")
	plt.SaveD("/tmp", fnkey+".png")
}
Exemplo n.º 21
0
func main() {

	// filename
	filename, fnkey := io.ArgToFilename(0, "a-coarse-elast-d2-q9.sim", ".sim", true)

	// start analysis process
	out.Start(filename, 0, 0)

	// define entities
	out.Define("A B C D E", out.N{-1, -2, -3, -4, -5})                       // top => bottom
	out.Define("a b c d e", out.P{{18, 8}, {8, 8}, {4, 8}, {30, 8}, {0, 0}}) // top => bottom

	// load results
	out.LoadResults(nil)

	// styles
	me := 10
	S := []plt.Fmt{
		plt.Fmt{C: "b", M: "*", Me: me},
		plt.Fmt{C: "g", M: "o", Me: me},
		plt.Fmt{C: "m", M: "x", Me: me},
		plt.Fmt{C: "orange", M: "+", Me: me},
		plt.Fmt{C: "r", M: "^", Me: me},
	}

	// pl
	out.Splot("liquid pressure")
	for i, l := range []string{"A", "B", "C", "D", "E"} {
		out.Plot("t", "pl", l, S[i], -1)
	}

	// uy
	out.Splot("displacements")
	for i, l := range []string{"A", "B", "C", "D", "E"} {
		out.Plot("t", "uy", l, S[i], -1)
	}

	out.Splot("liquid saturation")
	for i, l := range []string{"a", "b", "c", "d", "e"} {
		out.Plot("t", "sl", l, S[i], -1)
	}

	out.Splot("stresses")
	for i, l := range []string{"a", "b", "c", "d", "e"} {
		out.Plot("t", "sy", l, S[i], -1)
	}

	// show
	plt.SetForPng(1, 500, 200)
	out.Draw("/tmp", "up_indentation2d_unsat_"+fnkey+".png", false, nil)
}
Exemplo n.º 22
0
func Test_invs05(tst *testing.T) {

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

	if SAVEPLOT {
		plt.Reset()
		plt.SetForPng(1, 500, 125)
		PlotRosette(1.1, true, true, true, 7)
	}

	addtoplot := func(σa, σb float64, σ []float64) {
		plt.PlotOne(σa, σb, "'ro', ms=5")
		plt.Text(σa, σb, io.Sf("$\\sigma_{123}=(%g,%g,%g)$", σ[0], σ[1], σ[2]), "size=8")
	}

	dotest := func(σ []float64, σacor, σbcor, σccor, θcor, tolσ float64) {
		w := M_w(σ)
		θ2 := math.Asin(w) * 180.0 / (3.0 * math.Pi)
		θ3 := M_θ(σ)
		σa, σb, σc := L2O(σ[0], σ[1], σ[2])
		σ0, σ1, σ2 := O2L(σa, σb, σc)
		σI, σA := make([]float64, 3), []float64{σa, σb, σc}
		la.MatVecMul(σI, 1, O2Lmat(), σA) // σI := L * σA
		io.Pf("σa σb σc = %v %v %v\n", σa, σb, σc)
		io.Pf("w        = %v\n", w)
		io.Pf("θ2, θ3   = %v, %v\n", θ2, θ3)
		chk.Scalar(tst, "σa", 1e-17, σa, σacor)
		chk.Scalar(tst, "σb", 1e-17, σb, σbcor)
		chk.Scalar(tst, "σc", 1e-17, σc, σccor)
		chk.Scalar(tst, "σ0", tolσ, σ0, σ[0])
		chk.Scalar(tst, "σ1", tolσ, σ1, σ[1])
		chk.Scalar(tst, "σ2", tolσ, σ2, σ[2])
		chk.Scalar(tst, "σI0", tolσ, σI[0], σ[0])
		chk.Scalar(tst, "σI1", tolσ, σI[1], σ[1])
		chk.Scalar(tst, "σI2", tolσ, σI[2], σ[2])
		chk.Scalar(tst, "θ2", 1e-6, θ2, θcor)
		chk.Scalar(tst, "θ3", 1e-17, θ3, θ2)
		addtoplot(σa, σb, σ)
	}

	dotest([]float64{-1, 0, 0, 0}, 0, 2.0/SQ6, 1.0/SQ3, 30, 1e-15)
	dotest([]float64{0, -1, 0, 0}, 1.0/SQ2, -1.0/SQ6, 1.0/SQ3, 30, 1e-15)
	dotest([]float64{0, 0, -1, 0}, -1.0/SQ2, -1.0/SQ6, 1.0/SQ3, 30, 1e-15)

	if SAVEPLOT {
		plt.Gll("$\\sigma_a$", "$\\sigma_b$", "")
		plt.Equal()
		plt.SaveD("/tmp/gosl", "fig_invs05.png")
	}
}
Exemplo n.º 23
0
// PlotNurbsBasis plots basis functions la and lb
func PlotNurbsBasis(dirout, fn string, b *Nurbs, la, lb int) {
	npts := 41
	plt.Reset()
	if io.FnExt(fn) == ".eps" {
		plt.SetForEps(1.5, 500)
	} else {
		plt.SetForPng(1.5, 600, 150)
	}

	plt.Subplot(3, 2, 1)
	b.DrawCtrl2d(false, "", "")
	b.DrawElems2d(npts, false, "", "")
	t0 := time.Now()
	b.PlotBasis(la, "", 11, 0) // 0 => CalcBasis
	io.Pfcyan("time elapsed (calcbasis) = %v\n", time.Now().Sub(t0))
	plt.Equal()

	plt.Subplot(3, 2, 2)
	b.DrawCtrl2d(false, "", "")
	b.DrawElems2d(npts, false, "", "")
	b.PlotBasis(lb, "", 11, 0) // 0 => CalcBasis
	plt.Equal()

	plt.Subplot(3, 2, 3)
	b.DrawCtrl2d(false, "", "")
	b.DrawElems2d(npts, false, "", "")
	b.PlotBasis(la, "", 11, 1) // 1 => CalcBasisAndDerivs
	plt.Equal()

	plt.Subplot(3, 2, 4)
	b.DrawCtrl2d(false, "", "")
	b.DrawElems2d(npts, false, "", "")
	b.PlotBasis(lb, "", 11, 1) // 1 => CalcBasisAndDerivs
	plt.Equal()

	plt.Subplot(3, 2, 5)
	b.DrawCtrl2d(false, "", "")
	b.DrawElems2d(npts, false, "", "")
	t0 = time.Now()
	b.PlotBasis(la, "", 11, 2) // 2 => RecursiveBasis
	io.Pfcyan("time elapsed (recursive) = %v\n", time.Now().Sub(t0))
	plt.Equal()

	plt.Subplot(3, 2, 6)
	b.DrawCtrl2d(false, "", "")
	b.DrawElems2d(npts, false, "", "")
	b.PlotBasis(lb, "", 11, 2) // 2 => RecursiveBasis
	plt.Equal()

	plt.SaveD(dirout, fn)
}
Exemplo n.º 24
0
func Test_bezier02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("bezier02. quadratic Bezier. point-distance")

	bez := BezierQuad{
		Q: [][]float64{
			{-1, 1},
			{0.5, -2},
			{2, 4},
		},
	}

	nx, ny := 5, 5
	xx, yy := utl.MeshGrid2D(-1.5, 2.5, -0.5, 4.5, nx, ny)
	//zz := la.MatAlloc(nx, ny)

	// TODO: finish this test

	doplot := false
	if doplot {
		plt.SetForPng(1, 400, 200)
	}

	C := make([]float64, 2)
	for j := 0; j < ny; j++ {
		for i := 0; i < nx; i++ {
			C[0], C[1] = xx[i][j], yy[i][j]
			d := bez.DistPoint(C, doplot)
			io.Pforan("d = %v\n", d)
		}
	}

	np := 21
	T := utl.LinSpace(0, 1, np)
	X := make([]float64, np)
	Y := make([]float64, np)
	for i, t := range T {
		bez.Point(C, t)
		X[i], Y[i] = C[0], C[1]
	}

	if doplot {
		plt.Plot(X, Y, "'b-', label='Bezier'")
		plt.Gll("x", "y", "")
		plt.Equal()
		plt.SaveD("/tmp", "fig_gm_bezier02.png")
	}
}
Exemplo n.º 25
0
// PlotNurbs plots a NURBS
func PlotNurbs(dirout, fn string, b *Nurbs, npts int, ids bool, extra func()) {
	plt.Reset()
	if io.FnExt(fn) == ".eps" {
		plt.SetForEps(1.0, 500)
	} else {
		plt.SetForPng(1.0, 500, 150)
	}
	b.DrawCtrl2d(ids, "", "")
	b.DrawElems2d(npts, ids, "", "")
	if extra != nil {
		extra()
	}
	plt.Equal()
	plt.SaveD(dirout, fn)
}
Exemplo n.º 26
0
// PlotNurbsDerivs plots derivatives of basis functions la and lb
func PlotNurbsDerivs(dirout, fn string, b *Nurbs, la, lb int) {
	npts := 41
	plt.Reset()
	if io.FnExt(fn) == ".eps" {
		plt.SetForEps(1.5, 500)
	} else {
		plt.SetForPng(1.5, 600, 150)
	}

	plt.Subplot(4, 2, 1)
	t0 := time.Now()
	b.PlotDeriv(la, 0, "", npts, 0) // 0 => CalcBasisAndDerivs
	io.Pfcyan("time elapsed (calcbasis) = %v\n", time.Now().Sub(t0))
	plt.Equal()

	plt.Subplot(4, 2, 2)
	t0 = time.Now()
	b.PlotDeriv(la, 0, "", npts, 1) // 1 => NumericalDeriv
	io.Pfcyan("time elapsed (numerical) = %v\n", time.Now().Sub(t0))
	plt.Equal()

	plt.Subplot(4, 2, 3)
	b.PlotDeriv(la, 1, "", npts, 0) // 0 => CalcBasisAndDerivs
	plt.Equal()

	plt.Subplot(4, 2, 4)
	b.PlotDeriv(la, 1, "", npts, 1) // 0 => NumericalDeriv
	plt.Equal()

	plt.Subplot(4, 2, 5)
	b.PlotDeriv(lb, 0, "", npts, 0) // 0 => CalcBasisAndDerivs
	plt.Equal()

	plt.Subplot(4, 2, 6)
	b.PlotDeriv(lb, 0, "", npts, 1) // 0 => NumericalDeriv
	plt.Equal()

	plt.Subplot(4, 2, 7)
	b.PlotDeriv(lb, 1, "", npts, 0) // 0 => CalcBasisAndDerivs
	plt.Equal()

	plt.Subplot(4, 2, 8)
	b.PlotDeriv(lb, 1, "", npts, 1) // 0 => NumericalDeriv
	plt.Equal()

	plt.SaveD(dirout, fn)
}
Exemplo n.º 27
0
func Test_bspline02(tst *testing.T) {

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

	//               0 1 2 3 4 5 6 7 8 9 10
	T := []float64{0, 0, 0, 1, 2, 3, 4, 4, 5, 5, 5}
	sol := []int{2, 2, 3, 3, 4, 4, 5, 5, 7, 7, 7}
	var s Bspline
	s.Init(T, 2)
	s.SetControl([][]float64{{0, 0}, {0.5, 1}, {1, 0}, {1.5, 0}, {2, 1}, {2.5, 1}, {3, 0.5}, {3.5, 0}})

	tt := utl.LinSpace(0, 5, 11)
	for k, t := range tt {
		span := s.find_span(t)
		io.Pforan("t=%.4f  =>  span=%v\n", t, span)
		if span != sol[k] {
			chk.Panic("find_span failed: t=%v  span => %d != %d", t, span, sol[k])
		}
	}

	tol := 1e-14
	np := len(tt)
	xx, yy := make([]float64, np), make([]float64, np)
	for k, t := range tt {
		t0 := time.Now()
		pa := s.Point(t, 0) // 0 => CalcBasis
		io.Pf("Point(rec): dtime = %v\n", time.Now().Sub(t0))
		t0 = time.Now()
		pb := s.Point(t, 1) // 1 => RecursiveBasis
		io.Pf("Point:      dtime = %v\n", time.Now().Sub(t0))
		xx[k], yy[k] = pb[0], pb[1]
		io.Pfred("pa - pb = %v, %v\n", pa[0]-pb[0], pa[1]-pb[1])
		chk.Vector(tst, "Point", tol, pa, pb)
	}

	if chk.Verbose {
		npts := 201
		plt.SetForPng(0.75, 300, 150)
		str0 := ",lw=2"
		str1 := ",ls='none',marker='+',color='cyan',markevery=10"
		s.Draw2d(str0, "", npts, 0) // 0 => CalcBasis
		s.Draw2d(str1, "", npts, 1) // 1 => RecursiveBasis
		plt.Plot(xx, yy, "'bo', clip_on=0")
		plt.SaveD("/tmp/gosl/gm", "bspline02.png")
	}
}
Exemplo n.º 28
0
// SetFig sets figure space for plotting
// Note: this method is optional
func (o *Plotter) SetFig(split, epsfig bool, prop, width float64, savedir, savefnk string) {
	plt.Reset()
	if o.PngRes < 150 {
		o.PngRes = 150
	}
	o.Split = split
	o.UseEps = epsfig
	if o.UseEps {
		plt.SetForEps(prop, width)
	} else {
		plt.SetForPng(prop, width, o.PngRes)
	}
	o.SaveDir = savedir
	o.SaveFnk = io.FnKey(savefnk)
	o.maxR = -1
	// colors and markers
	o.set_default_clr_mrk()
}
Exemplo n.º 29
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")
	}
}
Exemplo n.º 30
0
func main() {

	// define function and derivative function
	y_fcn := func(x float64) float64 { return math.Sin(x) }
	dydx_fcn := func(x float64) float64 { return math.Cos(x) }
	d2ydx2_fcn := func(x float64) float64 { return -math.Sin(x) }

	// run test for 11 points
	X := utl.LinSpace(0, 2*math.Pi, 11)
	io.Pf("          %8s %23s %23s %23s\n", "x", "analytical", "numerical", "error")
	for _, x := range X {

		// analytical derivatives
		dydx_ana := dydx_fcn(x)
		d2ydx2_ana := d2ydx2_fcn(x)

		// numerical derivative: dydx
		dydx_num, _ := num.DerivCentral(func(t float64, args ...interface{}) float64 {
			return y_fcn(t)
		}, x, 1e-3)

		// numerical derivative d2ydx2
		d2ydx2_num, _ := num.DerivCentral(func(t float64, args ...interface{}) float64 {
			return dydx_fcn(t)
		}, x, 1e-3)

		// check
		chk.PrintAnaNum(io.Sf("dy/dx   @ %.6f", x), 1e-10, dydx_ana, dydx_num, true)
		chk.PrintAnaNum(io.Sf("d²y/dx² @ %.6f", x), 1e-10, d2ydx2_ana, d2ydx2_num, true)
	}

	// generate 101 points for plotting
	X = utl.LinSpace(0, 2*math.Pi, 101)
	Y := make([]float64, len(X))
	for i, x := range X {
		Y[i] = y_fcn(x)
	}

	// plot
	plt.SetForPng(0.75, 300, 150)
	plt.Plot(X, Y, "'b.-', clip_on=0, markevery=10, label='y(x)=sin(x)'")
	plt.Gll("x", "y", "")
	plt.SaveD("/tmp/gosl", "num_deriv01.png")
}