// register element func init() { // information allocator infogetters["beam"] = func(cellType string, faceConds []*FaceCond) *Info { // new info var info Info // solution variables ykeys := []string{"ux", "uy", "rz"} if Global.Ndim == 3 { ykeys = []string{"ux", "uy", "uz", "rx", "ry", "rz"} } info.Dofs = make([][]string, 2) for m := 0; m < 2; m++ { info.Dofs[m] = ykeys } // maps info.Y2F = map[string]string{"ux": "fx", "uy": "fy", "uz": "fz", "rx": "mx", "ry": "my", "rz": "mz"} // t1 and t2 variables info.T2vars = ykeys return &info } // element allocator eallocators["beam"] = func(cellType string, faceConds []*FaceCond, cid int, edat *inp.ElemData, x [][]float64) Elem { // check if LogErrCond(Global.Ndim == 3, "beam is not implemented for 3D yet") { return nil } // basic data var o Beam o.Cid = cid o.X = x ndim := Global.Ndim ndof := 3 * (ndim - 1) o.Nu = ndof * ndim // parameters matname := edat.Mat matdata := Global.Sim.Mdb.Get(edat.Mat) if LogErrCond(matdata == nil, "materials database failed on getting %q material\n", matname) { return nil } for _, p := range matdata.Prms { switch p.N { case "E": o.E = p.V case "A": o.A = p.V case "Izz": o.Izz = p.V case "rho": o.Rho = p.V } } // vectors and matrices o.T = la.MatAlloc(o.Nu, o.Nu) o.Kl = la.MatAlloc(o.Nu, o.Nu) o.K = la.MatAlloc(o.Nu, o.Nu) o.Ml = la.MatAlloc(o.Nu, o.Nu) o.M = la.MatAlloc(o.Nu, o.Nu) o.ue = make([]float64, o.Nu) o.ζe = make([]float64, o.Nu) o.fxl = make([]float64, o.Nu) o.Rus = make([]float64, o.Nu) // T dx := o.X[0][1] - o.X[0][0] dy := o.X[1][1] - o.X[1][0] l := math.Sqrt(dx*dx + dy*dy) c := dx / l s := dy / l o.T[0][0] = c o.T[0][1] = s o.T[1][0] = -s o.T[1][1] = c o.T[2][2] = 1 o.T[3][3] = c o.T[3][4] = s o.T[4][3] = -s o.T[4][4] = c o.T[5][5] = 1 // aux vars ll := l * l m := o.E * o.A / l n := o.E * o.Izz / (ll * l) // K o.Kl[0][0] = m o.Kl[0][3] = -m o.Kl[1][1] = 12 * n o.Kl[1][2] = 6 * l * n o.Kl[1][4] = -12 * n o.Kl[1][5] = 6 * l * n o.Kl[2][1] = 6 * l * n o.Kl[2][2] = 4 * ll * n o.Kl[2][4] = -6 * l * n o.Kl[2][5] = 2 * ll * n o.Kl[3][0] = -m o.Kl[3][3] = m o.Kl[4][1] = -12 * n o.Kl[4][2] = -6 * l * n o.Kl[4][4] = 12 * n o.Kl[4][5] = -6 * l * n o.Kl[5][1] = 6 * l * n o.Kl[5][2] = 2 * ll * n o.Kl[5][4] = -6 * l * n o.Kl[5][5] = 4 * ll * n la.MatTrMul3(o.K, 1, o.T, o.Kl, o.T) // K := 1 * trans(T) * Kl * T // M m = o.Rho * o.A * l / 420.0 o.Ml[0][0] = 140.0 * m o.Ml[0][3] = 70.0 * m o.Ml[1][1] = 156.0 * m o.Ml[1][2] = 22.0 * l * m o.Ml[1][4] = 54.0 * m o.Ml[1][5] = -13.0 * l * m o.Ml[2][1] = 22.0 * l * m o.Ml[2][2] = 4.0 * ll * m o.Ml[2][4] = 13.0 * l * m o.Ml[2][5] = -3.0 * ll * m o.Ml[3][0] = 70.0 * m o.Ml[3][3] = 140.0 * m o.Ml[4][1] = 54.0 * m o.Ml[4][2] = 13.0 * l * m o.Ml[4][4] = 156.0 * m o.Ml[4][5] = -22.0 * l * m o.Ml[5][1] = -13.0 * l * m o.Ml[5][2] = -3.0 * ll * m o.Ml[5][4] = -22.0 * l * m o.Ml[5][5] = 4.0 * ll * m la.MatTrMul3(o.M, 1, o.T, o.Ml, o.T) // M := 1 * trans(T) * Ml * T // scratchpad. computed @ each ip o.grav = make([]float64, Global.Ndim) o.fi = make([]float64, o.Nu) // return new element return &o } }
// Recompute re-compute matrices after dimensions or parameters are externally changed func (o *Beam) Recompute(withM bool) { // T dx := o.X[0][1] - o.X[0][0] dy := o.X[1][1] - o.X[1][0] l := math.Sqrt(dx*dx + dy*dy) o.L = l c := dx / l s := dy / l o.T[0][0] = c o.T[0][1] = s o.T[1][0] = -s o.T[1][1] = c o.T[2][2] = 1 o.T[3][3] = c o.T[3][4] = s o.T[4][3] = -s o.T[4][4] = c o.T[5][5] = 1 // aux vars ll := l * l m := o.E * o.A / l n := o.E * o.Izz / (ll * l) // K o.Kl[0][0] = m o.Kl[0][3] = -m o.Kl[1][1] = 12 * n o.Kl[1][2] = 6 * l * n o.Kl[1][4] = -12 * n o.Kl[1][5] = 6 * l * n o.Kl[2][1] = 6 * l * n o.Kl[2][2] = 4 * ll * n o.Kl[2][4] = -6 * l * n o.Kl[2][5] = 2 * ll * n o.Kl[3][0] = -m o.Kl[3][3] = m o.Kl[4][1] = -12 * n o.Kl[4][2] = -6 * l * n o.Kl[4][4] = 12 * n o.Kl[4][5] = -6 * l * n o.Kl[5][1] = 6 * l * n o.Kl[5][2] = 2 * ll * n o.Kl[5][4] = -6 * l * n o.Kl[5][5] = 4 * ll * n la.MatTrMul3(o.K, 1, o.T, o.Kl, o.T) // K := 1 * trans(T) * Kl * T // M if withM { m = o.Rho * o.A * l / 420.0 o.Ml[0][0] = 140.0 * m o.Ml[0][3] = 70.0 * m o.Ml[1][1] = 156.0 * m o.Ml[1][2] = 22.0 * l * m o.Ml[1][4] = 54.0 * m o.Ml[1][5] = -13.0 * l * m o.Ml[2][1] = 22.0 * l * m o.Ml[2][2] = 4.0 * ll * m o.Ml[2][4] = 13.0 * l * m o.Ml[2][5] = -3.0 * ll * m o.Ml[3][0] = 70.0 * m o.Ml[3][3] = 140.0 * m o.Ml[4][1] = 54.0 * m o.Ml[4][2] = 13.0 * l * m o.Ml[4][4] = 156.0 * m o.Ml[4][5] = -22.0 * l * m o.Ml[5][1] = -13.0 * l * m o.Ml[5][2] = -3.0 * ll * m o.Ml[5][4] = -22.0 * l * m o.Ml[5][5] = 4.0 * ll * m la.MatTrMul3(o.M, 1, o.T, o.Ml, o.T) // M := 1 * trans(T) * Ml * T } }