func Test_nurbs01(tst *testing.T) { //verbose() chk.PrintTitle("nurbs01") nurbs := get_nurbs_A() faces := nurbs.ExtractSurfaces() spans := nurbs.Elements() ibasis0 := nurbs.IndBasis(spans[0]) ibasis1 := nurbs.IndBasis(spans[1]) io.Pforan("spans = %v\n", spans) chk.Ints(tst, "span0", spans[0], []int{2, 3, 1, 2}) chk.Ints(tst, "span1", spans[1], []int{3, 4, 1, 2}) chk.Ints(tst, "ibasis0", ibasis0, []int{0, 1, 2, 4, 5, 6}) chk.Ints(tst, "ibasis1", ibasis1, []int{1, 2, 3, 5, 6, 7}) shape0 := GetShapeNurbs(nurbs, faces, spans[0]) shape1 := GetShapeNurbs(nurbs, faces, spans[1]) dux := 0.5 duy := 1.0 drx := 2.0 dry := 2.0 r := []float64{0.75, 0.75, 0} shape0.NurbsFunc(shape0.S, shape0.DSdR, r, true, -1) io.Pforan("0: u = %v\n", shape0.U) chk.Scalar(tst, "0: ux", 1e-17, shape0.U[0], (1.0+r[0])*dux/drx) chk.Scalar(tst, "0: uy", 1e-17, shape0.U[1], (1.0+r[1])*duy/dry) chk.Ints(tst, "0: ibasis", shape0.Ibasis, []int{0, 1, 2, 4, 5, 6}) io.Pforan("S(u(r)) = %v\n", shape0.S) shape1.NurbsFunc(shape1.S, shape1.DSdR, r, true, -1) io.Pfpink("\n1: u = %v\n", shape1.U) chk.Scalar(tst, "1: ux", 1e-17, shape1.U[0], 0.5+(1.0+r[0])*dux/drx) chk.Scalar(tst, "1: uy", 1e-17, shape1.U[1], (1.0+r[1])*duy/dry) chk.Ints(tst, "1: ibasis", shape1.Ibasis, []int{1, 2, 3, 5, 6, 7}) if chk.Verbose { gm.PlotNurbs("/tmp/gofem", "tst_nurbs01", nurbs, 21, false, nil) } }
func Test_nurbs03(tst *testing.T) { //verbose() chk.PrintTitle("nurbs03") nurbs := get_nurbs_B() faces := nurbs.ExtractSurfaces() spans := nurbs.Elements() shape0 := GetShapeNurbs(nurbs, faces, spans[0]) shape1 := GetShapeNurbs(nurbs, faces, spans[1]) C0 := [][]float64{{5, 10}, {6.5, 11}, {6.5, 12}, {5, 13}} C1 := [][]float64{{6.5, 11}, {8, 10}, {8, 13}, {6.5, 12}} Cnat := [][]float64{ {-1, 1, 1, -1}, {-1, -1, 1, 1}, } r := []float64{0.75, 0.75, 0} tol := 1e-14 verb := true CheckIsop(tst, shape0, C0, Cnat) CheckIsop(tst, shape1, C1, Cnat) CheckDSdR(tst, shape0, r, tol, verb) CheckDSdR(tst, shape1, r, tol, verb) X0 := get_nurbs_xmat(nurbs, shape0.Ibasis) X1 := get_nurbs_xmat(nurbs, shape1.Ibasis) io.Pforan("X0 = %v\n", X0) io.Pforan("X1 = %v\n", X1) tol = 1e-9 x := []float64{6, 12} CheckDSdx(tst, shape0, X0, x, tol, verb) x = []float64{7, 12} CheckDSdx(tst, shape1, X1, x, tol, verb) if false { gm.PlotNurbs("/tmp/gofem", "tst_nurbs03", nurbs, 21, false, nil) } }
func Test_nurbs04(tst *testing.T) { //verbose() chk.PrintTitle("nurbs04") ori := get_nurbs_A() nurbs := ori.KrefineN(3, false) if false { gm.PlotNurbs("/tmp/gofem", "tst_nurbs04", nurbs, 21, false, nil) } faces := nurbs.ExtractSurfaces() spans := nurbs.Elements() shape0 := GetShapeNurbs(nurbs, faces, spans[0]) chk.Ints(tst, "V0_0", shape0.FaceLocalVerts[0], []int{0, 1, 2}) chk.Ints(tst, "V0_1", shape0.FaceLocalVerts[1], []int{2, 5}) chk.Ints(tst, "V0_2", shape0.FaceLocalVerts[2], []int{3, 4, 5}) chk.Ints(tst, "V0_3", shape0.FaceLocalVerts[3], []int{0, 3}) }
func Test_nurbs01(tst *testing.T) { /* 4 (1,2) (2,2) 6 5 2@o--------------o@3 7 | | | | @ -- control point | | o -- node | | (a,b) -- span | | | | 0 0@o--------------o@1 2 1 (1,1) (2,1) 3 */ //verbose() chk.PrintTitle("nurb01. square with initial stress") // fem analysis := NewFEM("data/nurbs01.sim", "", true, false, false, false, chk.Verbose, 0) // set stage err := analysis.SetStage(0) if err != nil { tst.Errorf("SetStage failed:\n%v", err) return } // initialise solution vectors err = analysis.ZeroStage(0, true) if err != nil { tst.Errorf("ZeroStage failed:\n%v", err) return } // domain dom := analysis.Domains[0] // draw NURBS if false { nurbs := dom.Msh.Cells[0].Shp.Nurbs gm.PlotNurbs("/tmp/gofem", "test_nurbs01", nurbs, 21, false, nil) } // nodes and elements chk.IntAssert(len(dom.Nodes), 4) chk.IntAssert(len(dom.Elems), 1) // check dofs for _, nod := range dom.Nodes { chk.IntAssert(len(nod.Dofs), 2) chk.StrAssert(nod.Dofs[0].Key, "ux") chk.StrAssert(nod.Dofs[1].Key, "uy") } // check equations nids, eqs := get_nids_eqs(dom) chk.Ints(tst, "eqs", eqs, utl.IntRange(4*2)) chk.Ints(tst, "nids", nids, []int{0, 1, 2, 3}) // check Umap Umaps := [][]int{ {0, 1, 2, 3, 4, 5, 6, 7}, } for i, ele := range dom.Elems { e := ele.(*ElemU) io.Pfpink("%2d : Umap = %v\n", e.Id(), e.Umap) chk.Ints(tst, "Umap", e.Umap, Umaps[i]) } // constraints chk.IntAssert(len(dom.EssenBcs.Bcs), 4) var ct_ux_eqs []int // equations with ux prescribed [sorted] var ct_uy_eqs []int // equations with uy prescribed [sorted] for _, c := range dom.EssenBcs.Bcs { chk.IntAssert(len(c.Eqs), 1) eq := c.Eqs[0] io.Pfgrey("key=%v eq=%v\n", c.Key, eq) switch c.Key { case "ux": ct_ux_eqs = append(ct_ux_eqs, eq) case "uy": ct_uy_eqs = append(ct_uy_eqs, eq) default: tst.Errorf("key %s is incorrect", c.Key) } } sort.Ints(ct_ux_eqs) sort.Ints(ct_uy_eqs) chk.Ints(tst, "equations with ux prescribed", ct_ux_eqs, []int{0, 4}) chk.Ints(tst, "equations with uy prescribed", ct_uy_eqs, []int{1, 3}) // check displacements tolu := 1e-16 for _, n := range dom.Nodes { eqx := n.GetEq("ux") eqy := n.GetEq("uy") u := []float64{dom.Sol.Y[eqx], dom.Sol.Y[eqy]} chk.Vector(tst, "u", tolu, u, nil) } // analytical solution qnV, qnH := -100.0, -50.0 ν := 0.25 σx, σy := qnH, qnV σz := ν * (σx + σy) σref := []float64{σx, σy, σz, 0} // check stresses e := dom.Elems[0].(*ElemU) tols := 1e-13 for idx, _ := range e.IpsElem { σ := e.States[idx].Sig io.Pforan("σ = %v\n", σ) chk.Vector(tst, "σ", tols, σ, σref) } }