Esempio n. 1
0
// PlotFltFlt plots flt-flt contour
// use iFlt==-1 || jFlt==-1 to plot all combinations
func (o *Optimiser) PlotFltFltContour(sols0 []*Solution, iFlt, jFlt, iOva int, pp *PlotParams) {
	best, _ := GetBestFeasible(o, iOva)
	plotAll := iFlt < 0 || jFlt < 0
	plotCommands := func(i, j int) {
		o.PlotContour(i, j, iOva, pp)
		if sols0 != nil {
			o.PlotAddFltFlt(i, j, sols0, &pp.FmtSols0)
		}
		o.PlotAddFltFlt(i, j, o.Solutions, &pp.FmtSols)
		if best != nil {
			plt.PlotOne(best.Flt[i], best.Flt[j], pp.FmtBest.GetArgs(""))
		}
		if pp.Extra != nil {
			pp.Extra()
		}
		if pp.AxEqual {
			plt.Equal()
		}
	}
	if plotAll {
		idx := 1
		ncol := o.Nflt - 1
		for row := 0; row < o.Nflt; row++ {
			idx += row
			for col := row + 1; col < o.Nflt; col++ {
				plt.Subplot(ncol, ncol, idx)
				plt.SplotGap(0.0, 0.0)
				plotCommands(col, row)
				if col > row+1 {
					plt.SetXnticks(0)
					plt.SetYnticks(0)
				} else {
					plt.Gll(io.Sf("$x_{%d}$", col), io.Sf("$x_{%d}$", row), "leg=0")
				}
				idx++
			}
		}
		idx = ncol*(ncol-1) + 1
		plt.Subplot(ncol, ncol, idx)
		plt.AxisOff()
		// TODO: fix formatting of open marker, add star to legend
		plt.DrawLegend([]plt.Fmt{pp.FmtSols0, pp.FmtSols, pp.FmtBest}, 8, "center", false, "")
	} else {
		plotCommands(iFlt, jFlt)
		if pp.Xlabel == "" {
			plt.Gll(io.Sf("$x_{%d}$", iFlt), io.Sf("$x_{%d}$", jFlt), pp.LegPrms)
		} else {
			plt.Gll(pp.Xlabel, pp.Ylabel, pp.LegPrms)
		}
	}
	plt.SaveD(pp.DirOut, pp.FnKey+pp.FnExt)
}
Esempio n. 2
0
// PlotStar plots star with normalised OVAs
func (o *Optimiser) PlotStar() {
	nf := o.Nf
	dθ := 2.0 * math.Pi / float64(nf)
	θ0 := 0.0
	if nf == 3 {
		θ0 = -math.Pi / 6.0
	}
	for _, ρ := range []float64{0.25, 0.5, 0.75, 1.0} {
		plt.Circle(0, 0, ρ, "ec='gray',lw=0.5,zorder=5")
	}
	arrowM, textM := 1.1, 1.15
	for i := 0; i < nf; i++ {
		θ := θ0 + float64(i)*dθ
		xi, yi := 0.0, 0.0
		xf, yf := arrowM*math.Cos(θ), arrowM*math.Sin(θ)
		plt.Arrow(xi, yi, xf, yf, "sc=10,st='->',lw=0.7,zorder=10,clip_on=0")
		plt.PlotOne(xf, yf, "'k+', ms=0")
		xf, yf = textM*math.Cos(θ), textM*math.Sin(θ)
		plt.Text(xf, yf, io.Sf("%d", i), "size=6,zorder=10,clip_on=0")
	}
	X, Y := make([]float64, nf+1), make([]float64, nf+1)
	clr := false
	neg := false
	step := 1
	count := 0
	colors := []string{"m", "orange", "g", "r", "b", "k"}
	var ρ float64
	for i, sol := range o.Solutions {
		if sol.Feasible() && sol.FrontId == 0 && i%step == 0 {
			for j := 0; j < nf; j++ {
				if neg {
					ρ = 1.0 - sol.Ova[j]/(o.RptFmax[j]-o.RptFmin[j])
				} else {
					ρ = sol.Ova[j] / (o.RptFmax[j] - o.RptFmin[j])
				}
				θ := θ0 + float64(j)*dθ
				X[j], Y[j] = ρ*math.Cos(θ), ρ*math.Sin(θ)
			}
			X[nf], Y[nf] = X[0], Y[0]
			if clr {
				j := count % len(colors)
				plt.Plot(X, Y, io.Sf("'k-',color='%s',markersize=3,clip_on=0", colors[j]))
			} else {
				plt.Plot(X, Y, "'r-',marker='.',markersize=3,clip_on=0")
			}
			count++
		}
	}
	plt.Equal()
	plt.AxisOff()
}
Esempio n. 3
0
func (o *Plotter) Plot_oct(x, y []float64, res []*State, sts [][]float64, last bool) {
	// stress path
	nr := len(res)
	k := nr - 1
	var σa, σb, xmi, xma, ymi, yma float64
	for i := 0; i < nr; i++ {
		σa, σb, _ = tsr.PQW2O(o.P[i], o.Q[i], o.W[i])
		x[i], y[i] = σa, σb
		o.maxR = max(o.maxR, math.Sqrt(σa*σa+σb*σb))
		if i == 0 {
			xmi, xma = x[i], x[i]
			ymi, yma = y[i], y[i]
		} else {
			xmi = min(xmi, x[i])
			xma = max(xma, x[i])
			ymi = min(ymi, y[i])
			yma = max(yma, y[i])
		}
	}
	plt.Plot(x, y, io.Sf("'r.', ls='%s', clip_on=0, color='%s', marker='%s', label=r'%s'", o.Ls, o.Clr, o.Mrk, o.Lbl))
	plt.PlotOne(x[0], y[0], io.Sf("'bo', clip_on=0, color='%s', marker='%s', ms=%d", o.SpClr, o.SpMrk, o.SpMs))
	plt.PlotOne(x[k], y[k], io.Sf("'bs', clip_on=0, color='%s', marker='%s', ms=%d", o.SpClr, o.EpMrk, o.EpMs))
	// fix range and max radius
	xmi, xma, ymi, yma = o.fix_range(0, xmi, xma, ymi, yma)
	rr := math.Sqrt((xma-xmi)*(xma-xmi) + (yma-ymi)*(yma-ymi))
	if o.maxR < rr {
		o.maxR = rr
	}
	if o.maxR < 1e-10 {
		o.maxR = 1
	}
	if yma > -xmi {
		xmi = -yma
	}
	if o.OctLims != nil {
		xmi, xma, ymi, yma = o.OctLims[0], o.OctLims[1], o.OctLims[2], o.OctLims[3]
	}
	//xmi, xma, ymi, yma = -20000, 20000, -20000, 20000
	// yield surface
	var σcmax float64
	if o.WithYs && o.m != nil {
		//io.Pforan("xmi,xma ymi,yma = %v,%v %v,%v\n", xmi,xma, ymi,yma)
		dx := (xma - xmi) / float64(o.NptsOct-1)
		dy := (yma - ymi) / float64(o.NptsOct-1)
		xx := la.MatAlloc(o.NptsOct, o.NptsOct)
		yy := la.MatAlloc(o.NptsOct, o.NptsOct)
		zz := la.MatAlloc(o.NptsOct, o.NptsOct)
		var λ0, λ1, λ2, σc float64
		v := NewState(len(res[0].Sig), len(res[0].Alp), false, len(res[0].EpsE) > 0)
		for k := 0; k < nr; k++ {
			copy(v.Alp, res[k].Alp)
			v.Dgam = res[k].Dgam
			σc = tsr.M_p(res[k].Sig) * tsr.SQ3
			//σc = 30000
			σcmax = max(σcmax, σc)
			for i := 0; i < o.NptsOct; i++ {
				for j := 0; j < o.NptsOct; j++ {
					xx[i][j] = xmi + float64(i)*dx
					yy[i][j] = ymi + float64(j)*dy
					λ0, λ1, λ2 = tsr.O2L(xx[i][j], yy[i][j], σc)
					v.Sig[0], v.Sig[1], v.Sig[2] = λ0, λ1, λ2
					ys := o.m.YieldFuncs(v)
					zz[i][j] = ys[0]
				}
			}
			plt.ContourSimple(xx, yy, zz, io.Sf("colors=['%s'], levels=[0], linestyles=['%s'], linewidths=[%g], clip_on=0", o.YsClr0, o.YsLs0, o.YsLw0)+o.ArgsYs)

		}
	}
	// predictor-corrector
	if len(o.PreCor) > 1 {
		var σa, σb, σanew, σbnew float64
		for i := 1; i < len(o.PreCor); i++ {
			σa, σb, _ = tsr.M_oct(o.PreCor[i-1])
			σanew, σbnew, _ = tsr.M_oct(o.PreCor[i])
			if math.Abs(σanew-σa) > 1e-7 || math.Abs(σbnew-σb) > 1e-7 {
				//plt.Plot([]float64{σa,σanew}, []float64{σb,σbnew}, "'k+', ms=3, color='k'")
				plt.Arrow(σa, σb, σanew, σbnew, io.Sf("sc=%d, fc='%s', ec='%s'", o.ArrWid, o.ClrPC, o.ClrPC))
			}
			o.maxR = max(o.maxR, math.Sqrt(σa*σa+σb*σb))
			o.maxR = max(o.maxR, math.Sqrt(σanew*σanew+σbnew*σbnew))
		}
	}
	// rosette and settings
	if last {
		tsr.PlotRefOct(o.Phi, σcmax, true)
		tsr.PlotRosette(o.maxR, false, true, true, 6)
		if o.OctAxOff {
			plt.AxisOff()
		}
		plt.Gll("$\\sigma_a$", "$\\sigma_b$", "")
		if lims, ok := o.Lims["oct"]; ok {
			plt.AxisLims(lims)
		}
		if lims, ok := o.Lims["oct,ys"]; ok {
			plt.AxisLims(lims)
		}
	}
}
Esempio n. 4
0
func (o *Plotter) set_empty() {
	plt.AxisOff()
}
Esempio n. 5
0
// Draw draws grid
//  r   -- radius of circles
//  W   -- width of paths
//  dwt -- δwt for positioning text (w = W/2)
//  arrow_scale -- scale for arrows. use 0 for default value
func (o *Graph) Draw(dirout, fname string, r, W, dwt, arrow_scale float64,
	verts_lbls map[int]string, verts_fsz float64, verts_clr string,
	edges_lbls map[int]string, edges_fsz float64, edges_clr string) {
	if len(o.Verts) < 1 {
		return
	}
	xmin, ymin := o.Verts[0][0], o.Verts[0][1]
	xmax, ymax := xmin, ymin
	var lbl string
	for i, v := range o.Verts {
		if verts_lbls == nil {
			lbl = io.Sf("%d", i)
		} else {
			lbl = verts_lbls[i]
		}
		plt.Text(v[0], v[1], lbl, io.Sf("clip_on=0, color='%s', fontsize=%g, ha='center', va='center'", verts_clr, verts_fsz))
		plt.Circle(v[0], v[1], r, "clip_on=0, ec='k', lw=0.8")
		xmin, ymin = utl.Min(xmin, v[0]), utl.Min(ymin, v[1])
		xmax, ymax = utl.Max(xmax, v[0]), utl.Max(ymax, v[1])
	}
	if W > 2*r {
		W = 1.8 * r
	}
	w := W / 2.0
	xa, xb := make([]float64, 2), make([]float64, 2)
	xc, dx := make([]float64, 2), make([]float64, 2)
	mu, nu := make([]float64, 2), make([]float64, 2)
	xi, xj := make([]float64, 2), make([]float64, 2)
	l := math.Sqrt(r*r - w*w)
	var L float64
	if arrow_scale <= 0 {
		arrow_scale = 20
	}
	for k, e := range o.Edges {
		L = 0.0
		for i := 0; i < 2; i++ {
			xa[i] = o.Verts[e[0]][i]
			xb[i] = o.Verts[e[1]][i]
			xc[i] = (xa[i] + xb[i]) / 2.0
			dx[i] = xb[i] - xa[i]
			L += dx[i] * dx[i]
		}
		L = math.Sqrt(L)
		mu[0], mu[1] = dx[0]/L, dx[1]/L
		nu[0], nu[1] = -dx[1]/L, dx[0]/L
		for i := 0; i < 2; i++ {
			xi[i] = xa[i] + l*mu[i] - w*nu[i]
			xj[i] = xb[i] - l*mu[i] - w*nu[i]
			xc[i] = (xi[i]+xj[i])/2.0 - dwt*nu[i]
		}
		plt.Arrow(xi[0], xi[1], xj[0], xj[1], io.Sf("st='->', sc=%g", arrow_scale))
		if edges_lbls == nil {
			lbl = io.Sf("%d", k)
		} else {
			lbl = edges_lbls[k]
		}
		plt.Text(xc[0], xc[1], lbl, io.Sf("clip_on=0, color='%s', fontsize=%g, ha='center', va='center'", edges_clr, edges_fsz))
	}
	xmin -= r
	xmax += r
	ymin -= r
	ymax += r
	plt.AxisOff()
	plt.Equal()
	plt.AxisRange(xmin, xmax, ymin, ymax)
	plt.SaveD(dirout, fname)
}
Esempio n. 6
0
// PlotOct plots a function cross-section and gradients projections on octahedral plane
func PlotOct(filename string, σcCte, rmin, rmax float64, nr, nα int, φ float64, F Cb_F_t, G Cb_G_t,
	notpolarc, simplec, only0, grads, showpts, first, last bool, ferr float64, args ...interface{}) {
	A := make([]float64, 6)
	dfdA := make([]float64, 6)
	dα := 2.0 * math.Pi / float64(nα)
	dr := (rmax - rmin) / float64(nr-1)
	αmin := -math.Pi / 6.0
	if notpolarc {
		rmin = -rmax
		dr = (rmax - rmin) / float64(nr-1)
		nα = nr
		dα = dr
		αmin = rmin
	}
	x, y, f := la.MatAlloc(nα, nr), la.MatAlloc(nα, nr), la.MatAlloc(nα, nr)
	//var gx, gy, L [][]float64
	var gx, gy [][]float64
	if grads {
		gx, gy = la.MatAlloc(nα, nr), la.MatAlloc(nα, nr)
		//L      = O2Lmat()
	}
	var σa, σb []float64
	if showpts {
		σa, σb = make([]float64, nα*nr), make([]float64, nα*nr)
	}
	k := 0
	var err error
	for i := 0; i < nα; i++ {
		for j := 0; j < nr; j++ {
			α := αmin + float64(i)*dα
			r := rmin + float64(j)*dr
			if notpolarc {
				x[i][j] = α // σa
				y[i][j] = r // σb
			} else {
				x[i][j] = r * math.Cos(α) // σa
				y[i][j] = r * math.Sin(α) // σb
			}
			A[0], A[1], A[2] = O2L(x[i][j], y[i][j], σcCte)
			if showpts {
				σa[k] = x[i][j]
				σb[k] = y[i][j]
			}
			f[i][j], err = F(A, args...)
			if err != nil {
				if ferr > 0 {
					f[i][j] = ferr
				} else {
					chk.Panic(_octahedral_err1, "func", err)
				}
			}
			if grads {
				_, err = G(dfdA, A, args...)
				if err != nil {
					chk.Panic(_octahedral_err1, "grads", err)
				}
				/*
				   gx[i][j] = -o.dfdλ[0]*L[0][0] - o.dfdλ[1]*L[1][0] - o.dfdλ[2]*L[2][0]
				   gy[i][j] = -o.dfdλ[0]*L[0][1] - o.dfdλ[1]*L[1][1] - o.dfdλ[2]*L[2][1]
				*/
			}
			k += 1
		}
	}
	if first {
		plt.Reset()
		plt.SetForPng(1, 500, 125)
		PlotRosette(1.1*rmax, true, true, true, 7)
		PlotRefOct(φ, σcCte, false)
		if showpts {
			plt.Plot(σa, σb, "'k.', ms=5")
		}
	}
	if simplec {
		if !only0 {
			plt.ContourSimple(x, y, f, false, 8, "")
		}
		plt.ContourSimple(x, y, f, false, 8, "levels=[0], colors=['blue'], linewidths=[2]")
	} else {
		plt.Contour(x, y, f, "fsz=8")
	}
	if grads {
		plt.Quiver(x, y, gx, gy, "")
	}
	if last {
		plt.AxisOff()
		plt.Equal()
		plt.SaveD("/tmp", filename)
	}
}
Esempio n. 7
0
// Draw2d draws 2D mesh
func (o *Mesh) Draw2d() {

	// auxiliary
	type triple struct{ a, b, c int }   // points on edge
	edgesdrawn := make(map[triple]bool) // edges drawn already
	var tri triple

	// loop over cells
	for _, cell := range o.Cells {

		// loop edges of cells
		for _, lvids := range cell.Shp.FaceLocalVerts {

			// set triple of nodes
			tri.a = cell.Verts[lvids[0]]
			tri.b = cell.Verts[lvids[1]]
			nv := len(lvids)
			if nv > 2 {
				tri.c = cell.Verts[lvids[2]]
			} else {
				tri.c = len(o.Verts) + 1 // indicator of not-available
			}
			utl.IntSort3(&tri.a, &tri.b, &tri.c)

			// draw edge if not drawn yet
			if _, drawn := edgesdrawn[tri]; !drawn {
				x := make([]float64, nv)
				y := make([]float64, nv)
				x[0] = o.Verts[tri.a].C[0]
				y[0] = o.Verts[tri.a].C[1]
				if nv == 3 {
					x[1] = o.Verts[tri.c].C[0]
					y[1] = o.Verts[tri.c].C[1]
					x[2] = o.Verts[tri.b].C[0]
					y[2] = o.Verts[tri.b].C[1]
				} else {
					x[1] = o.Verts[tri.b].C[0]
					y[1] = o.Verts[tri.b].C[1]
				}
				plt.Plot(x, y, "'k-o', ms=3, clip_on=0")
				edgesdrawn[tri] = true
			}
		}

		// add middle node
		if cell.Type == "qua9" {
			vid := cell.Verts[8]
			x := o.Verts[vid].C[0]
			y := o.Verts[vid].C[1]
			plt.PlotOne(x, y, "'ko', ms=3, clip_on=0")
		}

		// linear cells
		if strings.HasPrefix(cell.Type, "lin") {
			nv := len(cell.Verts)
			x := make([]float64, nv)
			y := make([]float64, nv)
			for i, vid := range cell.Verts {
				x[i] = o.Verts[vid].C[0]
				y[i] = o.Verts[vid].C[1]
			}
			plt.Plot(x, y, "'-o', ms=3, clip_on=0, color='#41045a', lw=2")
		}
	}

	// set up
	plt.Equal()
	plt.AxisRange(o.Xmin, o.Xmax, o.Ymin, o.Ymax)
	plt.AxisOff()
}