def test_solid_05(self): """checks linear static solid material""" mid = 2 pid = 4 rho = 0.1 table_id = 42 cards = [ #$ Solid Nodes ['GRID', 11, 0, 0., 0., 0., 0], ['GRID', 12, 0, 1., 0., 0., 0], ['GRID', 13, 0, 1., 1., 0., 0], ['GRID', 14, 0, 0., 1., 0., 0], ['GRID', 15, 0, 0., 0., 2., 0], ['GRID', 16, 0, 1., 0., 2., 0], ['GRID', 17, 0, 1., 1., 2., 0], ['GRID', 18, 0, 0., 1., 2., 0], # Solids ['CHEXA', 7, pid, 11, 12, 13, 14, 15, 16, 17, 18], ['CTETRA', 8, pid, 11, 12, 13, 15], # Solid Nodes ['GRID', 21, 0, 0., 0., 0., 0,], ['GRID', 22, 0, 1., 0., 0., 0,], ['GRID', 23, 0, 1., 1., 0., 0,], ['GRID', 24, 0, 0., 0., 2., 0,], ['GRID', 25, 0, 1., 0., 2., 0,], ['GRID', 26, 0, 1., 1., 2., 0,], ['CPENTA', 9, pid, 21, 22, 23, 24, 25, 26], # static ['PSOLID', pid, mid, 0], ['MAT1', mid, 1.0, 2.0, 3.0, rho], ['MATS1', mid, table_id, 'PLASTIC', 0.0, 1, 1, 100000., ], #['TABLEST'], ['TABLES1', table_id, 1, None, None, None, None, None, None, 1.0, 10.0, 2.0, 10.0, 'ENDT'], ] card_count = { 'GRID' : 14, 'CPENTA6': 1, 'CTETRA4': 1, 'PSOLID': 1, 'CHEXA8' : 1, 'MAT1': 1, 'MATS1': 1, 'TABLES1': 1, } model = BDF(debug=False) model.allocate(card_count) for fields in cards: model.add_card(fields, fields[0], is_list=True) model.build() mat = model.materials[mid] print('----MAT----', type(mat)) print(mat) print('E = %s' % mat.get_E_by_material_index()) print('E = %s' % mat.get_E_by_material_id())
def test_cord1c_01(self): lines = ['cord1c,2,1,4,3'] grids = [ ['GRID', 4, 0, 0.0, 0., 0.], ['GRID', 3, 0, 0.0, 0., 1.], ['GRID', 1, 0, 0.0, 1., 0.], ] card_count = { 'CORD1C': 1, 'GRID': 3, } model = BDF(debug=False) model.allocate(card_count) model.add_card(lines, 'CORD1C', is_list=False) for grid in grids: model.add_card(grid, grid[0], is_list=True) model.build() size = 8 bdf_file = StringIO() card = model.coords.slice_by_coord_id(2) self.assertEquals(card.get_cid_by_coord_id(), 2) self.assertEquals(card.get_rid_by_coord_id(), 0) card.write_card(bdf_file, size=8, is_double=False)
def test_solid_03(self): mid = 2 pid = 4 rho = 0.1 cards = [ #$ Solid Nodes ['GRID', 11, 0, 0., 0., 0., 0], ['GRID', 12, 0, 1., 0., 0., 0], ['GRID', 13, 0, 1., 1., 0., 0], ['GRID', 14, 0, 0., 1., 0., 0], ['GRID', 15, 0, 0., 0., 2., 0], ['GRID', 16, 0, 1., 0., 2., 0], ['GRID', 17, 0, 1., 1., 2., 0], ['GRID', 18, 0, 0., 1., 2., 0], # Solids ['CHEXA', 7, pid, 11, 12, 13, 14, 15, 16, 17, 18], ['CTETRA', 8, pid, 11, 12, 13, 15], # Solid Nodes ['GRID', 21, 0, 0., 0., 0., 0,], ['GRID', 22, 0, 1., 0., 0., 0,], ['GRID', 23, 0, 1., 1., 0., 0,], ['GRID', 24, 0, 0., 0., 2., 0,], ['GRID', 25, 0, 1., 0., 2., 0,], ['GRID', 26, 0, 1., 1., 2., 0,], ['CPENTA', 9, pid, 21, 22, 23, 24, 25, 26], # hyperelastic ['PLSOLID', pid, mid, 'GRID'], ['MATHP', mid, None, None, None, rho], ] card_count = { 'GRID' : 14, 'CTETRA4': 1, 'CPENTA6': 1, 'CHEXA8' : 1, 'PLSOLID': 1, 'MATHP': 1, } model = BDF(debug=True) model.allocate(card_count) for fields in cards: model.add_card(fields, fields[0], is_list=True) model.build() # CTETRA eid = 8 nsm = 0. V = 1. / 3. self.check_solid(model, eid, 'CTETRA4', pid, 'PLSOLID', mid, 'MATHP', nsm, rho, V) eid = 9 V = 1.0 self.check_solid(model, eid, 'CPENTA6', pid, 'PLSOLID', mid, 'MATHP', nsm, rho, V) eid = 7 V = 2.0 self.check_solid(model, eid, 'CHEXA8', pid, 'PLSOLID', mid, 'MATHP', nsm, rho, V)
def test_solid_04(self): """checks linear static solid material""" mid = 2 pid = 4 rho = 0.1 cards = [ #$ Solid Nodes ['GRID', 11, 0, 0., 0., 0., 0], ['GRID', 12, 0, 1., 0., 0., 0], ['GRID', 13, 0, 1., 1., 0., 0], ['GRID', 14, 0, 0., 1., 0., 0], ['GRID', 15, 0, 0., 0., 2., 0], ['GRID', 16, 0, 1., 0., 2., 0], ['GRID', 17, 0, 1., 1., 2., 0], ['GRID', 18, 0, 0., 1., 2., 0], # Solids ['CHEXA', 7, pid, 11, 12, 13, 14, 15, 16, 17, 18], ['CTETRA', 8, pid, 11, 12, 13, 15], # Solid Nodes ['GRID', 21, 0, 0., 0., 0., 0,], ['GRID', 22, 0, 1., 0., 0., 0,], ['GRID', 23, 0, 1., 1., 0., 0,], ['GRID', 24, 0, 0., 0., 2., 0,], ['GRID', 25, 0, 1., 0., 2., 0,], ['GRID', 26, 0, 1., 1., 2., 0,], ['CPENTA', 9, pid, 21, 22, 23, 24, 25, 26], # static ['PSOLID', pid, mid, 0], ['MAT1', mid, 1.0, 2.0, 3.0, rho], ['MATS1', mid, None, 'PLASTIC', 0.0, 1, 1, 100000., ], ] card_count = { 'GRID' : 14, 'CTETRA4': 1, 'CPENTA6': 1, 'CHEXA8' : 1, 'PSOLID': 1, 'MAT1': 1, 'MATS1': 1, } model = BDF(debug=True) model.allocate(card_count) for fields in cards: model.add_card(fields, fields[0], is_list=True) model.build()
def test_crod_01(self): model = BDF(debug=debug) model.allocate({'CROD': 1}) lines = ['CROD 10 100 10 2'] model.add_card(lines, 'CROD', is_list=False) size = 8 f = StringIO() #card = CROD(card) card = model.crod.slice_by_element_id([10]) card.write_card(f, size) #card.raw_fields() self.assertEqual(card.get_element_id_by_element_index(), 10) self.assertEqual(card.get_property_id_by_element_index(), 100)
def test_cord1r_02(self): model = BDF(debug=False) card_count = { 'CORD1R': 1, 'GRID': 3, } #model.allocate(card_count) cards = [ ['CORD1R', 1, 1, 2, 3], # fails on self.k ['GRID', 1, 0, 0., 0., 0.], ['GRID', 2, 0, 1., 0., 0.], ['GRID', 3, 0, 1., 1., 0.], ] for card in cards: model.add_card(card, card[0], comment='comment\n', is_list=True) model.build() c1 = model.coords.slice_by_coord_id(1)
def test_conrod_01(self): model = BDF(debug=debug) model.allocate({'CONROD': 1}) eid = 10 nid1 = 2 nid2 = 3 mid = 5 A = 27.0 lines = ['conrod,%i, %i, %i, %i, %f' % (eid, nid1, nid2, mid, A)] model.add_card(lines, 'CONROD', is_list=False) size = 8 card = model.conrod.slice_by_element_id([eid]) f = StringIO() card.write_card(f, size) #card.raw_fields() self.assertEqual(card.get_element_id_by_element_index(), eid) self.assertEqual(card.get_material_id_by_element_index(), mid)
def test_grid_01(self): model = BDF(debug=False) card_lines = [ #['CORD1R', 1, 1, 2, 3], # fails on self.k ['GRID', 1, 0, 0., 0., 0.], ['GRID', 2, 0, 1., 0., 0.], ['GRID', 4, 0, 1., 2., 3.], ] #card_count = { #'GRID': 3, #} cards, card_count = model.add_cards_lines(card_lines) model.allocate(card_count, cards) for card in cards: model.add_card(card, card[0], comment='comment', is_list=True) model.build() #+------+-----+----+----+----+----+----+----+------+ #| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | #+======+=====+====+====+====+====+====+====+======+ #| GRID | NID | CP | X1 | X2 | X3 | CD | PS | SEID | #+------+-----+----+----+----+----+----+----+------+ node = model.grid.slice_by_node_id(4)
def test_cord2c_01(self): lines_a = [ 'CORD2C* 3 0 0. 0.', '* 0. 0. 0. 1.*', '* 1. 0. 1.' ] lines_b = [ 'CORD2R 4 3 10. 0. 5. 10. 90. 5.', ' 10. 0. 6.' ] card_count = { 'CORD2C': 1, 'CORD2R': 1, } model = BDF(debug=False) cards = { 'CORD2C': ['', lines_a], 'CORD2R': ['', lines_b], } model.add_cards(cards, card_count) #model.allocate(cards, card_count) card = model.add_card(lines_a, 'CORD2C', is_list=False) card = model.add_card(lines_b, 'CORD2R', is_list=False) model.build() cord2r = model.coords.slice_by_coord_id(3) #print(type(cord2r)) self.assertEquals(cord2r.get_cid_by_coord_id(), 3) self.assertEquals(cord2r.get_rid_by_coord_id(), 0) cord2r = model.coords.slice_by_coord_id(4) #print(type(cord2r)) self.assertEquals(cord2r.get_cid_by_coord_id(), 4) self.assertEquals(cord2r.get_rid_by_coord_id(), 3) i = model.coords.get_coord_index_by_coord_id(4) T = model.coords.T[i, :, :].reshape(3, 3) Ti = T[0, :] Tj = T[1, :] Tk = T[2, :] msg = 'i=%s expected=(0., 0., 1.)' % Ti self.assertTrue(allclose(Ti, array([0., 0., 1.])), msg) delta = Tj - array([1., 1., 0.]) / 2**0.5 self.assertTrue(allclose(Tj, array([1., 1., 0.]) / 2**0.5), str(delta)) delta = Tk - array([-1., 1., 0.]) / 2**0.5 self.assertTrue(allclose(Tk, array([-1., 1., 0.]) / 2**0.5), str(delta))
def test_solid_02(self): """checks linear static solid material""" mid = 2 pid = 4 rho = 0.1 cards = [ #$ Solid Nodes ['GRID', 11, 0, 0., 0., 0., 0], ['GRID', 12, 0, 1., 0., 0., 0], ['GRID', 13, 0, 1., 1., 0., 0], ['GRID', 14, 0, 0., 1., 0., 0], ['GRID', 15, 0, 0., 0., 2., 0], ['GRID', 16, 0, 1., 0., 2., 0], ['GRID', 17, 0, 1., 1., 2., 0], ['GRID', 18, 0, 0., 1., 2., 0], # Solids ['CHEXA', 7, pid, 11, 12, 13, 14, 15, 16, 17, 18], ['CTETRA', 8, pid, 11, 12, 13, 15], # Solid Nodes [ 'GRID', 21, 0, 0., 0., 0., 0, ], [ 'GRID', 22, 0, 1., 0., 0., 0, ], [ 'GRID', 23, 0, 1., 1., 0., 0, ], [ 'GRID', 24, 0, 0., 0., 2., 0, ], [ 'GRID', 25, 0, 1., 0., 2., 0, ], [ 'GRID', 26, 0, 1., 1., 2., 0, ], ['CPENTA', 9, pid, 21, 22, 23, 24, 25, 26], # static ['PSOLID', pid, mid, 0], ['MAT1', mid, 1.0, 2.0, 3.0, rho] ] card_count = { 'GRID': 14, 'CTETRA4': 1, 'CPENTA6': 1, 'CHEXA8': 1, 'PSOLID': 1, 'MAT1': 1, } model = BDF(debug=True) model.allocate(card_count) for fields in cards: model.add_card(fields, fields[0], is_list=True) model.build() # CTETRA eid = 8 mid = 2 pid = 4 nsm = 0. V = 1. / 3. rho = 0.1 self.check_solid(model, eid, 'CTETRA4', pid, 'PSOLID', mid, 'MAT1', nsm, rho, V) eid = 9 V = 1.0 self.check_solid(model, eid, 'CPENTA6', pid, 'PSOLID', mid, 'MAT1', nsm, rho, V) eid = 7 V = 2.0 self.check_solid(model, eid, 'CHEXA8', pid, 'PSOLID', mid, 'MAT1', nsm, rho, V)
def test_pcomp_02(self): """ symmetrical, nsm=0.0 and nsm=1.0 """ model = BDF(debug=False) pid = 1 z0 = 0. nsm = 0. sb = 0. ft = 'HOFF' tref = 0. ge = 0. lam = 'SYM' # is_symmetrical SYM Mid = [1, 2, 3] Theta = [0., 10., 20.] T = [.1, .2, .3] Sout = ['YES', 'YES', 'NO'] # 0-NO, 1-YES pcomp = [ 'PCOMP', pid, z0, nsm, sb, ft, tref, ge, lam, Mid[0], T[0], Theta[0], Sout[0], Mid[1], T[1], Theta[1], Sout[1], Mid[2], T[2], Theta[2], Sout[2] ] #---- mid = 1 E = 3.0e7 G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None mcsid = None mat1_a = ['MAT1', mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid] mat1_b = [ 'MAT1', mid + 1, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid ] mat1_c = [ 'MAT1', mid + 2, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid ] card_count = { 'PCOMP': 1, 'MAT1': 3, } model.allocate(card_count) model.add_card(pcomp, pcomp[0], is_list=True) model.add_card(mat1_a, 'MAT1', is_list=True) model.add_card(mat1_b, 'MAT1', is_list=True) model.add_card(mat1_c, 'MAT1', is_list=True) model.build() p = model.properties.properties_shell.pcomp[0] self.assertTrue(p.is_symmetrical_by_property_id()) self.assertTrue(p.is_symmetrical_by_property_index()) self.assertEqual(p.get_nplies_by_property_id(), 6) self.assertAlmostEqual(p.get_thickness_by_property_id()[0], 1.2) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 0), 0.1) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 1), 0.2) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 2), 0.3) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 3), 0.1) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 4), 0.2) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 5), 0.3) with self.assertRaises(IndexError): p.get_thickness_by_property_id_ply(pid, 6) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 0), 0.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 1), 10.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 2), 20.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 3), 0.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 4), 10.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 5), 20.) with self.assertRaises(IndexError): p.get_theta_by_property_id_ply(pid, 6) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 0), 1) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 1), 2) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 2), 3) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 3), 1) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 4), 2) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 5), 3) with self.assertRaises(IndexError): p.get_material_id_by_property_id_ply(pid, 6) self.assertTrue( allclose(p.get_material_ids_by_property_id(pid), [1, 2, 3, 1, 2, 3])) self.assertEqual(p.get_sout_by_property_id_ply(pid, 0), 'YES') self.assertEqual(p.get_sout_by_property_id_ply(pid, 1), 'YES') self.assertEqual(p.get_sout_by_property_id_ply(pid, 2), 'NO') self.assertEqual(p.get_sout_by_property_id_ply(pid, 3), 'YES') self.assertEqual(p.get_sout_by_property_id_ply(pid, 4), 'YES') self.assertEqual(p.get_sout_by_property_id_ply(pid, 5), 'NO') with self.assertRaises(IndexError): p.get_sout_by_property_id_ply(pid, 6) #--------------- #Rho self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 0), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 1), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 2), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 3), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 4), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 5), 1.0) with self.assertRaises(IndexError): p.get_density_by_property_id_ply(pid, 6) # MassPerArea #self.assertAlmostEqual(p.get_mass_per_area_by_property_id(), 1.2) self.assertAlmostEqual(p.get_mass_per_area_by_property_id(pid), 1.2) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 0), 0.1) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 1), 0.2) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 2), 0.3) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 3), 0.1) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 4), 0.2) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 5), 0.3) with self.assertRaises(IndexError): p.get_mass_per_area_by_property_id_ply(pid, 6) self.assertEqual(p.get_nonstructural_mass_by_property_id(pid), 0.0) #---------------------- # change the nsm to 1.0 p.set_nonstructural_mass_by_property_id(pid, 1.0) self.assertEqual(p.get_nonstructural_mass_by_property_id(pid), 1.0) # MassPerArea self.assertAlmostEqual(p.get_mass_per_area_by_property_id(pid), 2.2) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 0, method='nplies'), 0.1 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 1, method='nplies'), 0.2 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 2, method='nplies'), 0.3 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 3, method='nplies'), 0.1 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 4, method='nplies'), 0.2 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 5, method='nplies'), 0.3 + 1 / 6.) with self.assertRaises(IndexError): p.get_mass_per_area_by_property_id_ply(pid, 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 = 'HILL' tref = 0. ge = 0. #lam = 'NO' # is_symmetrical YES/NO lam = 'BEND' # is_symmetrical YES/NO Mid = [1, 2, 3] Theta = [0., 10., 20.] T = [.1, .2, .3] Sout = ['YES', 'YES', 'NO'] # 0-NO, 1-YES card_lines = [ 'PCOMP', pid, z0, nsm, sb, ft, tref, ge, lam, Mid[0], T[0], Theta[0], Sout[0], Mid[1], T[1], Theta[1], Sout[1], Mid[2], T[2], Theta[2], Sout[2], ] model = BDF(debug=False) card_count = { 'PCOMP': 1, 'MAT1': 3, } model.allocate(card_count) model.add_card(card_lines, 'PCOMP', comment='', is_list=True) # material... mid = 1 E = 1e7 G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None mcsid = None mat1_a = ['MAT1', mid, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid] mat1_b = [ 'MAT1', mid + 1, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid ] mat1_c = [ 'MAT1', mid + 2, E, G, nu, rho, a, tref, ge, St, Sc, Ss, mcsid ] model.add_card(mat1_a, 'MAT1', comment='', is_list=True) model.add_card(mat1_b, 'MAT1', comment='', is_list=True) model.add_card(mat1_c, 'MAT1', comment='', is_list=True) #card = BDFCard(mat1) #m = MAT1(model) #m.allocate(1) #m.add(card) #m.build() model.build() #card = BDFCard(data) #p = PCOMP(model) #p = model.properties.pcomp #p.add(card) #p.build() p = model.properties_shell.pcomp m = model.materials.mat1 #self.assertFalse(p.is_symmetrical()) self.assertEqual(p.get_nplies_by_property_id(), 3) self.assertAlmostEqual(p.get_thickness_by_property_id(pid), 0.6) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 0), 0.1) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 1), 0.2) self.assertAlmostEqual(p.get_thickness_by_property_id_ply(pid, 2), 0.3) with self.assertRaises(IndexError): p.get_thickness_by_property_id_ply(pid, 3) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 0), 0.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 1), 10.) self.assertAlmostEqual(p.get_theta_by_property_id_ply(pid, 2), 20.) with self.assertRaises(IndexError): p.get_theta_by_property_id_ply(pid, 3) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 0), 1) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 1), 2) self.assertEqual(p.get_material_id_by_property_id_ply(pid, 2), 3) with self.assertRaises(IndexError): p.get_material_id_by_property_id_ply(pid, 3) #print('get_material_id_by_property_id = ', p.get_material_id_by_property_id(pid)) self.assertEqual(p.get_material_ids_by_property_id(pid)[0], 1) self.assertEqual(p.get_material_ids_by_property_id(pid)[0], 1) self.assertEqual(p.get_material_ids_by_property_id(pid)[1], 2) self.assertEqual(p.get_material_ids_by_property_id(pid)[2], 3) self.assertEqual(p.get_sout_by_property_id_ply(pid, 0), 'YES') self.assertEqual(p.get_sout_by_property_id_ply(pid, 1), 'YES') self.assertEqual(p.get_sout_by_property_id_ply(pid, 2), 'NO') with self.assertRaises(IndexError): p.get_sout_by_property_id_ply(pid, 3) #for iply in range(len(p.plies)): #mid = p.plies[iply][0] #p.plies[iply][0] = m # MAT1 ##p.mids = [m, m, m] from StringIO import StringIO f = StringIO() #print(m.write_card(f, size=8, material_id=None)) p.write_card(f) m.write_card(f) print(f.getvalue()) #Mid self.assertAlmostEqual(p.get_material_id_by_property_id_ply(pid, 0), 1) self.assertAlmostEqual(p.get_material_id_by_property_id_ply(pid, 1), 2) self.assertAlmostEqual(p.get_material_id_by_property_id_ply(pid, 2), 3) with self.assertRaises(IndexError): p.get_density_by_property_id_ply(pid, 3) #Rho self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 0), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 1), 1.0) self.assertAlmostEqual(p.get_density_by_property_id_ply(pid, 2), 1.0) with self.assertRaises(IndexError): p.get_density_by_property_id_ply(pid, 3) # MassPerArea self.assertAlmostEqual(p.get_mass_per_area_by_property_id(), 0.6) self.assertAlmostEqual(p.get_mass_per_area_by_property_id(pid), 0.6) self.assertAlmostEqual(p.get_mass_per_area_by_property_id([pid]), 0.6) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 0), 0.1) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 1), 0.2) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_ply(pid, 2), 0.3) #with self.assertRaises(IndexError): #p.MassPerArea(3) #---------------------- # change the nsm to 1.0 p.set_nonstructural_mass_by_property_id(pid, 1.0) self.assertEqual(p.get_nonstructural_mass_by_property_id(), 1.0) # MassPerArea self.assertAlmostEqual(p.get_mass_per_area_by_property_id(), 1.6) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 0, method='nplies'), 0.1 + 1 / 3.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 1, method='nplies'), 0.2 + 1 / 3.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 2, method='nplies'), 0.3 + 1 / 3.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 0, method='t'), 0.1 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 1, method='t'), 0.2 + 2 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 2, method='t'), 0.3 + 3 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 0, method='rho*t'), 0.1 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 1, method='rho*t'), 0.2 + 2 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 2, method='rho*t'), 0.3 + 3 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 0, method='t'), 0.1 + 1 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 1, method='t'), 0.2 + 2 / 6.) self.assertAlmostEqual( p.get_mass_per_area_by_property_id_ply(pid, 2, method='t'), 0.3 + 3 / 6.) with self.assertRaises(IndexError): p.get_mass_per_area_by_property_id_ply(pid, 3, method='nplies') z0 = p.get_z0_by_property_id(pid) z = p.get_z_locations_by_property_id(pid) 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[0] = 1.0 z_expected = 1.0 + z_expected z = p.get_z_locations_by_property_id(pid) for za, ze in zip(z, z_expected): self.assertAlmostEqual(za, ze)
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""" card_count = { 'CONROD' : 1, 'CTUBE' : 1, 'PTUBE' : 1, 'CROD' : 1, 'PROD' : 1, 'GRID' : 2, 'MAT1' : 1, } model = BDF(debug=debug) model.allocate(card_count) lines = ['conrod,%i, %i, %i, %i, %f, %f, %f, %f' % (eid, nid1, nid2, mid, A, J, c, nsm)] model.add_card(lines, 'conrod', is_list=False) lines = ['crod,%i, %i, %i, %i' % (eid+1, pid, nid1, nid2)] model.add_card(lines, 'crod', is_list=False) lines = ['ctube,%i, %i, %i, %i' % (eid+2, pid+1, nid1, nid2)] model.add_card(lines, 'ctube', is_list=False) lines = ['prod,%i, %i, %f, %f, %f, %f' % (pid, mid, A, J, c, nsm)] model.add_card(lines, 'prod', is_list=False) OD1 = sqrt(4 * A / pi) t = 0. OD2 = OD1 lines = ['ptube,%i, %i, %f, %f, %f, %f' % (pid+1, mid, OD1, t, nsm, OD2)] model.add_card(lines, 'ptube', is_list=False) lines = ['mat1,%i, %.2e, %.2e, %f, %f' % (mid, E, G, nu, rho)] model.add_card(lines, 'mat1', is_list=False) lines = ['grid,%i, %i, %f, %f, %f' % (nid1, 0, xyz1[0], xyz1[1], xyz1[2])] model.add_card(lines, 'grid', is_list=False) lines = ['grid,%i, %i, %f, %f, %f' % (nid2, 0, xyz2[0], xyz2[1], xyz2[2])] model.add_card(lines, 'grid', is_list=False) model.build() mass = L * (rho * A + nsm) f = StringIO() model.write_bdf(out_filename=f, interspersed=True, size=8, precision='single', enddata=None) print(f.getvalue()) #positions = model.get_positions() grid_cid0 = None # conrod conrod = model.conrod.slice_by_element_id(eid) self.assertEqual(conrod.get_element_id_by_element_index(), eid) #self.assertEqual(conrod.get_property_id_by_element_id(), None) self.assertEqual(conrod.get_material_id_by_element_id(eid), mid) self.assertEqual(conrod.get_length_by_element_index(i=None, grid_cid0=grid_cid0), L) #self.assertEqual(conrod.Nsm(), nsm) rhoi = conrod.get_density_by_element_id(eid) Ai = conrod.get_area_by_element_id(eid) Li = conrod.get_length_by_element_id(eid, grid_cid0=grid_cid0) nsmi = conrod.get_non_structural_mass_by_element_id(eid) massa = conrod.get_mass_by_element_index() mass_msg_conrod = 'mass = L * (rho * A + nsm)\n' mass_msg_conrod += 'L=%s expected=%s\n' % (Li, L) mass_msg_conrod += 'rho=%s expected=%s\n' % (rhoi, rho) mass_msg_conrod += 'A=%s expected=%s\n' % (Ai, A) mass_msg_conrod += 'nsm=%s expected=%s\n' % (nsmi, nsm) mass_msg_conrod += 'mass=%s actual=%s expected=%s\n' % (Li * (rhoi*Ai + nsmi), massa, mass) #mass_msg_conrod += 'mass=%s expected=%s\n' % (Li * (rhoi*Ai + nsmi), mass) self.assertEqual(massa, mass, mass_msg_conrod) #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 crod_eid = eid + 1 crod = model.crod.slice_by_element_id([crod_eid]) self.assertEqual(crod.get_element_id_by_element_index(), crod_eid) self.assertEqual(crod.get_property_id_by_element_id(crod_eid), pid) self.assertEqual(crod.get_material_id_by_element_id(crod_eid), mid) rhoi = crod.get_density_by_element_id(crod_eid) Ai = crod.get_area_by_element_id(crod_eid) Li = crod.get_length_by_element_id(crod_eid, grid_cid0=grid_cid0) nsmi = crod.get_non_structural_mass_by_element_id(crod_eid) self.assertEqual(Li, L) #self.assertEqual(crod.Nsm(), nsm) massa = crod.get_mass_by_element_id(crod_eid) mass_msg_crod = 'mass = L * (rho * A + nsm)\n' mass_msg_crod += 'L=%s expected=%s\n' % (Li, L) mass_msg_crod += 'rho=%s expected=%s\n' % (rhoi, rho) mass_msg_crod += 'A=%s expected=%s\n' % (Ai, A) mass_msg_crod += 'nsm=%s expected=%s\n' % (nsmi, nsm) mass_msg_crod += 'mass=%s actual=%s expected=%s\n' % (Li * (rhoi*Ai + nsmi), massa, mass) self.assertEqual(massa, mass, mass_msg_crod) #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 prod = model.prod.slice_by_property_id([pid]) self.assertEqual(prod.property_id[0], pid) self.assertEqual(prod.get_material_id_by_property_id(pid), mid) self.assertEqual(prod.get_non_structural_mass_by_property_id(pid), nsm) self.assertEqual(prod.get_E_by_property_id(pid), E) self.assertEqual(prod.get_G_by_property_id(pid), G) self.assertEqual(prod.get_area_by_property_id(pid), A) self.assertEqual(prod.get_J_by_property_id(pid), J) self.assertEqual(prod.get_c_by_property_id(pid), c) self.assertEqual(prod.get_density_by_property_id(pid), rho) # ctube if 1: ctube_eid = eid + 2 ptube_pid = pid + 1 assert ctube_eid == 12, ctube_eid assert ptube_pid == 68, ptube_pid ctube = model.ctube.slice_by_element_id(ctube_eid) self.assertEqual(ctube.get_element_id_by_element_index(), ctube_eid) self.assertEqual(ctube.get_property_id_by_element_id(ctube_eid), ptube_pid) self.assertEqual(ctube.get_material_id_by_element_id(ctube_eid), mid) self.assertEqual(ctube.get_length_by_element_id(ctube_eid, grid_cid0), L) self.assertEqual(ctube.get_non_structural_mass_by_element_id(ctube_eid), nsm) self.assertAlmostEquals(ctube.get_mass_by_element_id(ctube_eid), mass, 5) self.assertEqual(ctube.get_E_by_element_id(ctube_eid), E) self.assertEqual(ctube.get_G_by_element_id(ctube_eid), G) self.assertAlmostEquals(ctube.get_area_by_element_id(ctube_eid), A, 5) ctube.get_J_by_element_id(ctube_eid) self.assertEqual(ctube.get_density_by_element_id(), rho) # ptube ptube = model.ptube.slice_by_property_id(pid+1) self.assertEqual(ptube.get_property_id_by_property_index(), pid+1) self.assertEqual(ptube.get_material_id_by_property_id(), mid) self.assertEqual(ptube.get_non_structural_mass_by_property_id(), nsm) self.assertEqual(ptube.get_E_by_property_id(), E) self.assertEqual(ptube.get_G_by_property_id(), G) self.assertAlmostEquals(ptube.get_area_by_property_id(), A, 5) ptube.get_J_by_property_id() self.assertEqual(ptube.get_density_by_property_id(), rho)