示例#1
0
func read_summary(simfn string) (*utl.DblSlist, string) {
	if simfn == "" {
		return nil, ""
	}
	if io.FnExt(simfn) == "" {
		simfn += ".sim"
	}
	out.Start(simfn, 0, 0)
	return &out.Sum.Resids, io.FnKey(simfn)
}
示例#2
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()
	}
}
示例#3
0
func main() {

	// default input data
	fn := "nurbs01.msh"
	ctrl := true
	ids := true
	npts := 41

	// parse flags
	flag.Parse()
	if len(flag.Args()) > 0 {
		fn = flag.Arg(0)
	}
	if len(flag.Args()) > 1 {
		ctrl = io.Atob(flag.Arg(1))
	}
	if len(flag.Args()) > 2 {
		ids = io.Atob(flag.Arg(2))
	}
	if len(flag.Args()) > 3 {
		npts = io.Atoi(flag.Arg(3))
	}

	// print input data
	io.Pforan("Input data\n")
	io.Pforan("==========\n")
	io.Pfblue2("  fn   = %v\n", fn)
	io.Pfblue2("  ctrl = %v\n", ctrl)
	io.Pfblue2("  ids  = %v\n", ids)
	io.Pfblue2("  npts = %v\n", npts)

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

	// plot
	plt.SetForEps(0.75, 500)
	for _, b := range B {
		if ctrl {
			b.DrawCtrl2d(ids, "", "")
		}
		b.DrawElems2d(npts, ids, "", "")
	}
	plt.Equal()
	plt.Save(fnk + ".eps")
}
示例#4
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()
}
示例#5
0
文件: sim.go 项目: PatrickSchm/gofem
// PostProcess performs a post-processing of the just read json file
func (o *Data) PostProcess(dir, fn string, erasefiles bool) {
	o.FnameDir = os.ExpandEnv(dir)
	o.FnameKey = io.FnKey(fn)
	if o.DirOut == "" {
		o.DirOut = "/tmp/gofem/" + o.FnameKey
	}
	if o.Encoder != "gob" && o.Encoder != "json" {
		o.Encoder = "gob"
	}
	err := os.MkdirAll(o.DirOut, 0777)
	if err != nil {
		chk.Panic("cannot create directory for output results (%s): %v", o.DirOut, err)
	}
	if erasefiles {
		io.RemoveAll(io.Sf("%s/%s_*.vtu", o.DirOut, o.FnameKey))
		io.RemoveAll(io.Sf("%s/%s_*.log", o.DirOut, o.FnameKey))
		io.RemoveAll(io.Sf("%s/%s_*.gob", o.DirOut, o.FnameKey))
		io.RemoveAll(io.Sf("%s/%s_*.json", o.DirOut, o.FnameKey))
	}
}
示例#6
0
func main() {

	defer func() {
		if err := recover(); err != nil {
			io.PfRed("Some error has happened: %v\n", err)
		}
	}()

	// input data
	matfn := "materials.mat"

	skip := "gref nowet α"

	// parse flags
	flag.Parse()
	if len(flag.Args()) > 0 {
		matfn = flag.Arg(0)
	}
	if len(flag.Args()) > 1 {
		skip = flag.Arg(1)
	}

	// skip parameters
	skipp := make(map[string]bool)
	for _, key := range io.SplitKeys(skip) {
		skipp[key] = true
	}

	// file key
	fnk := io.FnKey(matfn)

	// print input data
	io.Pforan("Input data\n")
	io.Pfblue2("  matfn = %v\n", matfn)
	io.Pfblue2("  skip  = %v\n", skip)

	// Read
	mdb := inp.ReadMat("", matfn)

	// Get max number of parameters
	nmaxprms := 0
	for _, mdat := range mdb.Materials {
		n := len(mdat.Prms)
		if n > nmaxprms {
			nmaxprms = n
		}
	}

	// header
	b := new(bytes.Buffer)
	io.Ff(b, "\\documentclass[12pt,a4paper]{article}\n")
	io.Ff(b, "\\usepackage[margin=2.0cm,footskip=0.5cm]{geometry}\n")
	io.Ff(b, "\\usepackage[labelfont=bf,tableposition=top,aboveskip=4pt]{caption}\n")
	io.Ff(b, "\\usepackage{tabularx}\n")
	io.Ff(b, "\\usepackage{booktabs}\n")
	io.Ff(b, "\n")
	io.Ff(b, "\\title{Materials Table}\n")
	io.Ff(b, "\\author{GoFem MatTable tool}\n")
	io.Ff(b, "\n")
	io.Ff(b, "\\begin{document}\n")
	io.Ff(b, "\\maketitle\n")

	// table with parameters
	io.Ff(b, "\n")
	io.Ff(b, "\\begin{table} \\centering\n")
	io.Ff(b, "\\caption{Parameters from %s}\n", matfn)
	io.Ff(b, "\\begin{tabularx}{\\linewidth}[c]{l %s} \\toprule\n", strings.Repeat("c", nmaxprms))

	for i, mdat := range mdb.Materials {
		necols := nmaxprms - len(mdat.Prms) // number of empty cols

		// mat name
		io.Ff(b, "  %-20s", mdat.Name)

		// parameters names
		for _, param := range mdat.Prms {
			io.Ff(b, " &%12s", ToTex(param.N))
		}

		io.Ff(b, " %s", strings.Repeat(" &", necols))
		io.Ff(b, " \\\\\n")

		// values
		io.Ff(b, "  %-20s", "")
		for _, param := range mdat.Prms {
			io.Ff(b, " &%12s", NumFormat(param.V))
		}

		io.Ff(b, " %s", strings.Repeat(" &", necols))
		io.Ff(b, " \\\\\n")

		// units
		io.Ff(b, "  %-20s", "")
		for _, param := range mdat.Prms {
			if param.U == "" {
				io.Ff(b, " &%12v", "-")
			} else {
				io.Ff(b, " &%12v", UnitFormat(param.U))
			}
		}

		io.Ff(b, " %s", strings.Repeat(" &", necols))
		io.Ff(b, " \\\\\n")

		if i < len(mdb.Materials)-1 {
			io.Ff(b, "  \\\\\n")
		}
	}

	// footer
	io.Ff(b, "  \\bottomrule\n\\end{tabularx}\n\\label{tab:prms}\n\\end{table}\n")
	io.Ff(b, "\\end{document}\n")
	io.WriteFileV(fnk+".tex", b)

}