def test_cord2c_01(self): lines = [ 'CORD2C* 3 0 0. 0.', '* 0. 0. 0. 1.*', '* 1. 0. 1.' ] model = BDF(debug=False) card = model.process_card(lines) card = BDFCard(card) model.coords.add_cord2c(card) lines = [ 'CORD2R 4 3 10. 0. 5. 10. 90. 5.', ' 10. 0. 6.' ] card = model.process_card(lines) card = BDFCard(card) model.coords.add_cord2r(card) model.cross_reference() cord2r = model.Coord(3) self.assertEquals(cord2r.Cid(), 3) self.assertEquals(cord2r.Rid(), 0) cord2r = model.Coord(4) self.assertEquals(cord2r.Cid(), 4) self.assertEquals(cord2r.Rid(), 3) self.assertTrue(allclose(cord2r.i, array([0., 0., 1.]))) delta = cord2r.j - array([1., 1., 0.]) / 2**0.5 self.assertTrue(allclose(cord2r.j, array([1., 1., 0.]) / 2**0.5), str(delta)) delta = cord2r.k - array([-1., 1., 0.]) / 2**0.5 self.assertTrue(allclose(cord2r.k, array([-1., 1., 0.]) / 2**0.5), str(delta))
def test_grid_03(self): model = BDF() nid = 1 cp = 2 cd = 0 ps = '' seid = 0 card_count = { 'GRID': 2, } model = BDF() model.allocate(card_count) nodes = model.grid data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid]) data2 = BDFCard(['GRID', nid + 1, cp, 0., 0., 0., cd, ps, seid]) data3 = BDFCard(['GRID', nid + 2, cp, 0., 0., 0., cd, ps, seid]) nodes.add(data1) nodes.add(data2) nodes.resize(3, refcheck=False) #print('nodes.node_id = %s' % nodes.node_id) nodes.add(data3) f = StringIO() nodes.write_bdf(f, size=8, write_header=False)
def test_grid_04(self): model = BDF() nid = 1 cp = 2 cd = 0 ps = '' seid = 0 card_count = { 'GRID': 2, } model = BDF() model.allocate(card_count) nodes = model.grid data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid]) data2 = BDFCard(['GRID', nid + 1, cp, 0., 0., 0., cd, ps, seid]) data3 = BDFCard(['GRID', nid + 2, cp, 0., 0., 0., cd, ps, seid]) data4 = BDFCard(['GRID', nid + 3, cp, 0., 0., 0., cd, ps, seid]) nodes.add(data1) nodes.add(data2) nodes.resize(4, refcheck=False) #print('nodes.node_id = %s' % nodes.node_id) nodes.add(data3) self.assertEqual(len(nodes.node_id), 4) self.assertEqual(nodes.n, 4) self.assertEqual(nodes.i, 3) nodes.shrink(refcheck=False) #print('nodes.node_id = %s' % nodes.node_id) self.assertEqual(len(nodes.node_id), 3) self.assertEqual(nodes.n, 3) self.assertEqual(nodes.i, 3) nodes.resize(4, refcheck=False) nodes.add(data4) self.assertEqual(len(nodes.node_id), 4) self.assertEqual(nodes.n, 4) self.assertEqual(nodes.i, 4) f = StringIO() nodes.write_bdf(f, size=8, write_header=False) #print(f.getvalue()) nodes.resize(2, refcheck=False) self.assertEqual(len(nodes.node_id), 2) self.assertEqual(nodes.n, 2) self.assertEqual(nodes.i, 2) f = StringIO() nodes.write_bdf(f, size=8, write_header=False)
def test_grid_01(self): nid = 1 cp = 2 cd = 0 ps = '' seid = 0 card_count = {'GRID': 1,} model = BDF(debug=False) model.allocate(card_count) data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid]) nodes = model.grid nodes.add(data1) #print(n1) f = StringIO() nodes.write_card(f, size=8, write_header=False) nodes.write_card(f, size=16, write_header=False) nodes.write_card(f, size=16, is_double=True, write_header=False) # small field f = StringIO() nodes.write_card(f, size=8, write_header=False) msg = f.getvalue() card = 'GRID 1 2 0. 0. 0.\n' self.assertCardEqual(msg, card) # large field f = StringIO() nodes.write_card(f, size=16, write_header=False) card = ('GRID* 1 2 0. 0.\n' '* 0.\n') msg = f.getvalue() self.assertCardEqual(msg, card)
def test_cord1r_01(self): lines = ['cord1r,2,1,4,3'] card = bdf.process_card(lines) card = BDFCard(card) size = 8 card = CORD1R(card) self.assertEquals(card.Cid(), 2) self.assertEquals(card.Rid(), 0) card.write_bdf(size, 'dummy') card.raw_fields()
def test_cord1s_01(self): lines = ['cord1s,2,1,4,3'] card = bdf.process_card(lines) card = BDFCard(card) size = 8 f = StringIO() card = CORD1S(card) self.assertEquals(card.Cid(), 2) self.assertEquals(card.Rid(), 0) card.write_bdf(f, size) card.raw_fields()
def test_grid_02(self): model = BDF(debug=False) nid = 1 cp = 2 cd = 0 ps = '' seid = 0 card_count = {'GRID': 2,} model = BDF(debug=False) model.allocate(card_count) nodes = model.grid data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid]) data2 = BDFCard(['GRID', nid+1, cp, 0., 0., 0., cd, ps, seid]) nodes.add(data1) nodes.add(data2) f = StringIO() nodes.write_card(f, size=8, write_header=False)
def test_cpenta_01(self): model = BDF() lines = ['CPENTA,85,22,201,202,203,205,206,207'] card = model.process_card(lines) card = BDFCard(card) size = 8 f = StringIO() penta = CPENTA6(model) penta.allocate(1) penta.add(card) penta.write_bdf(f, size) #card.rawFields() print(f.getvalue())
def test_ctetra_01(self): model = BDF() lines = ['CTETRA,85,22,201,202,203,205'] card = model.process_card(lines) card = BDFCard(card) size = 8 f = StringIO() hexa = CTETRA4(model) hexa.allocate(1) hexa.add(card) hexa.write_bdf(f, size) #card.rawFields() print(f.getvalue())
def test_chexa_01(self): model = BDF() lines = ['CHEXA,85,22,201,202,203,205,206,207,+PN2', '+PN2,209,210'] card = model.process_card(lines) card = BDFCard(card) size = 8 f = StringIO() hexa = CHEXA8(model) hexa.allocate(1) hexa.add(card) hexa.write_bdf(f, size) #card.rawFields() print(f.getvalue())
def test_ctetra_02(self): model = BDF(debug=False) lines = [ 'CTETRA,85,22,201,202,203,205,206,207,+PN2', '+PN2,209,210,217' ] card = model.process_card(lines) card = BDFCard(card) size = 8 f = StringIO() hexa = CTETRA10(model) hexa.allocate(1) hexa.add(card) hexa.write_card(f, size) #card.rawFields() print(f.getvalue())
def test_cpenta_02(self): model = BDF(debug=False) lines = [ 'CPENTA,85,22,201,202,203,205,206,207,+PN2', '+PN2,209,210,217, , , ,213,214,218' ] card = model.process_card(lines) card = BDFCard(card) size = 8 f = StringIO() penta = CPENTA15(model) penta.allocate(1) penta.add(card) penta.write_card(f, size) #card.rawFields() print(f.getvalue())
def add_card(self, card_lines, card_name, comment='', is_list=True): card_name = card_name.upper() self._increase_card_count(card_name) if card_name in ['DEQATN']: card_obj = card_lines card = card_lines else: if is_list: fields = card_lines else: fields = to_fields(card_lines, card_name) # apply OPENMDAO syntax if self._is_dynamic_syntax: fields = [ self._parse_dynamic_syntax(field) if '%' in field[0:1] else field for field in fields ] card = wipe_empty_fields([ interpret_value(field, fields) if field is not None else None for field in fields ]) else: # leave everything as strings card = wipe_empty_fields(fields) card_obj = BDFCard(card) if card_name == 'HYPER': hyper = HYPER(card_obj, comment) self.hyper[hyper.pid] = hyper return elif card_name == 'FLOW': flow = FLOW(card_obj, comment) self.flow[flow.flow_id] = flow return BDF.add_card(self, card, card_name, comment=comment, is_list=True)
def test_spoint_01(self): model = BDF() card_count = { 'SPOINT': 2, } model = BDF() model.allocate(card_count) spoints = model.spoint data1 = BDFCard(['SPOINT', 1, 2]) data2 = BDFCard(['SPOINT', 4, 5]) data3 = BDFCard(['SPOINT', 10, 20]) data4 = BDFCard(['SPOINT', 30, 'THRU', 40]) spoints.add(data1) spoints.add(data2) f = StringIO() spoints.write_bdf(f, size=8) #print('spoints %s' % f.getvalue()) self.assertEqual(len(spoints), 4) self.assertEqual(spoints.n, 4) spoints.add(data3) f = StringIO() spoints.write_bdf(f, size=8) #print('spoints %s' % f.getvalue()) self.assertEqual(len(spoints), 6) self.assertEqual(spoints.n, 6) spoints.add(data4) f = StringIO() spoints.write_bdf(f, size=16) #print('spoints %s' % f.getvalue()) self.assertEqual(len(spoints), 17) self.assertEqual(spoints.n, 17) spoints.add(data4) f = StringIO() spoints.write_bdf(f, size=16) #print('spoints %s' % f.getvalue()) self.assertEqual(spoints.max(), 40) self.assertEqual(spoints.min(), 1) self.assertEqual(spoints.n, 17) if 1 in spoints: pass else: raise RuntimeError('invalid catch') if 29 in spoints: raise RuntimeError('invalid catch') data5 = BDFCard(['SPOINT', 50, 'THRU', 55, 59, '61', 'THRU', '64']) spoints.add(data5) f = StringIO() spoints.write_bdf(f, size=16) #print('spoints %s' % f.getvalue()) self.assertEqual(spoints.max(), 64) self.assertEqual(spoints.min(), 1) self.assertEqual(spoints.n, 28) spoints.remove([1, 2, 64]) #self.assertRaises(KeyError, spoints.remove([1, 2])) f = StringIO() spoints.write_bdf(f, size=16) #print('spoints %s' % f.getvalue()) self.assertEqual(spoints.n, 25)
def test_pcomp_02(self): """ symmetrical, nsm=0.0 and nsm=1.0 """ model = BDF() pid = 1 z0 = 0. nsm = 0. sb = 0. ft = 'HOFF' TRef = 0. ge = 0. lam = 'SYM' # isSymmetrical SYM Mid = [1, 2, 3] Theta = [0., 10., 20.] T = [.1, .2, .3] Sout = ['YES', 'YES', 'NO'] # 0-NO, 1-YES card = [ '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] ] card = BDFCard(card) p = PCOMP(model) p.add(card) p.build() 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(), 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.Thickness(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.assertEqual(p.get_material_ids_by_property_id(), [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) 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] m = MAT1(data=mat1) for iply in range(len(p.plies)): mid = p.plies[iply][0] p.plies[iply][0] = m # MAT1 #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 = 'HILL' TRef = 0. ge = 0. #lam = 'NO' # isSymmetrical YES/NO lam = 'BEND' # isSymmetrical YES/NO Mid = [1, 2, 3] Theta = [0., 10., 20.] T = [.1, .2, .3] Sout = ['YES', 'YES', 'NO'] # 0-NO, 1-YES data = [ '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() card = BDFCard(data) p = PCOMP(model) #p = model.properties.pcomp p.add(card) p.build() #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_ids_by_property_id = ', p.get_material_ids_by_property_id(pid)) self.assertEqual(p.get_material_ids_by_property_id(pid)[0][0], 1) self.assertEqual(p.get_material_ids_by_property_id(pid)[0][0], 1) self.assertEqual(p.get_material_ids_by_property_id(pid)[0][1], 2) self.assertEqual(p.get_material_ids_by_property_id(pid)[0][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) # material... mid = 1 E = 1e7 G = None nu = None rho = 1.0 a = None St = None Sc = None Ss = None Mcsid = None mat1 = ['MAT1', mid, E, G, nu, rho, a, TRef, ge, St, Sc, Ss, Mcsid] card = BDFCard(mat1) m = MAT1(model) m.allocate(1) m.add(card) m.build() #for iply in range(len(p.plies)): #mid = p.plies[iply][0] #p.plies[iply][0] = m # MAT1 ##p.mids = [m, m, m] #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_iply(pid, 0), 0.1) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_iply(pid, 1), 0.2) self.assertAlmostEqual(p.get_mass_per_area_by_property_id_iply(pid, 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)