func main() { // catch errors var tst testing.T defer func() { if mpi.Rank() == 0 { if err := recover(); err != nil { io.PfRed("ERROR: %v\n", err) } if tst.Failed() { io.PfRed("test failed\n") } } mpi.Stop(false) }() mpi.Start(false) // start global variables and log if !fem.Start("data/p01.sim", true, true) { tst.Error("Start failed\n") return } // make sure to flush log defer fem.End() // run simulation if !fem.Run() { tst.Error("Run failed\n") return } }
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") }
func Test_out02(tst *testing.T) { // finalise analysis process and catch errors defer func() { if err := recover(); err != nil { tst.Fail() io.PfRed("ERROR: %v\n", err) } else { fem.End() } }() // test title //verbose() chk.PrintTitle("out02") // run FE simulation if !fem.Start("data/twoqua4.sim", true, chk.Verbose) { chk.Panic("cannot start FE simulation") } if !fem.Run() { chk.Panic("cannot run FE simulation") } // start analysis process Start("data/twoqua4.sim", 0, 0) // get second ip coordinates xip := Ipoints[1].X io.Pfcyan("xip = %v\n", xip) // define points Define("A", N{-1}) Define("ips", Along{{xip[0], 0}, {xip[0], 1}}) // load results LoadResults(nil) // solution var sol ana.CteStressPstrain sol.Init(fun.Prms{ &fun.Prm{N: "qnH", V: -50}, &fun.Prm{N: "qnV", V: -100}, }) // check displacements tolu := 1e-15 x := GetCoords("A") ux := GetRes("ux", "A", 0) uy := GetRes("uy", "A", 0) io.Pforan("ux=%v uy=%v\n", ux, uy) for j, t := range Times { io.Pfyel("t=%g\n", t) sol.CheckDispl(tst, t, []float64{ux[j], uy[j]}, x, tolu) } }
func Test_plot01(tst *testing.T) { // test title //verbose() chk.PrintTitle("plot01") // constants datadir := "$GOPATH/src/github.com/cpmech/gofem/fem/data/" simfn := "p02.sim" // run FE simulation defer fem.End() if !fem.Start(datadir+simfn, true, chk.Verbose) { chk.Panic("cannot start FE simulation") } if !fem.Run() { chk.Panic("cannot run FE simulation") } // start post-processing Start(datadir+simfn, 0, 0) // define entities Define("A", N{1}) Define("B", At{0, 1}) //Define("left", Along{{0, 0}, {0, 10}}) Define("left", AlongY{0}) // 0 => x_cte // load results LoadResults(nil) plA := GetRes("pl", "A", 0) Splot("liquid pressure") Plot("t", "pl", "B", plt.Fmt{C: "b", M: "."}, -1) Plot("t", plA, "A", plt.Fmt{C: "r", M: "."}, -1) Splot("") Plot("pl", "pl", "A", plt.Fmt{C: "k", M: "o"}, -1) Splot("") Plot("pl", "y", "left", plt.Fmt{C: "b", M: "o"}, 0) Plot("pl", "y", "left", plt.Fmt{C: "g", M: "o"}, -1) Splot("") io.Pforan("T = %v\n", Times) last := len(Times) - 1 Plot("y", "pl", "left", plt.Fmt{C: "b", M: "o", L: io.Sf("t=%g", Times[0])}, 0) Plot("y", "pl", "left", plt.Fmt{C: "m", M: "*", Lw: 2, L: io.Sf("t=%g", Times[last])}, -1) //Draw("", "", true, nil) Draw("", "", false, nil) }
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") }
func main() { // catch errors var tst testing.T defer func() { if mpi.Rank() == 0 { if err := recover(); err != nil { io.PfRed("ERROR: %v\n", err) } if tst.Failed() { io.PfRed("test failed\n") } } mpi.Stop(false) }() mpi.Start(false) // start global variables and log if !fem.Start("data/spo751.sim", true, true) { tst.Error("Start failed\n") return } // make sure to flush log defer fem.End() // run simulation if !fem.Run() { tst.Error("Run failed\n") return } // check skipK := true tolK := 1e-17 tolu := 1e-12 tols := 1e-14 fem.TestingCompareResultsU(&tst, "data/spo751.sim", "cmp/spo751.cmp", tolK, tolu, tols, skipK, true) }
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") } }
func Test_out01(tst *testing.T) { // finalise analysis process and catch errors defer func() { if err := recover(); err != nil { tst.Fail() io.PfRed("ERROR: %v\n", err) } else { fem.End() } }() // test title //verbose() chk.PrintTitle("out01") // run FE simulation if !fem.Start("data/onequa4.sim", true, chk.Verbose) { chk.Panic("cannot start FE simulation") } if !fem.Run() { chk.Panic("cannot run FE simulation") } // start analysis process Start("data/onequa4.sim", 0, 0) // define points Define("A B C D", N{0, 1, 2, 3}) Define("a b c d", P{{0, 0}, {0, 1}, {-1, 2}, {-1, 3}}) Define("!right side", Along{{1, 0}, {1, 1}}) io.Pfcyan("Entities = %v\n", Results) // check slices nnod := 4 nele := 1 nip := 4 chk.IntAssert(len(Dom.Nodes), nnod) chk.IntAssert(len(Ipoints), nele*nip) chk.IntAssert(len(Cid2ips), 1) chk.IntAssert(len(Ipkey2ips), 4) chk.IntAssert(len(Ipkeys), 4) for key, ips := range Ipkey2ips { chk.Ints(tst, io.Sf("%s : ips", key), ips, utl.IntRange(4)) } // load results LoadResults(nil) // check points nlabels := []string{"A", "B", "C", "D"} for _, l := range nlabels { if _, ok := Results[l]; !ok { chk.Panic("1: %q alias in Entities is not available", l) } } plabels := []string{"a", "b", "c", "d"} for _, l := range plabels { if _, ok := Results[l]; !ok { chk.Panic("2: %q alias in Entities is not available", l) } } if _, ok := Results["right side"]; !ok { chk.Panic("3: %q alias in Entities is not available", "right side") } // check u-keys ukeys := []string{"ux", "uy"} for _, l := range nlabels { for _, p := range Results[l] { //io.Pfyel("p = %v\n", p) if p == nil { chk.Panic("1: p is nil") } for _, key := range ukeys { if _, ok := p.Vals[key]; !ok { chk.Panic("%s is not available in point", key) } } } } // check s-keys skeys := fem.StressKeys() for _, l := range plabels { for _, p := range Results[l] { //io.Pfgreen("q = %v\n", p) if p == nil { chk.Panic("2: p is nil") } for _, key := range skeys { if _, ok := p.Vals[key]; !ok { chk.Panic("%s is not available in point", key) } } } } // check GetRes uxC := GetRes("ux", "C", 0) uxR := GetRes("ux", "right side", -1) io.Pforan("uxC = %v\n", uxC) io.Pforan("uxR = %v\n", uxR) chk.IntAssert(len(uxC), 2) idx := len(uxC) - 1 chk.Vector(tst, "uxR", 1e-17, uxR, []float64{uxC[idx], uxC[idx]}) // solution var sol ana.CteStressPstrain sol.Init(fun.Prms{ &fun.Prm{N: "qnH", V: -50}, &fun.Prm{N: "qnV", V: -100}, }) // check displacements tolu := 1e-15 for _, l := range nlabels { x := GetCoords(l) ux := GetRes("ux", l, 0) uy := GetRes("uy", l, 0) io.Pforan("ux=%v uy=%v\n", ux, uy) for j, t := range Times { io.Pfyel("t=%g\n", t) sol.CheckDispl(tst, t, []float64{ux[j], uy[j]}, x, tolu) } } // check stresses tolσ := 1e-14 for _, l := range plabels { x := GetCoords(l) sx := GetRes("sx", l, 0) sy := GetRes("sy", l, 0) sz := GetRes("sz", l, 0) sxy := GetRes("sxy", l, 0) for j, t := range Times { io.Pfyel("t=%g\n", t) sol.CheckStress(tst, t, []float64{sx[j], sy[j], sz[j], sxy[j]}, x, tolσ) } } }
// Start starts handling of results given a simulation input file func Start(simfnpath string, stageIdx, regionIdx int) { // start FE global structure fem.Global.LogPrefix = "out_" erasefiles := false verbose := false if !fem.Start(simfnpath, erasefiles, verbose) { chk.Panic("cannot start analysis process with simfnpath=%q\n", simfnpath) } // read summary Sum = fem.ReadSum(fem.Global.Dirout, fem.Global.Fnkey) if Sum == nil { chk.Panic("cannot read summary file for simulation=%q\n", simfnpath) } // allocate domain distr := false Dom = fem.NewDomain(fem.Global.Sim.Regions[regionIdx], distr) if !Dom.SetStage(stageIdx, fem.Global.Sim.Stages[stageIdx], distr) { chk.Panic("cannot allocate domain\n") } // clear previous data Ipoints = make([]*fem.OutIpData, 0) Cid2ips = make([][]int, len(Dom.Msh.Cells)) Ipkey2ips = make(map[string][]int) Ipkeys = make(map[string]bool) Planes = make(map[string]*PlaneData) Results = make(map[string]Points) TimeInds = make([]int, 0) Times = make([]float64, 0) Splots = make([]*SplotDat, 0) // bins m := Dom.Msh δ := TolC * 2 xi := []float64{m.Xmin - δ, m.Ymin - δ} xf := []float64{m.Xmax + δ, m.Ymax + δ} if m.Ndim == 3 { xi = append(xi, m.Zmin-δ) xf = append(xf, m.Zmax+δ) } err := NodBins.Init(xi, xf, Ndiv) if err != nil { chk.Panic("cannot initialise bins for nodes: %v", err) } err = IpsBins.Init(xi, xf, Ndiv) if err != nil { chk.Panic("cannot initialise bins for integration points: %v", err) } // add nodes to bins for _, nod := range Dom.Nodes { err := NodBins.Append(nod.Vert.C, nod.Vert.Id) if err != nil { return } } // to find limits ndim := Dom.Msh.Ndim IpsMin = make([]float64, ndim) IpsMax = make([]float64, ndim) first := true // add integration points to slice of ips and to bins for cid, ele := range Dom.Cid2elem { if ele == nil { continue } dat := ele.OutIpsData() nip := len(dat) ids := make([]int, nip) for i, d := range dat { // add to bins ipid := len(Ipoints) ids[i] = ipid Ipoints = append(Ipoints, d) err = IpsBins.Append(d.X, ipid) if err != nil { chk.Panic("cannot append to bins of integration points: %v", err) } // set auxiliary map vals := d.Calc(Dom.Sol) for key, _ := range vals { utl.StrIntsMapAppend(&Ipkey2ips, key, ipid) Ipkeys[key] = true } // limits if first { for j := 0; j < ndim; j++ { IpsMin[j] = d.X[j] IpsMax[j] = d.X[j] } first = false } else { for j := 0; j < ndim; j++ { IpsMin[j] = min(IpsMin[j], d.X[j]) IpsMax[j] = max(IpsMax[j], d.X[j]) } } } Cid2ips[cid] = ids } }
func Test_topol01(tst *testing.T) { // test title //verbose() chk.PrintTitle("topol01") // constants datadir := "data/" simfn := "box.sim" // run FE simulation defer fem.End() if !fem.Start(datadir+simfn, true, chk.Verbose) { chk.Panic("cannot start FE simulation") } if !fem.Run() { chk.Panic("cannot run FE simulation") } // start post-processing Start(datadir+simfn, 0, 0) // vertices on plane (indenter/surface) ftag := -31 surf := NodesOnPlane(ftag) vids := []int{48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63} chk.IntAssert(surf.Plane, 2) // perpendicular to z chk.IntAssert(len(surf.Ids), 16) for _, vid := range vids { if !surf.Ids[vid] { chk.Panic("vid=%d is not in map", vid) } } chk.Scalar(tst, "Δx", 1e-15, surf.Dx[0], 4.0/3.0) chk.Scalar(tst, "Δy", 1e-15, surf.Dx[1], 4.0/3.0) chk.Scalar(tst, "Δz", 1e-15, surf.Dx[2], 0) chk.Ints(tst, "Iu", surf.Iu, []int{0, 1}) chk.Scalar(tst, "Δu", 1e-15, surf.Du[0], 4.0/3.0) chk.Scalar(tst, "Δv", 1e-15, surf.Du[1], 4.0/3.0) chk.Vector(tst, "Umin", 1e-15, surf.Umin, []float64{0, 0}) chk.Vector(tst, "Umax", 1e-15, surf.Umax, []float64{4, 4}) chk.Ints(tst, "Nu", surf.Nu, []int{4, 4}) // define entities lx, ly, lz := 4.0, 4.0, 4.0 Define("A", At{lx, ly, lz}) Define("surf", surf) // load results Extrap = []string{"sz"} LoadResults(nil) // displacements Splot("displacements") Plot("t", "uz", "A", plt.Fmt{C: "b", M: "o"}, -1) // stresses on surface V := IntegOnPlane("ex_sz", "surf") Splot("integral of stresses") Plot(Times, V, "surf", plt.Fmt{C: "r", M: "o"}, -1) Csplot.Xlbl = "time" Csplot.Ylbl = "integ(sz)" //Draw("", "", true, nil) Draw("", "", false, nil) }