Example #1
0
// xfem_set_info sets extra information for XFEM elements
func xfem_set_info(info *Info, cell *inp.Cell, edat *inp.ElemData) (ykeys []string) {

	// flags
	xmat, xcrk, xfem := false, false, false
	if s_xmat, found := io.Keycode(edat.Extra, "xmat"); found {
		xmat = io.Atob(s_xmat)
		xfem = true
	}
	if s_xcrk, found := io.Keycode(edat.Extra, "xcrk"); found {
		xcrk = io.Atob(s_xcrk)
		xfem = true
	}
	_ = xcrk // TODO

	// skip if not XFEM
	if !xfem {
		return
	}

	// extra information
	nverts := cell.Shp.Nverts
	if xmat {
		for m := 0; m < nverts; m++ {
			info.Dofs[m] = append(info.Dofs[m], "am")
		}
		info.Y2F["am"] = "nil"
		info.T2vars = append(info.T2vars, "am")
	}
	return
}
Example #2
0
func GetSolidFlags(extra string) (useB, debug bool, thickness float64) {

	// defaults
	useB = false
	debug = false
	thickness = 1.0

	// flag: use B matrix
	if s_useB, found := io.Keycode(extra, "useB"); found {
		useB = io.Atob(s_useB)
	}

	// fix useB flag in case of axisymmetric simulation
	if Global.Sim.Data.Axisym {
		useB = true
	}

	// flag: thickess => plane-stress
	if s_thick, found := io.Keycode(extra, "thick"); found {
		thickness = io.Atof(s_thick)
	}

	// fix thickness flag
	if !Global.Sim.Data.Pstress {
		thickness = 1.0
	}

	// flag: debug
	if s_debug, found := io.Keycode(extra, "debug"); found {
		debug = io.Atob(s_debug)
	}
	return
}
Example #3
0
func main() {

	// input data
	matOld := "matOld.mat"
	matNew := "matNew.mat"
	convSymb := true

	// parse flags
	flag.Parse()
	if len(flag.Args()) > 0 {
		matOld = flag.Arg(0)
	}
	if len(flag.Args()) > 1 {
		matNew = flag.Arg(1)
	}
	if len(flag.Args()) > 2 {
		convSymb = io.Atob(flag.Arg(2))
	}

	// print input data
	io.Pf("\nInput data\n")
	io.Pf("==========\n")
	io.Pf("  matOld   = %30s // old material filename\n", matOld)
	io.Pf("  matNew   = %30s // new material filename\n", matNew)
	io.Pf("  convSymb = %30v // do convert symbols\n", convSymb)
	io.Pf("\n")

	// convert old => new
	inp.MatfileOld2New("", matNew, matOld, convSymb)
	io.Pf("conversion successful\n")
	io.Pfblue2("file <matNew.mat> created\n")
}
Example #4
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")
}
Example #5
0
func atob(s string) bool {
	if s == ".t." || s == ".T." {
		return true
	}
	if s == ".f." || s == ".F." {
		return false
	}
	return io.Atob(s)
}
Example #6
0
// xfem_init initialises variables need by xfem model
func (o *ElemU) xfem_init(edat *inp.ElemData) {

	// flags
	o.Xmat, o.Xcrk, o.Xfem = false, false, false
	if s_xmat, found := io.Keycode(edat.Extra, "xmat"); found {
		o.Xmat = io.Atob(s_xmat)
		o.Xfem = true
	}
	if s_xcrk, found := io.Keycode(edat.Extra, "xcrk"); found {
		o.Xcrk = io.Atob(s_xcrk)
		o.Xfem = true
	}

	// skip if not XFEM
	if !o.Xfem {
		return
	}

	// auxiliary variables
	switch {
	case o.Xmat:
		o.Na = 1
	case o.Xcrk:
		o.Na = 4 // TODO: this is 2D only
		if o.Ndim != 2 {
			chk.Panic("xfem with crack works in 2D only for now")
		}
	}

	// allocate extrem XFEM coupling matrices
	nverts := o.Cell.Shp.Nverts
	o.Amap = make([]int, o.Na*nverts)
	o.Kua = la.MatAlloc(o.Nu, o.Na)
	o.Kau = la.MatAlloc(o.Na, o.Nu)
	o.Kaa = la.MatAlloc(o.Na, o.Na)
}
Example #7
0
func main() {

	// input data
	simfile := "simfile.sim"
	zmin := 0.0
	zmax := 3.0
	npts := 11

	// parse flags
	flag.Parse()
	if len(flag.Args()) > 0 {
		simfile = flag.Arg(0)
	}
	if len(flag.Args()) > 1 {
		zmin = io.Atof(flag.Arg(1))
	}
	if len(flag.Args()) > 2 {
		zmax = io.Atob(flag.Arg(2))
	}
	if len(flag.Args()) > 3 {
		npts = io.Atoi(flag.Arg(3))
	}

	// print input data
	io.Pf("\nInput data\n")
	io.Pf("==========\n")
	io.Pf("  simfile  = %30s // simulation filename\n", simfile)
	io.Pf("  zmin     = %30s // min elevation\n", zmin)
	io.Pf("  zmax     = %30v // max elevation\n", zmax)
	io.Pf("  npts     = %30v // number of points\n", npts)
	io.Pf("\n")

	// sim file
	sim := inp.ReadSim("", simfile, false)
	if sim == nil {
		io.PfRed("cannot read sim file\n")
		return
	}

	// layer
	var lay fem.GeoLayer
	lay.Zmin = zmin
	lay.Zmax = zmax
	lay.Cl = sim.WaterRho0 / sim.WaterBulk
	//if !lay.ReadPorousParameters(sim.Regions[0],
	// TODO

}
Example #8
0
func GetSeepFaceFlags(extra string) (Macaulay bool, BetRamp, Kappa float64) {

	// defaults
	Macaulay = false
	BetRamp = math.Ln2 / 0.01
	Kappa = 1.0

	// use macaulay function ?
	if s_mac, found := io.Keycode(extra, "mac"); found {
		Macaulay = io.Atob(s_mac)
	}

	// coefficient for smooth ramp function
	if s_bet, found := io.Keycode(extra, "bet"); found {
		BetRamp = io.Atof(s_bet)
	}

	// κ coefficient
	if s_kap, found := io.Keycode(extra, "kap"); found {
		Kappa = io.Atof(s_kap)
	}
	return
}
Example #9
0
func main() {

	// catch errors
	defer func() {
		if err := recover(); err != nil {
			if mpi.Rank() == 0 {
				chk.Verbose = true
				for i := 8; i > 3; i-- {
					chk.CallerInfo(i)
				}
				io.PfRed("ERROR: %v\n", err)
			}
		}
		mpi.Stop(false)
	}()
	mpi.Start(false)

	// message
	if mpi.Rank() == 0 {
		io.PfWhite("\nGofem v3 -- Go Finite Element Method\n\n")
		io.Pf("Copyright 2015 Dorival Pedroso and Raul Durand. All rights reserved.\n")
		io.Pf("Use of this source code is governed by a BSD-style\n")
		io.Pf("license that can be found in the LICENSE file.\n\n")
	}

	// simulation filenamepath
	flag.Parse()
	var fnamepath string
	if len(flag.Args()) > 0 {
		fnamepath = flag.Arg(0)
	} else {
		chk.Panic("Please, provide a filename. Ex.: cylinder.sim")
	}

	// check extension
	if io.FnExt(fnamepath) == "" {
		fnamepath += ".sim"
	}

	// other options
	erasefiles := true
	verbose := true
	if len(flag.Args()) > 1 {
		erasefiles = io.Atob(flag.Arg(1))
	}
	if len(flag.Args()) > 2 {
		verbose = io.Atob(flag.Arg(2))
	}

	// profiling?
	defer utl.DoProf(false)()

	// start global variables and log
	if !fem.Start(fnamepath, erasefiles, verbose) {
		chk.Panic("Start failed\n")
		return
	}

	// make sure to flush log
	defer fem.End()

	// run simulation
	if !fem.Run() {
		io.PfRed("ERROR: cannot run simulation\n")
	}
}
Example #10
0
func main() {

	// finalise analysis process and catch errors
	defer out.End()

	// input data
	simfn := "data/twoqua4.sim"
	exnwl := false
	stgidx := 0

	// parse flags
	flag.Parse()
	if len(flag.Args()) > 0 {
		simfn = flag.Arg(0)
	}
	if len(flag.Args()) > 1 {
		exnwl = io.Atob(flag.Arg(1))
	}
	if len(flag.Args()) > 2 {
		stgidx = io.Atoi(flag.Arg(2))
	}

	// check extension
	if io.FnExt(simfn) == "" {
		simfn += ".sim"
	}

	// print input data
	io.Pf("\nInput data\n")
	io.Pf("==========\n")
	io.Pf("  simfn   = %30s // simulation filename\n", simfn)
	io.Pf("  exnwl   = %30v // extrapolate nwl\n", exnwl)
	io.Pf("  stgidx  = %30v // stage index\n", stgidx)
	io.Pf("\n")

	// start analysis process
	out.Start(simfn, stgidx, 0)

	// global variables
	ndim = out.Dom.Msh.Ndim
	verts = out.Dom.Msh.Verts
	cells = out.Dom.Msh.Cells
	nodes = out.Dom.Nodes
	elems = out.Dom.Elems
	dirout = fem.Global.Sim.Data.DirOut
	fnkey = fem.Global.Sim.Data.FnameKey
	steady = fem.Global.Sim.Data.Steady

	// flags
	has_u := out.Dom.YandC["ux"]
	has_pl := out.Dom.YandC["pl"]
	has_pg := out.Dom.YandC["pg"]
	has_sig := out.Ipkeys["sx"]
	has_nwl := out.Ipkeys["nwlx"]
	has_p := has_pl || has_pg
	lbb := has_u && has_p
	if fem.Global.Sim.Data.NoLBB {
		lbb = false
	}

	// buffers
	pvd := make(map[string]*bytes.Buffer)
	geo := make(map[string]*bytes.Buffer)
	vtu := make(map[string]*bytes.Buffer)
	if _, ok := out.Dom.YandC["ux"]; ok {
		pvd["u"] = new(bytes.Buffer)
		geo["u"] = new(bytes.Buffer)
		vtu["u"] = new(bytes.Buffer)
	}
	if _, ok := out.Dom.YandC["fl"]; ok {
		pvd["fl"] = new(bytes.Buffer)
		geo["fl"] = new(bytes.Buffer)
		vtu["fl"] = new(bytes.Buffer)
	}
	if _, ok := out.Dom.YandC["pl"]; ok {
		pvd["pl"] = new(bytes.Buffer)
		geo["pl"] = new(bytes.Buffer)
		vtu["pl"] = new(bytes.Buffer)
	}
	if _, ok := out.Dom.YandC["pg"]; ok {
		pvd["pg"] = new(bytes.Buffer)
		geo["pg"] = new(bytes.Buffer)
		vtu["pg"] = new(bytes.Buffer)
	}
	if len(out.Ipkeys) > 0 {
		pvd["ips"] = new(bytes.Buffer)
		geo["ips"] = new(bytes.Buffer)
		vtu["ips"] = new(bytes.Buffer)
	}
	if exnwl {
		pvd["ex_nwl"] = new(bytes.Buffer)
		geo["ex_nwl"] = new(bytes.Buffer)
		vtu["ex_nwl"] = new(bytes.Buffer)
	}

	// extrapolated values keys
	extrap_keys := []string{"nwlx", "nwly"}
	if ndim == 3 {
		extrap_keys = []string{"nwlx", "nwly", "nwlz"}
	}

	// headers
	for _, b := range pvd {
		pvd_header(b)
	}

	// process results
	for tidx, t := range out.Sum.OutTimes {

		// input results into domain
		if !out.Dom.In(out.Sum, tidx, true) {
			chk.Panic("cannot load results into domain; please check log file")
		}

		// message
		io.PfWhite("time     = %g\r", t)

		// generate topology
		if tidx == 0 {
			for label, b := range geo {
				topology(b, label == "ips", lbb)
			}

			// allocate integration points values
			ipvals = make([]map[string]float64, len(out.Ipoints))
			for i, _ := range out.Ipoints {
				ipvals[i] = make(map[string]float64)
			}
		}

		// get integration points values @ time t
		for i, p := range out.Ipoints {
			vals := p.Calc(out.Dom.Sol)
			for key, val := range vals {
				ipvals[i][key] = val
			}
		}

		// compute extrapolated values
		if exnwl {
			out.ComputeExtrapolatedValues(extrap_keys)
		}

		// for each data buffer
		for label, b := range vtu {

			// reset buffer
			b.Reset()

			// points data
			if label == "ips" {
				pdata_open(b)
				if has_sig {
					pdata_write(b, "sig", skeys, true)
				}
				if has_nwl {
					pdata_write(b, "nwl", nwlkeys, true)
				}
				for key, _ := range out.Ipkeys {
					if !is_sig[key] && !is_nwl[key] {
						pdata_write(b, key, []string{key}, true)
					}
				}
				pdata_close(b)
			} else {
				pdata_open(b)
				pdata_write(b, label, label2keys[label], false)
				pdata_close(b)
			}

			// cells data
			cdata_write(b, label == "ips")

			// write vtu file
			vtu_write(geo[label], b, tidx, label)
		}

		// pvd
		for label, b := range pvd {
			pvd_line(b, tidx, t, label)
		}
	}

	// write pvd files
	for label, b := range pvd {
		pvd_write(b, label)
	}
}