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 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() { // 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σ) } } }
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) }