def test_mat1_01(self): """tests MAT1 initialization from a BDFCard""" # #MAT5 1 700. 300. 900. 400. 200. 600. 90.+ #+ .1 mid = 1 E = 2e7 G = 3e7 nu = 0.4 rho = 1e-50 fields = ['MAT1', mid, E, G, nu, rho] card = BDFCard(fields) mat1 = MAT1.add_card(card) self.assertEqual(mid, mat1.Mid()) self.assertEqual(E, mat1.E()) self.assertEqual(G, mat1.G()) self.assertEqual(nu, mat1.Nu()) self.assertEqual(rho, mat1.Rho()) size = 8 msg = mat1.write_card(size, 'dummy') self.assertEqual(msg, 'MAT1 1 2.+7 3.+7 .4 1.-50\n') size = 16 expected = 'MAT1* 1 20000000. 30000000. .4\n* 1.-50\n' actual = mat1.write_card(size, is_double=False) msg = 'actual=\n%s\nexpected=\n%s' % (actual, expected) self.assertEqual(actual, expected, msg)
def test_mat1_01(self): # #MAT5 1 700. 300. 900. 400. 200. 600. 90.+ #+ .1 mid = 1 E = 2e7 G = 3e7 nu = 0.4 rho = 1e-50 fields = ['MAT1', mid, E, G, nu, rho] card = BDFCard(fields) mat1 = MAT1(card) self.assertEquals(mid, mat1.Mid()) self.assertEquals(E, mat1.E()) self.assertEquals(G, mat1.G()) self.assertEquals(nu, mat1.Nu()) self.assertEquals(rho, mat1.Rho()) size = 8 msg = mat1.write_bdf(size, 'dummy') self.assertEquals( msg, 'MAT1 1 2.+7 3.+7 .4 1.-50\n') size = 16 msg = mat1.write_bdf(size, 'dummy') self.assertEquals( msg, 'MAT1* 1 20000000. 30000000. .4\n* 1.-50\n' )
def test_mat1_01(self): # #MAT5 1 700. 300. 900. 400. 200. 600. 90.+ #+ .1 mid = 1 E = 2e7 G = 3e7 nu = 0.4 rho = 1e-50 fields = ['MAT1', mid, E, G, nu, rho] card = BDFCard(fields) mat1 = MAT1.add_card(card) self.assertEqual(mid, mat1.Mid()) self.assertEqual(E, mat1.E()) self.assertEqual(G, mat1.G()) self.assertEqual(nu, mat1.Nu()) self.assertEqual(rho, mat1.Rho()) size = 8 msg = mat1.write_card(size, 'dummy') self.assertEqual(msg, 'MAT1 1 2.+7 3.+7 .4 1.-50\n') size = 16 expected = 'MAT1* 1 20000000. 30000000. .4\n* 1.-50\n' actual = mat1.write_card(size, is_double=False) msg = 'actual=\n%s\nexpected=\n%s' % (actual, expected) self.assertEqual(actual, expected, msg)
def build(): from pyNastran.bdf.bdf import BDF, GRID, CQUAD4, PSHELL, PROD, MAT1 model = BDF(debug=False) xyz1 = [0., 0., 0.] xyz2 = [0., 1., 0.] xyz3 = [1., 1., 0.] xyz4 = [1., 0., 0.] model.nodes[1] = GRID(nid=1, cp=0, xyz=xyz1) model.nodes[2] = GRID(nid=2, cp=0, xyz=xyz2) model.nodes[3] = GRID(nid=3, cp=0, xyz=xyz3) model.nodes[4] = GRID(nid=4, cp=0, xyz=xyz4) model.elements[1] = CQUAD4(eid=1, pid=100, nids=[1, 2, 3, 4]) model.properties[100] = PSHELL(pid=100, mid1=1000, t=0.1) model.materials[1000] = MAT1(mid=1000, E=1e7, G=None, nu=0.3)
def get_mass(self, nid1, nid2, xyz1, xyz2, eid, pid, mid, A, J, c, nsm, E, G, nu, rho, L): """tests a CROD and a CONROD""" model = BDF(debug=False) lines = [ 'conrod,%i, %i, %i, %i, %f, %f, %f, %f' % (eid, nid1, nid2, mid, A, J, c, nsm) ] card = model.process_card(lines) cardi = BDFCard(card) conrod = CONROD.add_card(cardi) model._add_element_object(conrod) card = model.elements[eid] node_ids = card.node_ids assert node_ids == [nid1, nid2], node_ids # probably wrong lines = ['crod,%i, %i, %i, %i' % (eid + 1, pid, nid1, nid2)] card = model.process_card(lines) cardi = BDFCard(card) crod = CROD.add_card(cardi) model._add_element_object(crod) card = model.elements[eid + 1] node_ids = card.node_ids assert node_ids == [nid1, nid2], node_ids # probably wrong lines = ['ctube,%i, %i, %i, %i' % (eid + 2, pid + 1, nid1, nid2)] card = model.process_card(lines) cardi = BDFCard(card) ctube = CTUBE.add_card(cardi) model._add_element_object(ctube) card = model.elements[eid + 2] node_ids = card.node_ids assert node_ids == [nid1, nid2], node_ids # probably wrong lines = ['prod,%i, %i, %f, %f, %f, %f' % (pid, mid, A, J, c, nsm)] card = model.process_card(lines) cardi = BDFCard(card) prod = PROD.add_card(cardi) model._add_property_object(prod) #self.pid = integer(card, 1, 'pid') #self.mid = integer(card, 2, 'mid') #self.OD1 = double(card, 3, 'OD1') #self.t = double_or_blank(card, 4, 't', self.OD1 / 2.) #self.nsm = double_or_blank(card, 5, 'nsm', 0.0) #self.OD2 = double_or_blank(card, 6, 'OD2', self.OD1) OD1 = sqrt(4 * A / pi) t = 0. OD2 = OD1 lines = [ 'ptube,%i, %i, %f, %f, %f, %f' % (pid + 1, mid, OD1, t, nsm, OD2) ] card = model.process_card(lines) cardi = BDFCard(card) ptube = PTUBE.add_card(cardi) model._add_property_object(ptube) lines = ['mat1,%i, %.2e, %.2e, %f, %f' % (mid, E, G, nu, rho)] card = model.process_card(lines) cardi = BDFCard(card) card = MAT1.add_card(cardi) model._add_structural_material_object(card) lines = [ 'grid,%i, %i, %f, %f, %f' % (nid1, 0, xyz1[0], xyz1[1], xyz1[2]) ] card = model.process_card(lines) cardi = BDFCard(card) card = GRID.add_card(cardi) model._add_node_object(card) lines = [ 'grid,%i, %i, %f, %f, %f' % (nid2, 0, xyz2[0], xyz2[1], xyz2[2]) ] card = model.process_card(lines) cardi = BDFCard(card) card = GRID.add_card(cardi) model._add_node_object(card) model.cross_reference() mass = L * (rho * A + nsm) # conrod self.assertEqual(conrod.eid, eid) self.assertEqual(conrod.Pid(), -10) self.assertEqual(conrod.Mid(), mid) self.assertEqual(conrod.Length(), L) self.assertEqual(conrod.Nsm(), nsm) self.assertEqual(conrod.Mass(), mass) self.assertEqual(conrod.E(), E) self.assertEqual(conrod.G(), G) self.assertEqual(conrod.Area(), A) self.assertEqual(conrod.J(), J) self.assertEqual(conrod.C(), c) self.assertEqual(conrod.Rho(), rho) # crod self.assertEqual(crod.eid, eid + 1) self.assertEqual(crod.Pid(), pid) self.assertEqual(crod.Mid(), mid) self.assertEqual(crod.Length(), L) self.assertEqual(crod.Nsm(), nsm) self.assertEqual(crod.Mass(), mass) self.assertEqual(crod.E(), E) self.assertEqual(crod.G(), G) self.assertEqual(crod.Area(), A) self.assertEqual(crod.J(), J) self.assertEqual(crod.C(), c) self.assertEqual(crod.Rho(), rho) #self.assertEqual(crod.Nu(), nu) # prod self.assertEqual(prod.Pid(), pid) self.assertEqual(prod.Mid(), mid) self.assertEqual(prod.Nsm(), nsm) self.assertEqual(prod.E(), E) self.assertEqual(prod.G(), G) self.assertEqual(prod.Area(), A) self.assertEqual(prod.J(), J) self.assertEqual(prod.C(), c) self.assertEqual(prod.Rho(), rho) # ctube self.assertEqual(ctube.eid, eid + 2) self.assertEqual(ctube.Pid(), pid + 1) self.assertEqual(ctube.Mid(), mid) self.assertEqual(ctube.Length(), L) self.assertEqual(ctube.Nsm(), nsm) self.assertAlmostEqual(ctube.Mass(), mass, 5) self.assertEqual(ctube.E(), E) self.assertEqual(ctube.G(), G) self.assertAlmostEqual(ctube.Area(), A, 5) ctube.J() self.assertEqual(ctube.Rho(), rho) # ptube self.assertEqual(ptube.Pid(), pid + 1) self.assertEqual(ptube.Mid(), mid) self.assertEqual(ptube.Nsm(), nsm) self.assertEqual(ptube.E(), E) self.assertEqual(ptube.G(), G) self.assertAlmostEqual(ptube.Area(), A, 5) ptube.J() self.assertEqual(ptube.Rho(), rho)
def test_pcomp_02(self): """ symmetrical, nsm=0.0 and nsm=1.0 """ pid = 1 z0 = 0. nsm = 0. sb = 0. ft = 0. tref = 0. ge = 0. lam = 'SYM' # isSymmetrical SYM Mid = [1, 2, 3] theta = [0., 10., 20.] T = [.1, .2, .3] sout = [1, 1, 0] # 0-NO, 1-YES data = [pid, z0, nsm, sb, ft, tref, ge, lam, Mid, T, theta, sout] p = PCOMP.add_op2_data(data) self.assertTrue(p.isSymmetrical()) self.assertEqual(p.nPlies(), 6) self.assertAlmostEqual(p.Thickness(), 1.2) self.assertAlmostEqual(p.Thickness(0), 0.1) self.assertAlmostEqual(p.Thickness(1), 0.2) self.assertAlmostEqual(p.Thickness(2), 0.3) self.assertAlmostEqual(p.Thickness(3), 0.1) self.assertAlmostEqual(p.Thickness(4), 0.2) self.assertAlmostEqual(p.Thickness(5), 0.3) with self.assertRaises(IndexError): p.Thickness(6) self.assertAlmostEqual(p.Theta(0), 0.) self.assertAlmostEqual(p.Theta(1), 10.) self.assertAlmostEqual(p.Theta(2), 20.) self.assertAlmostEqual(p.Theta(3), 0.) self.assertAlmostEqual(p.Theta(4), 10.) self.assertAlmostEqual(p.Theta(5), 20.) with self.assertRaises(IndexError): p.Theta(6) self.assertEqual(p.Mid(0), 1) self.assertEqual(p.Mid(1), 2) self.assertEqual(p.Mid(2), 3) self.assertEqual(p.Mid(3), 1) self.assertEqual(p.Mid(4), 2) self.assertEqual(p.Mid(5), 3) with self.assertRaises(IndexError): p.Mid(6) self.assertEqual(p.Mids(), [1, 2, 3, 1, 2, 3]) self.assertEqual(p.sout(0), 'YES') self.assertEqual(p.sout(1), 'YES') self.assertEqual(p.sout(2), 'NO') self.assertEqual(p.sout(3), 'YES') self.assertEqual(p.sout(4), 'YES') self.assertEqual(p.sout(5), 'NO') with self.assertRaises(IndexError): p.sout(6) mid = 1 E = None G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None Mcsid = None mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, Mcsid] with self.assertRaises(ValueError): m = MAT1.add_op2_data(mat1) G = 42. mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, Mcsid] m = MAT1.add_op2_data(mat1) for iply in range(len(p.plies)): mid = p.plies[iply][0] p.mids[iply] = m # MAT1 p.mids_ref = p.mids #Rho self.assertAlmostEqual(p.Rho(0), 1.0) self.assertAlmostEqual(p.Rho(1), 1.0) self.assertAlmostEqual(p.Rho(2), 1.0) self.assertAlmostEqual(p.Rho(3), 1.0) self.assertAlmostEqual(p.Rho(4), 1.0) self.assertAlmostEqual(p.Rho(5), 1.0) with self.assertRaises(IndexError): p.Rho(6) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 1.2) self.assertAlmostEqual(p.MassPerArea(0), 0.1) self.assertAlmostEqual(p.MassPerArea(1), 0.2) self.assertAlmostEqual(p.MassPerArea(2), 0.3) self.assertAlmostEqual(p.MassPerArea(3), 0.1) self.assertAlmostEqual(p.MassPerArea(4), 0.2) self.assertAlmostEqual(p.MassPerArea(5), 0.3) with self.assertRaises(IndexError): p.MassPerArea(6) self.assertEqual(p.Nsm(), 0.0) #---------------------- # change the nsm to 1.0 p.nsm = 1.0 self.assertEqual(p.Nsm(), 1.0) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 2.2) self.assertAlmostEqual(p.MassPerArea(0, method='nplies'), 0.1+1/6.) self.assertAlmostEqual(p.MassPerArea(1, method='nplies'), 0.2+1/6.) self.assertAlmostEqual(p.MassPerArea(2, method='nplies'), 0.3+1/6.) self.assertAlmostEqual(p.MassPerArea(3, method='nplies'), 0.1+1/6.) self.assertAlmostEqual(p.MassPerArea(4, method='nplies'), 0.2+1/6.) self.assertAlmostEqual(p.MassPerArea(5, method='nplies'), 0.3+1/6.) with self.assertRaises(IndexError): p.MassPerArea(6)
def test_pcomp_01(self): """ asymmetrical, nsm=0.0 and nsm=1.0 """ #self.pid = data[0] #self.z0 = data[1] #self.nsm = data[2] #self.sb = data[3] #self.ft = data[4] #self.TRef = data[5] #self.ge = data[6] #self.lam = data[7] #Mid = data[8] #T = data[9] #Theta = data[10] #Sout = data[11] pid = 1 z0 = 0. nsm = 0. sb = 0. ft = 0. tref = 0. ge = 0. lam = 'NO' # isSymmetrical YES/NO Mid = [1, 2, 3] theta = [0., 10., 20.] T = [.1, .2, .3] sout = [1, 1, 0] # 0-NO, 1-YES data = [pid, z0, nsm, sb, ft, tref, ge, lam, Mid, T, theta, sout] p = PCOMP.add_op2_data(data) self.assertFalse(p.isSymmetrical()) self.assertEqual(p.nPlies(), 3) self.assertAlmostEqual(p.Thickness(), 0.6) self.assertAlmostEqual(p.Thickness(0), 0.1) self.assertAlmostEqual(p.Thickness(1), 0.2) self.assertAlmostEqual(p.Thickness(2), 0.3) with self.assertRaises(IndexError): p.Thickness(3) self.assertAlmostEqual(p.Theta(0), 0.) self.assertAlmostEqual(p.Theta(1), 10.) self.assertAlmostEqual(p.Theta(2), 20.) with self.assertRaises(IndexError): p.Theta(3) self.assertEqual(p.Mid(0), 1) self.assertEqual(p.Mid(1), 2) self.assertEqual(p.Mid(2), 3) with self.assertRaises(IndexError): p.Mid(3) self.assertEqual(p.Mids(), [1, 2, 3]) self.assertEqual(p.sout(0), 'YES') self.assertEqual(p.sout(1), 'YES') self.assertEqual(p.sout(2), 'NO') with self.assertRaises(IndexError): p.sout(3) # material... #self.mid = data[0] #self.e = data[1] #self.g = data[2] #self.nu = data[3] #self.rho = data[4] #self.a = data[5] #self.TRef = data[6] #self.ge = data[7] #self.St = data[8] #self.Sc = data[9] #self.Ss = data[10] #self.Mcsid = data[11] mid = 1 E = None G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None Mcsid = None mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, Mcsid] with self.assertRaises(ValueError): m = MAT1.add_op2_data(mat1) G = 42. mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, Mcsid] m = MAT1.add_op2_data(mat1) for iply in range(len(p.plies)): mid = p.plies[iply][0] p.mids[iply] = m # MAT1 #p.mids = [m, m, m] p.mids_ref = p.mids #Rho self.assertAlmostEqual(p.Rho(0), 1.0) self.assertAlmostEqual(p.Rho(1), 1.0) self.assertAlmostEqual(p.Rho(2), 1.0) with self.assertRaises(IndexError): p.Rho(3) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 0.6) self.assertAlmostEqual(p.MassPerArea(0), 0.1) self.assertAlmostEqual(p.MassPerArea(1), 0.2) self.assertAlmostEqual(p.MassPerArea(2), 0.3) with self.assertRaises(IndexError): p.MassPerArea(3) #---------------------- # change the nsm to 1.0 p.nsm = 1.0 self.assertEqual(p.Nsm(), 1.0) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 1.6) self.assertAlmostEqual(p.MassPerArea(0, method='nplies'), 0.1+1/3.) self.assertAlmostEqual(p.MassPerArea(1, method='nplies'), 0.2+1/3.) self.assertAlmostEqual(p.MassPerArea(2, method='nplies'), 0.3+1/3.) self.assertAlmostEqual(p.MassPerArea(0, method='rho*t'), 0.1+1/6.) self.assertAlmostEqual(p.MassPerArea(1, method='rho*t'), 0.2+2/6.) self.assertAlmostEqual(p.MassPerArea(2, method='rho*t'), 0.3+3/6.) self.assertAlmostEqual(p.MassPerArea(0, method='t'), 0.1+1/6.) self.assertAlmostEqual(p.MassPerArea(1, method='t'), 0.2+2/6.) self.assertAlmostEqual(p.MassPerArea(2, method='t'), 0.3+3/6.) with self.assertRaises(IndexError): p.MassPerArea(3, method='nplies') z = p.get_z_locations() z_expected = array([0., T[0], T[0]+T[1], T[0]+T[1]+T[2]]) for za, ze in zip(z, z_expected): self.assertAlmostEqual(za, ze) #z0 = p.z0 = 1.0 z_expected = 1.0 + z_expected z = p.get_z_locations() for za, ze in zip(z, z_expected): self.assertAlmostEqual(za, ze)
def test_pbarl_1(self): """tests the PBARL""" model = BDF(log=None, debug=False) pid = 4 mid = 40 group = 'group' Type = 'bad_type' dim = 42 nsm = 0.5 pbarl = PBARL(pid, mid, Type, dim, group=group, nsm=nsm, comment='comment') with self.assertRaises(ValueError): # Type pbarl.validate() pbarl.Type = 'TUBE' with self.assertRaises(TypeError): # dim pbarl.validate() pbarl.dim = [20.] with self.assertRaises(RuntimeError): pbarl.validate() pbarl.dim = [2., 1.] #with self.assertRaises(ValueError): #pbarl.validate() #pbarl.group = 'MSCBMLO' pbarl.validate() str(pbarl) pbarl.write_card(size=8, is_double=False) pbarl.write_card(size=16, is_double=False) pbarl.write_card(size=16, is_double=True) model.properties[pid] = pbarl nid1 = 52 xyz1 = [0., 0., 0.] model.nodes[nid1] = GRID(nid1, cp=0, xyz=xyz1) nid2 = 53 xyz2 = [1., 0., 0.] model.nodes[nid2] = GRID(nid2, cp=0, xyz=xyz2) E = 30.0e7 G = None nu = 0.3 mat = MAT1(mid, E, G, nu, rho=1.0) model.materials[mid] = mat eid = 42 x = None g0 = None cbar = CBAR(eid, pid, [nid1, nid2], x, g0, offt='GGG', pa=0, pb=0, wa=None, wb=None, comment='') cbar.validate() model.elements[eid] = cbar pbarl._verify(xref=False) model.validate() model.cross_reference() pbarl._verify(xref=True) assert allclose(cbar.Mass(), 9.9247779608), cbar.Mass() mat.rho = 0. assert allclose(cbar.Mass(), 0.5), cbar.Mass()
def test_pcomp_02(self): """ symmetrical, nsm=0.0 and nsm=1.0 """ pid = 1 z0 = 0. nsm = 0. sb = 0. ft = 0. tref = 0. ge = 0. lam = 'SYM' # is_symmetrical SYM Mid = [1, 2, 3] theta = [0., 10., 20.] T = [.1, .2, .3] sout = [1, 1, 0] # 0-NO, 1-YES data = [pid, z0, nsm, sb, ft, tref, ge, lam, Mid, T, theta, sout] p = PCOMP.add_op2_data(data) self.assertTrue(p.is_symmetrical()) self.assertEqual(p.nplies, 6) self.assertAlmostEqual(p.Thickness(), 1.2) self.assertAlmostEqual(p.Thickness(0), 0.1) self.assertAlmostEqual(p.Thickness(1), 0.2) self.assertAlmostEqual(p.Thickness(2), 0.3) self.assertAlmostEqual(p.Thickness(3), 0.1) self.assertAlmostEqual(p.Thickness(4), 0.2) self.assertAlmostEqual(p.Thickness(5), 0.3) with self.assertRaises(IndexError): p.Thickness(6) self.assertAlmostEqual(p.Theta(0), 0.) self.assertAlmostEqual(p.Theta(1), 10.) self.assertAlmostEqual(p.Theta(2), 20.) self.assertAlmostEqual(p.Theta(3), 0.) self.assertAlmostEqual(p.Theta(4), 10.) self.assertAlmostEqual(p.Theta(5), 20.) with self.assertRaises(IndexError): p.Theta(6) self.assertEqual(p.Mid(0), 1) self.assertEqual(p.Mid(1), 2) self.assertEqual(p.Mid(2), 3) self.assertEqual(p.Mid(3), 1) self.assertEqual(p.Mid(4), 2) self.assertEqual(p.Mid(5), 3) with self.assertRaises(IndexError): p.Mid(6) self.assertEqual(p.Mids(), [1, 2, 3, 1, 2, 3]) self.assertEqual(p.sout(0), 'YES') self.assertEqual(p.sout(1), 'YES') self.assertEqual(p.sout(2), 'NO') self.assertEqual(p.sout(3), 'YES') self.assertEqual(p.sout(4), 'YES') self.assertEqual(p.sout(5), 'NO') with self.assertRaises(IndexError): p.sout(6) mid = 1 E = None G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None mcsid = None mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid] with self.assertRaises(ValueError): m = MAT1.add_op2_data(mat1) G = 42. mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid] m = MAT1.add_op2_data(mat1) for iply in range(len(p.plies)): mid = p.plies[iply][0] p.mids[iply] = m # MAT1 p.mids_ref = p.mids #Rho self.assertAlmostEqual(p.Rho(0), 1.0) self.assertAlmostEqual(p.Rho(1), 1.0) self.assertAlmostEqual(p.Rho(2), 1.0) self.assertAlmostEqual(p.Rho(3), 1.0) self.assertAlmostEqual(p.Rho(4), 1.0) self.assertAlmostEqual(p.Rho(5), 1.0) with self.assertRaises(IndexError): p.Rho(6) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 1.2) self.assertAlmostEqual(p.MassPerArea(0), 0.1) self.assertAlmostEqual(p.MassPerArea(1), 0.2) self.assertAlmostEqual(p.MassPerArea(2), 0.3) self.assertAlmostEqual(p.MassPerArea(3), 0.1) self.assertAlmostEqual(p.MassPerArea(4), 0.2) self.assertAlmostEqual(p.MassPerArea(5), 0.3) with self.assertRaises(IndexError): p.MassPerArea(6) self.assertEqual(p.Nsm(), 0.0) #---------------------- # change the nsm to 1.0 p.nsm = 1.0 self.assertEqual(p.Nsm(), 1.0) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 2.2) self.assertAlmostEqual(p.MassPerArea(0, method='nplies'), 0.1 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(1, method='nplies'), 0.2 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(2, method='nplies'), 0.3 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(3, method='nplies'), 0.1 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(4, method='nplies'), 0.2 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(5, method='nplies'), 0.3 + 1 / 6.) with self.assertRaises(IndexError): p.MassPerArea(6)
def test_pcomp_01(self): """ asymmetrical, nsm=0.0 and nsm=1.0 """ #self.pid = data[0] #self.z0 = data[1] #self.nsm = data[2] #self.sb = data[3] #self.ft = data[4] #self.tref = data[5] #self.ge = data[6] #self.lam = data[7] #Mid = data[8] #T = data[9] #Theta = data[10] #Sout = data[11] pid = 1 z0 = 0. nsm = 0. sb = 0. ft = 0. tref = 0. ge = 0. lam = 'NO' # is_symmetrical YES/NO Mid = [1, 2, 3] theta = [0., 10., 20.] T = [.1, .2, .3] sout = [1, 1, 0] # 0-NO, 1-YES data = [pid, z0, nsm, sb, ft, tref, ge, lam, Mid, T, theta, sout] p = PCOMP.add_op2_data(data) self.assertFalse(p.is_symmetrical()) self.assertEqual(p.nplies, 3) self.assertAlmostEqual(p.Thickness(), 0.6) self.assertAlmostEqual(p.Thickness(0), 0.1) self.assertAlmostEqual(p.Thickness(1), 0.2) self.assertAlmostEqual(p.Thickness(2), 0.3) with self.assertRaises(IndexError): p.Thickness(3) self.assertAlmostEqual(p.Theta(0), 0.) self.assertAlmostEqual(p.Theta(1), 10.) self.assertAlmostEqual(p.Theta(2), 20.) with self.assertRaises(IndexError): p.Theta(3) self.assertEqual(p.Mid(0), 1) self.assertEqual(p.Mid(1), 2) self.assertEqual(p.Mid(2), 3) with self.assertRaises(IndexError): p.Mid(3) self.assertEqual(p.Mids(), [1, 2, 3]) self.assertEqual(p.sout(0), 'YES') self.assertEqual(p.sout(1), 'YES') self.assertEqual(p.sout(2), 'NO') with self.assertRaises(IndexError): p.sout(3) # material... #self.mid = data[0] #self.e = data[1] #self.g = data[2] #self.nu = data[3] #self.rho = data[4] #self.a = data[5] #self.tref = data[6] #self.ge = data[7] #self.St = data[8] #self.Sc = data[9] #self.Ss = data[10] #self.mcsid = data[11] mid = 1 E = None G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None mcsid = None mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid] with self.assertRaises(ValueError): m = MAT1.add_op2_data(mat1) G = 42. mat1 = [mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid] m = MAT1.add_op2_data(mat1) for iply in range(len(p.plies)): mid = p.plies[iply][0] p.mids[iply] = m # MAT1 #p.mids = [m, m, m] p.mids_ref = p.mids #Rho self.assertAlmostEqual(p.Rho(0), 1.0) self.assertAlmostEqual(p.Rho(1), 1.0) self.assertAlmostEqual(p.Rho(2), 1.0) with self.assertRaises(IndexError): p.Rho(3) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 0.6) self.assertAlmostEqual(p.MassPerArea(0), 0.1) self.assertAlmostEqual(p.MassPerArea(1), 0.2) self.assertAlmostEqual(p.MassPerArea(2), 0.3) with self.assertRaises(IndexError): p.MassPerArea(3) #---------------------- # change the nsm to 1.0 p.nsm = 1.0 self.assertEqual(p.Nsm(), 1.0) # MassPerArea self.assertAlmostEqual(p.MassPerArea(), 1.6) self.assertAlmostEqual(p.MassPerArea(0, method='nplies'), 0.1 + 1 / 3.) self.assertAlmostEqual(p.MassPerArea(1, method='nplies'), 0.2 + 1 / 3.) self.assertAlmostEqual(p.MassPerArea(2, method='nplies'), 0.3 + 1 / 3.) self.assertAlmostEqual(p.MassPerArea(0, method='rho*t'), 0.1 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(1, method='rho*t'), 0.2 + 2 / 6.) self.assertAlmostEqual(p.MassPerArea(2, method='rho*t'), 0.3 + 3 / 6.) self.assertAlmostEqual(p.MassPerArea(0, method='t'), 0.1 + 1 / 6.) self.assertAlmostEqual(p.MassPerArea(1, method='t'), 0.2 + 2 / 6.) self.assertAlmostEqual(p.MassPerArea(2, method='t'), 0.3 + 3 / 6.) with self.assertRaises(IndexError): p.MassPerArea(3, method='nplies') z = p.get_z_locations() z_expected = array([0., T[0], T[0] + T[1], T[0] + T[1] + T[2]]) for za, ze in zip(z, z_expected): self.assertAlmostEqual(za, ze) #z0 = p.z0 = 1.0 z_expected = 1.0 + z_expected z = p.get_z_locations() for za, ze in zip(z, z_expected): self.assertAlmostEqual(za, ze)
def _beami_stiffness(prop: Union[PBAR, PBARL, PBEAM, PBEAML], mat: MAT1, L: float, Iy: float, Iz: float, k1: Optional[float] = None, k2: Optional[float] = None): """gets the ith Euler-Bernoulli beam stiffness""" E = mat.E() G = mat.G() A = prop.Area() J = prop.J() kaxial = E * A / L ktorsion = G * J / L L2 = L * L if k1 is not None: phiy = 12. * E * Iy / (k1 * G * A * L2) if k2 is not None: phiz = 12. * E * Iy / (k2 * G * A * L2) phiy = 1.0 phiz = 1.0 ky = E * Iy / (L * phiy) kz = E * Iz / (L * phiz) K = np.zeros((12, 12), dtype='float64') # axial K[0, 0] = K[6, 6] = kaxial K[6, 0] = K[0, 6] = -kaxial # torsion K[3, 3] = K[9, 9] = ktorsion K[9, 3] = K[3, 9] = -ktorsion #Fx - 0, 6 #Fy - 1, 7** #Fz - 2, 8 #Mx - 3, 9 #My - 4, 10 #Mz - 5, 11** # bending z (Fy/1/7, Mz/5/11) # 1 5 7 11 # 1 [12 & 6L & -12 & 6L # 5 [6L & 4L^2 & -6L & 2L^2 # 7 [-12 &-6L & 12 & -6L # 11 [6L & 2L^2 & -6L & 4L^2 K[1, 1] = K[7, 7] = 12. * kz K[1, 7] = K[1, 7] = -12. * kz K[1, 5] = K[5, 1] = K[11, 1] = K[1, 11] = 6. * L * kz K[5, 7] = K[7, 5] = K[7, 11] = K[11, 7] = -6. * L * kz K[5, 11] = K[11, 5] = 2. * L2 * kz * (2 - phiz) K[5, 5] = K[11, 11] = 4. * L2 * kz * (4 + phiz) #Fx - 0, 6 #Fy - 1, 7 #Fz - 2, 8** #Mx - 3, 9 #My - 4, 10** #Mz - 5, 11 # bending y (Fz/2/8, My/4/10) # 2 4 8 10 # 2 [12 & 6L & -12 & 6L # 4 [6L & 4L^2 & -6L & 2L^2 # 8 [-12 &-6L & 12 & -6L # 10 [6L & 2L^2 & -6L & 4L^2 K[2, 2] = K[8, 8] = 12. * ky K[2, 8] = K[2, 8] = -12. * ky K[2, 4] = K[4, 2] = K[10, 2] = K[2, 10] = 6. * L * ky K[4, 8] = K[8, 4] = K[8, 10] = K[10, 8] = -6. * L * ky K[4, 10] = K[10, 4] = 2. * L * L * ky * (2. - phiy) K[4, 4] = K[10, 10] = 4. * L * L * ky * (4. + phiy) return K
def get_mass(self, nid1, nid2, xyz1, xyz2, eid, pid, mid, A, J, c, nsm, E, G, nu, rho, L): """tests a CROD and a CONROD""" model = BDF(debug=False) lines = ['conrod,%i, %i, %i, %i, %f, %f, %f, %f' % (eid, nid1, nid2, mid, A, J, c, nsm)] card = model.process_card(lines) cardi = BDFCard(card) conrod = CONROD.add_card(cardi) model._add_element_object(conrod) card = model.elements[eid] node_ids = card.node_ids assert node_ids == [nid1, nid2], node_ids # probably wrong lines = ['crod,%i, %i, %i, %i' % (eid+1, pid, nid1, nid2)] card = model.process_card(lines) cardi = BDFCard(card) crod = CROD.add_card(cardi) model._add_element_object(crod) card = model.elements[eid+1] node_ids = card.node_ids assert node_ids == [nid1, nid2], node_ids # probably wrong lines = ['ctube,%i, %i, %i, %i' % (eid+2, pid+1, nid1, nid2)] card = model.process_card(lines) cardi = BDFCard(card) ctube = CTUBE.add_card(cardi) model._add_element_object(ctube) card = model.elements[eid+2] node_ids = card.node_ids assert node_ids == [nid1, nid2], node_ids # probably wrong lines = ['prod,%i, %i, %f, %f, %f, %f' % (pid, mid, A, J, c, nsm)] card = model.process_card(lines) cardi = BDFCard(card) prod = PROD.add_card(cardi) model._add_property_object(prod) #self.pid = integer(card, 1, 'pid') #self.mid = integer(card, 2, 'mid') #self.OD1 = double(card, 3, 'OD1') #self.t = double_or_blank(card, 4, 't', self.OD1 / 2.) #self.nsm = double_or_blank(card, 5, 'nsm', 0.0) #self.OD2 = double_or_blank(card, 6, 'OD2', self.OD1) OD1 = sqrt(4*A/pi) t = 0. OD2 = OD1 lines = ['ptube,%i, %i, %f, %f, %f, %f' % (pid+1, mid, OD1, t, nsm, OD2)] card = model.process_card(lines) cardi = BDFCard(card) ptube = PTUBE.add_card(cardi) model._add_property_object(ptube) lines = ['mat1,%i, %.2e, %.2e, %f, %f' % (mid, E, G, nu, rho)] card = model.process_card(lines) cardi = BDFCard(card) card = MAT1.add_card(cardi) model._add_structural_material_object(card) lines = ['grid,%i, %i, %f, %f, %f' % (nid1, 0, xyz1[0], xyz1[1], xyz1[2])] card = model.process_card(lines) cardi = BDFCard(card) card = GRID.add_card(cardi) model._add_node_object(card) lines = ['grid,%i, %i, %f, %f, %f' % (nid2, 0, xyz2[0], xyz2[1], xyz2[2])] card = model.process_card(lines) cardi = BDFCard(card) card = GRID.add_card(cardi) model._add_node_object(card) model.cross_reference() mass = L * (rho * A + nsm) # conrod self.assertEqual(conrod.eid, eid) self.assertEqual(conrod.Pid(), None) self.assertEqual(conrod.Mid(), mid) self.assertEqual(conrod.Length(), L) self.assertEqual(conrod.Nsm(), nsm) self.assertEqual(conrod.Mass(), mass) self.assertEqual(conrod.E(), E) self.assertEqual(conrod.G(), G) self.assertEqual(conrod.Area(), A) self.assertEqual(conrod.J(), J) self.assertEqual(conrod.C(), c) self.assertEqual(conrod.Rho(), rho) # crod self.assertEqual(crod.eid, eid+1) self.assertEqual(crod.Pid(), pid) self.assertEqual(crod.Mid(), mid) self.assertEqual(crod.Length(), L) self.assertEqual(crod.Nsm(), nsm) self.assertEqual(crod.Mass(), mass) self.assertEqual(crod.E(), E) self.assertEqual(crod.G(), G) self.assertEqual(crod.Area(), A) self.assertEqual(crod.J(), J) self.assertEqual(crod.C(), c) self.assertEqual(crod.Rho(), rho) #self.assertEqual(crod.Nu(), nu) # prod self.assertEqual(prod.Pid(), pid) self.assertEqual(prod.Mid(), mid) self.assertEqual(prod.Nsm(), nsm) self.assertEqual(prod.E(), E) self.assertEqual(prod.G(), G) self.assertEqual(prod.Area(), A) self.assertEqual(prod.J(), J) self.assertEqual(prod.C(), c) self.assertEqual(prod.Rho(), rho) # ctube self.assertEqual(ctube.eid, eid+2) self.assertEqual(ctube.Pid(), pid+1) self.assertEqual(ctube.Mid(), mid) self.assertEqual(ctube.Length(), L) self.assertEqual(ctube.Nsm(), nsm) self.assertAlmostEqual(ctube.Mass(), mass, 5) self.assertEqual(ctube.E(), E) self.assertEqual(ctube.G(), G) self.assertAlmostEqual(ctube.Area(), A, 5) ctube.J() self.assertEqual(ctube.Rho(), rho) # ptube self.assertEqual(ptube.Pid(), pid+1) self.assertEqual(ptube.Mid(), mid) self.assertEqual(ptube.Nsm(), nsm) self.assertEqual(ptube.E(), E) self.assertEqual(ptube.G(), G) self.assertAlmostEqual(ptube.Area(), A, 5) ptube.J() self.assertEqual(ptube.Rho(), rho)