예제 #1
0
파일: t_fun_test.go 프로젝트: yunpeng1/gosl
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)
}
예제 #2
0
파일: t_fun_test.go 프로젝트: yunpeng1/gosl
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)
}
예제 #3
0
// subplot sets subplot
func (o *Plotter) Subplot() {
	if o.Split {
		plt.Clf()
		return
	}
	plt.Subplot(o.Nrow, o.Ncol, o.Pidx)
	o.Pidx += 1
}
예제 #4
0
// Draw draws or save figure with plot
//  dirout -- directory to save figure
//  fname  -- file name; e.g. myplot.eps or myplot.png. Use "" to skip saving
//  show   -- shows figure
//  extra  -- is called just after Subplot command and before any plotting
//  Note: subplots will be split if using 'eps' files
func Draw(dirout, fname string, show bool, extra ExtraPlt) {
	var fnk string // filename key
	var ext string // extension
	var eps bool   // is eps figure
	if fname != "" {
		fnk = io.FnKey(fname)
		ext = io.FnExt(fname)
		eps = ext == ".eps"
	}
	nplots := len(Splots)
	nr, nc := utl.BestSquare(nplots)
	var k int
	for i := 0; i < nr; i++ {
		for j := 0; j < nc; j++ {
			if !eps {
				plt.Subplot(nr, nc, k+1)
			}
			if extra != nil {
				extra(i+1, j+1, nplots)
			}
			if Splots[k].Title != "" {
				plt.Title(Splots[k].Title, Splots[k].Topts)
			}
			data := Splots[k].Data
			for _, d := range data {
				if d.Style.L == "" {
					d.Style.L = d.Alias
				}
				x, y := d.X, d.Y
				if math.Abs(Splots[k].Xscale) > 0 {
					x = make([]float64, len(d.X))
					la.VecCopy(x, Splots[k].Xscale, d.X)
				}
				if math.Abs(Splots[k].Yscale) > 0 {
					y = make([]float64, len(d.Y))
					la.VecCopy(y, Splots[k].Yscale, d.Y)
				}
				plt.Plot(x, y, d.Style.GetArgs("clip_on=0"))
			}
			plt.Gll(Splots[k].Xlbl, Splots[k].Ylbl, Splots[k].GllArgs)
			if eps {
				savefig(dirout, fnk, ext, k)
				plt.Clf()
			}
			k += 1
		}
	}
	if !eps && fname != "" {
		savefig(dirout, fnk, ext, -1)
	}
	if show {
		plt.Show()
	}
}
예제 #5
0
// Plot runs the plot generation (basic set)
func (o *Plotter) Plot(keys []string, res []*State, sts [][]float64, first, last bool) {

	// auxiliary variables
	nr := imax(len(res), len(sts))
	if nr < 1 {
		return
	}
	x := make([]float64, nr)
	y := make([]float64, nr)
	o.P = make([]float64, nr)
	o.Q = make([]float64, nr)
	o.W = make([]float64, nr)
	o.Ev = make([]float64, nr)
	o.Ed = make([]float64, nr)

	// compute invariants
	for i := 0; i < len(res); i++ {
		if len(res[i].Sig) < 4 {
			chk.Panic("number of stress components is incorrect: %d", len(res[i].Sig))
		}
		o.P[i], o.Q[i], o.W[i] = tsr.M_pqw(res[i].Sig)
	}
	nsig := len(res[0].Sig)
	devε := make([]float64, nsig)
	for i := 0; i < len(sts); i++ {
		if len(sts[i]) < 4 {
			chk.Panic("number of strain components is incorrect: %d", len(sts[i]))
		}
		_, o.Ev[i], o.Ed[i] = tsr.M_devε(devε, sts[i])
	}

	// clear previous figure
	if first {
		plt.Clf()
		plt.SplotGap(0.35, 0.35)
		if o.Hspace > 0 {
			plt.SetHspace(o.Hspace)
		}
		if o.Vspace > 0 {
			plt.SetVspace(o.Vspace)
		}
	}

	// number of points for contour
	if o.NptsPq < 2 {
		o.NptsPq = 61
	}
	if o.NptsOct < 2 {
		o.NptsOct = 41
	}
	if o.NptsSig < 2 {
		o.NptsSig = 41
	}

	// subplot variables
	o.Pidx = 1
	o.Ncol, o.Nrow = utl.BestSquare(len(keys))
	if len(keys) == 2 {
		o.Ncol, o.Nrow = 1, 2
	}
	if len(keys) == 3 {
		o.Ncol, o.Nrow = 1, 3
	}

	// do plot
	for _, key := range keys {
		o.Subplot()
		switch key {
		case "ed,q":
			o.QdivP = false
			o.Plot_ed_q(x, y, res, sts, last)
		case "ed,q/p":
			o.QdivP = true
			o.Plot_ed_q(x, y, res, sts, last)
		case "p,q":
			o.WithYs = false
			o.Plot_p_q(x, y, res, sts, last)
		case "p,q,ys":
			o.WithYs = true
			o.Plot_p_q(x, y, res, sts, last)
		case "ed,ev":
			o.Plot_ed_ev(x, y, res, sts, last)
		case "p,ev":
			o.LogP = false
			o.Plot_p_ev(x, y, res, sts, last)
		case "log(p),ev":
			o.LogP = true
			o.Plot_p_ev(x, y, res, sts, last)
		case "i,f":
			o.Plot_i_f(x, y, res, sts, last)
		case "i,alp":
			o.Plot_i_alp(x, y, res, sts, last)
		case "Dgam,f":
			o.Plot_Dgam_f(x, y, res, sts, last)
		case "oct":
			o.WithYs = false
			o.Plot_oct(x, y, res, sts, last)
		case "oct,ys":
			o.WithYs = true
			o.Plot_oct(x, y, res, sts, last)
		case "s3,s1":
			o.WithYs = false
			o.Plot_s3_s1(x, y, res, sts, last)
		case "s3,s1,ys":
			o.WithYs = true
			o.Plot_s3_s1(x, y, res, sts, last)
		case "empty":
			continue
		default:
			chk.Panic("cannot handle key=%q", key)
		}
		if o.Split && last {
			o.Save("_", key)
		}
	}

	// save figure
	if !o.Split && last {
		o.Save("", "")
	}
}