def test_solid_04(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' ], ] model = BDF(debug=False) for fields in cards: model.add_card(fields, fields[0], is_list=True) model.cross_reference() mat = model.Material(mid) mat.E() model.get_mass_breakdown(property_ids=None, stop_if_no_mass=True, detailed=False) model.get_mass_breakdown(property_ids=None, stop_if_no_mass=True, detailed=True) model.get_volume_breakdown(property_ids=None, stop_if_no_volume=True) save_load_deck(model)
def test_msgmesh_1(self): """tests CGEN""" log = SimpleLogger(level='warning') model = BDF(log=log, debug=False) model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [1., 1., 0.]) model.add_grid(4, [0., 1., 0.]) #feedge = model.add_feedge() Type = 10 field_eid = 'cat' pid = 20 field_id = 30 th_geom_opt = 301. eidl = 40 eidh = 50 cgen = model.add_cgen(Type, field_eid, pid, field_id, th_geom_opt, eidl, eidh) cgen.raw_fields() #---------------------------------------- bdf_filename = StringIO() bdf_filename2 = StringIO() bdf_filename3 = StringIO() #bdf_filename4 = StringIO() model.validate() model._verify_bdf(xref=False) model.write_bdf(bdf_filename, encoding=None, size=8, is_double=False, interspersed=False, enddata=None, close=False) model.cross_reference() model.pop_xref_errors() model._verify_bdf(xref=True) model.write_bdf(bdf_filename2, encoding=None, size=16, is_double=False, interspersed=False, enddata=None, close=False) model.write_bdf(bdf_filename3, encoding=None, size=16, is_double=True, interspersed=False, enddata=None, close=False) ##model.cross_reference() ##print(bdf_filename.getvalue()) #bdf_filename2.seek(0) #model2 = read_bdf(bdf_filename2, xref=False) #print('---------------') #model2.safe_cross_reference() save_load_deck(model, run_convert=False, run_quality=False)
def test_solid_03(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], ['CIHEX1', 17, pid + 1, 11, 12, 13, 14, 15, 16, 17, 18], ['CIHEX2', 18, pid + 1, 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], ['PIHEX', pid + 1, mid, 0], ['MAT1', mid, 1.0, 2.0, 3.0, rho], [ 'MATS1', mid, None, 'PLASTIC', 0.0, 1, 1, 100000., ], ] model = BDF(debug=False) for fields in cards: model.add_card(fields, fields[0], is_list=True) model.cross_reference() save_load_deck(model)
def test_pbarl_nsm(self): model = BDF(debug=False) pid = 1 mid = 1 bar_type = 'BAR' dim = [1., 2.] # area = 2.0 pbarl = model.add_pbarl(pid, mid, bar_type, dim, group='MSCBML0', nsm=1., comment='') E = 1.0 G = None nu = 0.3 mat1 = model.add_mat1(mid, E, G, nu) #---------------- card_lines = [ 'PBARL 2 1 BAR', ' 1.0 2.0 1.0', ] model.add_card(card_lines, 'PBARL', comment='', is_list=False, has_none=True) pbarl2 = model.properties[2] #------------------ model.cross_reference() assert pbarl.Nsm() == 1.0 assert pbarl.Area() == 2.0 # mass/L = area*rho + nsm assert pbarl.MassPerLength() == 1.0 # area = 2.0 mat1.rho = 10.0 assert pbarl.MassPerLength() == 21.0, pbarl.MassPerLength() assert pbarl2.MassPerLength() == 21.0, pbarl2.MassPerLength() loadcase_id = 10 eid = 11 load_type = 'FZ' x1 = 0. x2 = None p1 = 10. scale = 'FR' model.add_pload1(loadcase_id, eid, load_type, scale, x1, p1, x2=x2, p2=None, comment='pload1') scale = 'LE' model.add_pload1(loadcase_id, eid, load_type, scale, x1, p1, x2=x2, p2=None, comment='') model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [0., 1., 0.]) x = None g0 = 3 model.add_cbar(eid, pid, [1, 2], x, g0) model.cross_reference() p0 = 1 eids = None nids = None force1, moment1 = model.sum_forces_moments(p0, loadcase_id, include_grav=False, xyz_cid0=None) force2, moment2 = model.sum_forces_moments_elements(p0, loadcase_id, eids, nids, include_grav=False, xyz_cid0=None) #print(force1, force2) assert np.allclose(force1, force2), force1 assert np.allclose(moment1, moment2), moment1 save_load_deck(model, xref='standard', punch=True)
def test_damper_03(self): """tests the CDAMP4, PDAMP, CDAMP4, SPOINT""" log = get_logger(level='warning') model = BDF(log=log) eid = 3 pid = 2 s1 = 3 s2 = 4 cdamp3 = model.add_cdamp3(eid, pid, [s1, s2], comment='cdamp3') bdamp = 1.0e3 pdamp = model.add_pdamp(pid, bdamp, comment='pdamp') spoints = model.add_spoint([3, 4, 5], comment='spoints') eid = 4 bdamp = 2.0e3 s1 = 3 s2 = 4 cdamp4 = model.add_cdamp4(eid, bdamp, [s1, s2], comment='cdamp4') eid = 5 pid = 5 mid = 10 bdamp = 3.0e3 pdamp5 = model.add_pdamp5(pid, mid, bdamp, comment='pdamp5') cdamp5 = model.add_cdamp5(eid, pid, [s1, s2], comment='cdamp5') eid = 6 pid = 6 ce = 1. cr = 1. model.add_grid(10, [0., 0., 0.]) model.add_grid(11, [0., 0., 0.]) nids = [10, 11] pvisc = model.add_pvisc(pid, ce, cr, comment='pvisc') cvisc = model.add_cvisc(eid, pid, nids, comment='cvisc') eid = 7 pid = 7 x = [1., 2., 3.] g0 = None cgap = model.add_cgap(eid, pid, nids, x, g0, cid=None, comment='cgap') pgap = model.add_pgap(pid, u0=0., f0=0., ka=1.e8, kb=None, mu1=0., kt=None, mu2=None, tmax=0., mar=100., trmin=0.001, comment='pgap') eid = 8 pid = 8 k = [1.0] b = [2.0] ge = [0.01] cbush = model.add_cbush(eid, pid, nids, x, g0, cid=None, s=0.5, ocid=-1, si=None, comment='cbush') pbush = model.add_pbush(pid, k, b, ge, rcv=None, mass=None, comment='pbush') eid = 9 pid = 9 k = 1. c = 2. m = 3. sa = 4. se = 5. #optional_vars = None cbush1d = model.add_cbush1d(eid, pid, nids, cid=None, comment='cbush1d') pbush1d = model.add_pbush1d(pid, k=k, c=c, m=m, sa=sa, se=se, optional_vars=None, comment='pbush1d') E = 3.0e7 G = None nu = 0.3 model.add_mat1(mid, E, G, nu) model.validate() cdamp3.raw_fields() cdamp4.raw_fields() cdamp5.raw_fields() pdamp5.raw_fields() cvisc.raw_fields() pvisc.raw_fields() cgap.raw_fields() pgap.raw_fields() cbush.raw_fields() pbush.raw_fields() cbush1d.raw_fields() pbush1d.raw_fields() spoints.raw_fields() cdamp3.write_card(size=8, is_double=False) cdamp4.write_card(size=8, is_double=False) cdamp5.write_card(size=8, is_double=False) pdamp5.write_card(size=8, is_double=False) cvisc.write_card(size=8, is_double=False) pvisc.write_card(size=8, is_double=False) cgap.write_card(size=8, is_double=False) pgap.write_card(size=8, is_double=False) cbush.write_card(size=8, is_double=False) pbush.write_card(size=8, is_double=False) cbush1d.write_card(size=8, is_double=False) pbush1d.write_card(size=8, is_double=False) params = [ ('K1', 1.0), ('K2', 1.0), ('K3', 1.0), ('K4', 1.0), ('K5', 1.0), ('K6', 1.0), ('B1', 1.0), ('B2', 1.0), ('B3', 1.0), ('B4', 1.0), ('B5', 1.0), ('B6', 1.0), #('M1', 1.0), #('M2', 1.0), #('M3', 1.0), #('M4', 1.0), #('M5', 1.0), #('M6', 1.0), ] i = make_dvprel_optimization(model, params, 'PBUSH', pbush.pid, i=1) params = [(5, 1.0)] i = make_dvprel_optimization(model, params, 'PGAP', pgap.pid, i) params = [('K', 1.0), ('C', 1.0), ('M', 1.0)] i = make_dvprel_optimization(model, params, 'PBUSH1D', pbush1d.pid, i) params = [('CE1', 1.0)] i = make_dvprel_optimization(model, params, 'PVISC', pvisc.pid, i) params = [('B1', 1.0), (3, 1.0)] i = make_dvprel_optimization(model, params, 'PDAMP', pdamp.pid, i) #----------------------------------------- params = [] i = make_dvcrel_optimization(model, params, 'CVISC', cvisc.eid, i) params = [ ('X1', 1.0), ('X2', 2.0), ('X3', 3.0), ('S1', 1.0), ('S2', 2.0), ('S3', 3.0), ('S', 1.0), ] i = make_dvcrel_optimization(model, params, 'CBUSH', cbush.eid, i) params = [] i = make_dvcrel_optimization(model, params, 'CBUSH1D', cbush.eid, i) params = [] i = make_dvcrel_optimization(model, params, 'CGAP', cgap.eid, i) spoints.write_card() model.cross_reference() model.update_model_by_desvars() save_load_deck(model, run_op2_writer=False)
def test_cbeam_03(self): """tests an BIT field on the CBEAM""" model = BDF(debug=False) model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) eid = 1 pid = 1 bit = 42 nids = [1, 2] x = [0., 0., 1.] g0 = None bit = None cbeam = model.add_cbeam(eid, pid, nids, x, g0, offt=None, bit=bit, pa=0, pb=0, wa=None, wb=None, sa=0, sb=0, comment='') with self.assertRaises(RuntimeError): cbeam.validate() del model.elements[eid] bit = 12 cbeam = model.add_cbeam(eid, pid, nids, x, g0, offt=None, bit=bit, pa=0, pb=0, wa=None, wb=None, sa=0, sb=0, comment='') with self.assertRaises(AssertionError): cbeam.raw_fields() del model.elements[eid] bit = 42. cbeam = model.add_cbeam(eid, pid, nids, x, g0, offt=None, bit=bit, pa=0, pb=0, wa=None, wb=None, sa=0, sb=0, comment='') assert cbeam.is_offt is False, cbeam.is_offt assert cbeam.is_bit is True, cbeam.is_bit mid = 1 beam_type = 'BAR' dim = [1., 2.] # area = 2.0 nsm = 1. xxb = [0., 1.] dims = [dim, dim] model.add_pbeaml(pid, mid, beam_type, xxb, dims, so=None, nsm=[1.0], group='MSCBML0', comment='') pid += 1 so = ['YES', 'YESA', 'NO', 'YES'] xxb = [0., 0.5, 0.75, 1.] area = [1., 2., 3., 4.] i1 = [2., 3., 4., 5.] i2 = [3., 4., .5, .6] i12 = [0.1, 0.2, 0.3, 0.4] j = [5., 6., 6.5, 7.0] nsm = None pbeam = model.add_pbeam(pid, mid, xxb, so, area, i1, i2, i12, j, nsm, c1=None, c2=None, d1=None, d2=None, e1=None, e2=None, f1=None, f2=None, k1=1., k2=1., s1=0., s2=0., nsia=0., nsib=None, cwa=0., cwb=None, m1a=0., m2a=None, m1b=0., m2b=None, n1a=0., n2a=None, n1b=0., n2b=None, comment='') str(pbeam) E = 3.0e7 G = None nu = 0.3 model.add_mat1(mid, E, G, nu, rho=1.) save_load_deck(model)
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 = 'MSCBML0' 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='') with self.assertRaises(ValueError): cbar.validate() cbar.x = [0., 1., 2.] cbar.validate() model.elements[eid] = cbar pbarl._verify(xref=False) model.validate() model.cross_reference() pbarl._verify(xref=True) assert np.allclose(cbar.Mass(), 9.9247779608), cbar.Mass() mat.rho = 0. assert np.allclose(cbar.Mass(), 0.5), cbar.Mass() scale = 'FR' x = [0.2, 0.4, 0.6, 0.8] model.add_cbarao(eid, scale, x, comment='cbarao') model.add_card(['CBARAO', eid+1, 'RF', 6, 0.1, 0.2], 'CBARAO') save_load_deck(model, run_quality=False, run_test_bdf=False)
def test_loads_combo(self): r""" tests CONROD, CTRIA3-PSHELL, CQUAD4-PCOMP, CTETRA/CPENTA/CPYRAM/CHEXA-PSOLID FORCE, FORCE1, PLOAD4 (CHEXA) PLOAD2 (CTRIA3, CQUAD4) ^ y | 4 3 12 +-----+--+ | | + 13 | | | +-----+--+--+---S -> x 1 2 9 10 11 """ model = BDF(debug=False) model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [1., 1., 0.]) model.add_grid(4, [0., 1., 0.]) model.add_grid(5, [0., 0., 1.]) model.add_grid(6, [1., 0., 1.]) model.add_grid(7, [1., 1., 1.]) model.add_grid(8, [0., 1., 1.]) model.add_grid(9, [5., 0., 0.]) model.add_grid(10, [6., 0., 0.]) model.add_grid(12, [2., 1., 0.]) model.add_grid(13, [2., 0.5, 0.]) eid = 1 mid = 1 A = 2.0 nids = [1, 2] # L = 1; A=2 # mass=(rho*A + nsm) * L = (0.2*2 + 1.0) * 1 = 1.4 conrod = model.add_conrod(eid, mid, nids, A, j=0.0, c=0.0, nsm=1.0, comment='') model.add_conrod(eid, mid, nids, A, j=0.0, c=0.0, nsm=1.0, comment='') eid = 2 pid = 2 nids = [3, 12] ctube = model.add_ctube(eid, pid, nids, comment='ctube') ctube = model.add_ctube(eid, pid, nids, comment='ctube') OD1 = 0.1 ptube = model.add_ptube(pid, mid, OD1, t=None, nsm=0., OD2=None, comment='ptube') model.add_ptube(pid, mid, OD1, t=None, nsm=0., OD2=None, comment='ptube') E = 3.0e7 G = None nu = 0.3 model.add_mat1(mid, E, G, nu, rho=0.2, a=0.0, tref=0.0, ge=0.0, St=0.0, Sc=0.0, Ss=0.0, mcsid=0, comment='') eid = 3 pid = 3 nids = [1, 2, 3] ctria3 = model.add_ctria3(eid, pid, nids, zoffset=0., theta_mcid=0.0, tflag=0, T1=1.0, T2=1.0, T3=1.0, comment='') # mass = (rho*t + nsm)*A = (0.2*0.5 + 0.3) * 0.5 = 0.4 * 0.5 = 0.2 model.add_pshell(pid, mid1=None, t=0.5, mid2=mid, twelveIt3=1.0, mid3=None, tst=0.833333, nsm=0.3, z1=None, z2=None, mid4=None, comment='') eid = 4 pid = 4 nids = [1, 2, 3, 4] cquad4 = model.add_cquad4(eid, pid, nids, theta_mcid=0.0, zoffset=0., tflag=0, T1=1.0, T2=1.0, T3=1.0, T4=1.0, comment='') mids = [mid, mid, mid] thicknesses = [0.1, 0.2, 0.3] model.add_pcomp(pid, mids, thicknesses, thetas=None, souts=None, nsm=0., sb=0., ft=None, tref=0., ge=0., lam=None, z0=None, comment='pcomp') model.add_pcomp(pid, mids, thicknesses, thetas=None, souts=None, nsm=0., sb=0., ft=None, tref=0., ge=0., lam=None, z0=None, comment='pcomp') sid = 2 pressure = 2.0 model.add_pload2(sid, pressure, [3, 4], comment='') # ctria3, cquad4 pid = 5 global_ply_ids = [5, 6, 7] mids = [mid, mid, mid] thicknesses = [0.1, 0.2, 0.3] pcompg = model.add_pcompg(pid, global_ply_ids, mids, thicknesses, thetas=None, souts=None, nsm=0.0, sb=0.0, ft=None, tref=0.0, ge=0.0, lam=None, z0=None, comment='pcompg') model.add_pcompg(pid, global_ply_ids, mids, thicknesses, thetas=None, souts=None, nsm=0.0, sb=0.0, ft=None, tref=0.0, ge=0.0, lam=None, z0=None, comment='pcompg') pid = 40 eid = 5 nids = [1, 2, 3, 5] ctetra = model.add_ctetra(eid, pid, nids, comment='ctetra') eid = 6 nids = [1, 2, 3, 4, 5] cpyram = model.add_cpyram(eid, pid, nids, comment='cpyram') eid = 7 nids = [1, 2, 3, 5, 6, 7] cpenta = model.add_cpenta(eid, pid, nids, comment='cpenta') eid = 8 nids = [1, 2, 3, 4, 5, 6, 7, 8] chexa = model.add_chexa(eid, pid, nids, comment='chexa') # mass = rho*V = 0.2*1 psolid = model.add_psolid(pid, mid, cordm=0, integ=None, stress=None, isop=None, fctn='SMECH', comment='psolid') sid = 13 eids = [eid] g1 = 6 g34 = 8 pressures = [1., 1., 1., 1.] pload4 = model.add_pload4(sid, eids, pressures, g1=1, g34=8, cid=0, nvector=None, surf_or_line='SURF', line_load_dir='NORM', comment='pload4') conid = 42 gids = [ 2, 2, 2, 2, 2, 2, 9, 9, 9, 9, 9, 9, ] components = [ 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, ] enforced = [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., ] mpc = model.add_mpc(conid, gids, components, enforced, comment='mpc') eid = 1 ga = 9 gb = 10 cna = '123456' cnb = '' cma = '' cmb = '' rbar = model.add_rbar(eid, [ga, gb], cna, cnb, cma, cmb, alpha=0., comment='rbar') eid = 2 ga = 10 gb = 13 rrod_a = RROD(eid, [ga, gb], cma='42', cmb='33') with self.assertRaises(RuntimeError): rrod_a.validate() rrod_b = model.add_rrod(eid, [ga, gb], cma='3', cmb=None, alpha=0.0, comment='') conid = 43 gids = [10, 11] components = [1, 0] enforced = [1., 1.] mpc = model.add_mpc(conid, gids, components, enforced) model.add_spoint(11, comment='spoint') conid = 44 sets = [42, 43] mpcadd = model.add_mpcadd(conid, sets, comment='mpcadd') #model.add_spoint([11, 'THRU', 42], comment='spoint3') str(model.spoints) sid = 14 nids = 11 # SPOINT mags = 20. sload = model.add_sload(sid, nids, mags, comment='an sload') sid = 14 nids = [11, 12] # SPOINT, GRID mags = [20., 30.] sload = model.add_sload(sid, nids, mags, comment='an sload') sid = 12 xyz = [2., 3., 4.] node = 7 mag = 1.0 force = model.add_force(sid, node, mag, xyz, cid=0, comment='force') moment = model.add_moment(sid, node, mag, xyz, comment='moment') node = 6 mag = 1.0 g1 = 2 g2 = 3 force1 = model.add_force1(sid, node, mag, g1, g2, comment='force1') moment1 = model.add_moment1(sid, node, mag, g1, g2, comment='moment1') g1 = 1 g2 = 3 g3 = 2 g4 = 4 force2 = model.add_force2(sid, node, mag, g1, g2, g3, g4, comment='force2') moment2 = model.add_moment2(sid, node, mag, g1, g2, g3, g4, comment='moment2') #g2, g3 = g3, g2 #force2 = model.add_force2(sid, node, mag, g1, g2, g3, g4, comment='force2') load_id = 120 scale = 1. scale_factors = [1.0, 2.0] load_ids = [12, 13] # force, pload4 load = model.add_load(load_id, scale, scale_factors, load_ids, comment='load') #----------------------------------------------------------------------- # constraints conid = 42 gids = [1, 2] components = ['123', '123'] enforced = [0., 0.] spc = model.add_spc(conid, gids, components, enforced, comment='spc') conid = 43 nodes = [1, 2] components2 = '123456' spc1 = model.add_spc1(conid, components2, nodes, comment='spc1') conid = 44 sets = [42, 43] spcadd = model.add_spcadd(conid, sets, comment='spcadd') #----------------------------------------------------------------------- model.add_eigrl(sid, v1=None, v2=None, nd=None, msglvl=0, maxset=None, shfscl=None, norm=None, options=None, values=None, comment='eigrl') sid = 13 model.add_eigr(sid, method='LAN', f1=None, f2=None, ne=None, nd=20, norm='MASS', G=None, C=None, comment='') #----------------------------------------------------------------------- model.validate() model._verify_bdf(xref=False) model.write_bdf('loads.temp') model.cross_reference() assert allclose(conrod.Mass(), 1.4) assert allclose(ctria3.Mass(), 0.2) assert allclose(chexa.Mass(), 0.2) model.write_bdf('loads.temp') model._verify_bdf(xref=True) model.write_bdf('loads.temp') model.uncross_reference() model.write_bdf('loads.temp') model.cross_reference() model.uncross_reference() model.safe_cross_reference() model.write_bdf('loads.temp', size=8, is_double=False) model.write_bdf('loads.temp', size=16, is_double=False) model.write_bdf('loads.temp', size=16, is_double=True) model2 = read_bdf('loads.temp', debug=None) os.remove('loads.temp') eids = list(model.elements.keys()) nids = list(model.nodes.keys()) p0 = [0., 0., 0.] loadcase_id = 120 forces1, moments1 = model2.sum_forces_moments_elements(p0, loadcase_id, eids, nids, include_grav=False, xyz_cid0=None) forces2, moments2 = model2.sum_forces_moments(p0, loadcase_id, include_grav=False, xyz_cid0=None) assert allclose(forces1, forces2), 'forces1=%s forces2=%s' % (forces1, forces2) assert allclose(moments1, moments2), 'moments1=%s moments2=%s' % (moments1, moments2) model2.get_area_breakdown() model2.get_volume_breakdown() model2.get_mass_breakdown() eids = list(model.elements.keys()) p0 = [0., 0., 0.] forces1, moments1 = model.sum_forces_moments(p0, loadcase_id, include_grav=True, xyz_cid0=None) forces2, moments2 = model.sum_forces_moments_elements(p0, loadcase_id, eids, nids, include_grav=True, xyz_cid0=None) assert np.array_equal(forces1, forces2) assert np.array_equal(moments1, moments2) model2.write_skin_solid_faces('skin.bdf', write_solids=False, write_shells=True) os.remove('skin.bdf') save_load_deck(model2)
def test_deqatn_11(self): """ based off nast/tpl/ptdmi1.dat What's going on with this... """ model = BDF(debug=None) deqatn_card = [ 'deqatn 2 f(x,y,z)= 1.;', ' L=x+y', ] model.add_card(deqatn_card, 'DEQATN', is_list=False) #dessub_desglb = 5 dconstr_cards = [ [ 'dconstr,5,10,', ], [ 'dconstr,6,11,', ], ] dresp_cards = [ [ # card1 'dresp2,10,respA,2', ',desvar,100,101,102', ], [ # card2 'dresp2,11,respB,2', ',desvar,100,101,102', ], ## TODO: support this... #[ #'dresp2,11,respB,F(A,B)=A+B**2*SIN(A*B)' #',desvar,100,101', #], ] #model.add_desvar(100, 'varA', 100.1, xlb=-1e20, xub=1e20, #delx=None, ddval=None, comment='') desvar_cards = [ [ 'desvar,100,varA,100.1', ], [ 'desvar,101,varB,100.2', ], [ 'desvar,102,varC,100.3', ], ] for desvar in desvar_cards: model.add_card(desvar, 'DESVAR', is_list=False) for dconstr in dconstr_cards: model.add_card(dconstr, 'DCONSTR', is_list=False) for dresp in dresp_cards: model.add_card(dresp, 'DRESP2', is_list=False) model._verify_bdf() model.cross_reference() model._verify_bdf() save_load_deck(model)
def test_ploadx1(self): """tests a CTRIAX, PLPLANE, MATHP, and PLOADX1""" model = BDF(debug=False) sid = 10 eid1 = 11 pa = 200. ga = 1 gb = 2 ploadx1 = model.add_ploadx1(sid, eid1, pa, [ga, gb], pb=None, theta=0., comment='ploadx1') model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [1., 1., 0.]) pid = 20 nids = [1, 2, 3, None, None, None] ctriax = model.add_ctriax(eid1, pid, nids, theta_mcid=0., comment='ctriax') mid = 21 plplane = model.add_plplane(pid, mid, cid=0, stress_strain_output_location='GRID', comment='plplane') #eid2 = 12 #model.add_ctriax6(eid2, mid, nids, theta=0., comment='ctriax6') #E = 30.e7 #G = None #nu = 0.3 #mat1 = model.add_mat1(mid, E, G, nu, rho=0.1, comment='mat1') #mathe = model.add_mathe(mid, model, bulk, rho, texp, mus, alphas, #betas, mooney, sussbat, comment='mathe') mathp = model.add_mathp(mid, comment='mathp') model.validate() ctriax.raw_fields() ctriax.write_card(size=8) ctriax.write_card(size=16) plplane.raw_fields() plplane.write_card(size=8) plplane.write_card(size=16) #mathe.raw_fields() #mathe.write_card(size=8) #mathe.write_card(size=16) mathp.raw_fields() mathp.write_card(size=8) mathp.write_card(size=16) ploadx1.raw_fields() ploadx1.write_card(size=8) ploadx1.write_card(size=16) ploadx1.write_card(size=16, is_double=True) model.validate() model._verify_bdf(xref=False) model.cross_reference() model._verify_bdf(xref=True) ctriax.write_card(size=8) plplane.write_card(size=8) #mathe.write_card(size=8) mathp.write_card(size=8) ploadx1.write_card(size=8) model.write_bdf('ploadx1.temp') model2 = read_bdf('ploadx1.temp', debug=None) model2._verify_bdf() os.remove('ploadx1.temp') save_load_deck(model2)
def test_shear(self): """tests a CSHEAR, PSHEAR""" pid = 10 pid_pshell = 11 mid = 100 log = get_logger(level='warning') model = BDF(log=log) model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [1., 1., 0.]) model.add_grid(4, [0., 1., 0.]) nsm = 10.0 t = 1.0 rho = 1.0 cshear = model.add_cshear(10, pid, [1, 2, 3, 4], comment='cshear') cquad4 = model.add_cquad4(14, pid_pshell, [1, 2, 3, 4], comment='cquad4') model.add_pshear(pid, mid, t=t, nsm=nsm, f1=0., f2=0., comment='pshear') model.add_pshell(pid_pshell, mid1=mid, t=t, mid2=None, twelveIt3=1.0, mid3=None, tst=0.833333, nsm=nsm, z1=None, z2=None, mid4=None, comment='') E = 3.0e7 G = None nu = 0.3 model.add_mat1(mid, E, G, nu, rho=rho) model.validate() model.cross_reference() model.pop_xref_errors() area = 1.0 mass_expected = area * (rho * t + nsm) mass = model.mass_properties()[0] assert np.allclose(mass, mass_expected*2), 'mass_properties all: mass=%s mass_expected=%s' % (mass, mass_expected*2) mass = model.mass_properties(element_ids=10)[0] assert np.allclose(mass, mass_expected), 'mass_properties reduced: mass=%s mass_expected=%s' % (mass, mass_expected) mass = mass_properties_nsm(model)[0] assert np.allclose(mass, mass_expected*2), 'mass_properties_nsm all: mass=%s mass_expected=%s' % (mass, mass_expected*2) mass = mass_properties_nsm(model, element_ids=10)[0] assert np.allclose(mass, mass_expected), 'mass_properties_nsm reduced: mass=%s mass_expected=%s' % (mass, mass_expected) bdf_file = StringIO() model.write_bdf(bdf_file) model.uncross_reference() model.cross_reference() model.pop_xref_errors() model.get_area_breakdown(property_ids=None, stop_if_no_area=True) model.get_mass_breakdown(property_ids=None, stop_if_no_mass=True, detailed=False) model.get_mass_breakdown(property_ids=None, stop_if_no_mass=True, detailed=True) model.get_volume_breakdown(property_ids=None, stop_if_no_volume=True) assert np.allclose(cshear.Mass(), mass_expected), cshear.Mass() model.uncross_reference() model.safe_cross_reference() model.uncross_reference() #bdf_file = model.write_bdf(bdf_file) save_load_deck(model)
def test_cfast(self): """tests a CFAST/PFAST""" model = BDF(debug=False) eid1 = 10 pid = 11 model.add_grid(1, xyz=[0., 0., 0.]) model.add_grid(2, xyz=[1., 0., 0.]) model.add_grid(3, xyz=[1., 1., 0.]) model.add_grid(4, xyz=[0., 1., 0.]) model.add_cquad4(eid1, pid, [1, 2, 3, 4]) eid2 = 12 model.add_grid(11, xyz=[0., 0., 1.]) model.add_grid(12, xyz=[1., 0., 1.]) model.add_grid(13, xyz=[1., 1., 1.]) model.add_grid(14, xyz=[0., 1., 1.]) model.add_cquad4(eid2, pid, [11, 12, 13, 14]) mid = 13 model.add_pshell(pid, mid1=mid, t=0.1) E = 1e7 nu = 0.3 G = E / (2. * (1. + nu)) E = None mat1 = model.add_mat1(mid, E, G, nu, rho=0.2) eid = 14 pid = 15 Type = 'ELEM' ida = eid1 idb = eid2 cfast = model.add_cfast(eid, pid, Type, ida, idb, gs=1, ga=None, gb=None, xs=None, ys=None, zs=None, comment='cfast') Type = 'fake' pid2 = None cfast2 = CFAST(eid, pid2, Type, ida, idb, gs=None, ga=None, gb=None, xs=None, ys=None, zs=None, comment='') with self.assertRaises(TypeError): cfast2.validate() cfast2.Type = 'ELEM' with self.assertRaises(ValueError): cfast2.validate() cfast2.ga = 3 cfast2.xs = 4. cfast2.ys = 4. cfast2.zs = 4. cfast2.validate() d = 1.0 kt1 = 1.0 kt2 = 1.0 kt3 = 0.1 pfast = model.add_pfast(pid, d, kt1, kt2, kt3, mcid=-1, mflag=0, kr1=0., kr2=0., kr3=0., mass=0., ge=0., comment='') model.validate() cfast.raw_fields() pfast.raw_fields() cfast.write_card() pfast.write_card() model._verify_bdf(xref=False) model.cross_reference() model.pop_xref_errors() model._verify_bdf(xref=True) cfast.raw_fields() pfast.raw_fields() cfast.write_card() pfast.write_card() model.uncross_reference() model.safe_cross_reference() model.mass_properties() save_load_deck(model)
def test_multiple_materials(self): """tests multiple materials""" log = get_logger(level='warning') model = BDF(log=log) E = 3.0e7 G = None nu = 0.3 mat1 = model.add_mat1(1, E, G, nu) e11 = e22 = 3.0e7 nu12 = 0.3 model.add_mat8(8, e11, e22, nu12) model.add_mat4(4, 10.0) mat5 = model.add_mat5(5) mat9 = model.add_mat9(9, G11=0., G12=0., G13=0., G14=0., G15=0., G16=0., G22=0., G23=0., G24=0., G25=0., G26=0., G33=0., G34=0., G35=0., G36=0., G44=0., G45=0., G46=0., G55=0., G56=0., G66=0., rho=0., A=None, tref=0., ge=0., comment='mat9') bulk = 0.3 rho = 0.2 c = None model.add_mat10(10, bulk, rho, c) e1 = 1. e2 = 2. e3 = 3. nu13 = 0.3 nu23 = 0.3 g12 = 12. g13 = 13. g23 = 23. mat11 = model.add_mat11(11, e1, e2, e3, nu12, nu13, nu23, g12, g13, g23, rho=0.0, a1=0.0, a2=0.0, a3=0.0, tref=0.0, ge=0.0, comment='mat11') mat1.raw_fields() mat5.raw_fields() mat9.raw_fields() mat11.raw_fields() structural_material_ids = model.get_structural_material_ids() assert len(structural_material_ids) == 5, structural_material_ids thermal_material_ids = model.get_thermal_material_ids() assert len(thermal_material_ids) == 2, thermal_material_ids mats = model.Materials(1) assert len(mats) == 1, mats mats = model.Materials([1, 4, 5]) assert len(mats) == 3, mats with self.assertRaises(KeyError): model.Material(-1) with self.assertRaises(KeyError): model.StructuralMaterial(-1) with self.assertRaises(KeyError): model.ThermalMaterial(-1) save_load_deck(model)
def test_mat2_01(self): """tests MAT2, MATT2""" log = get_logger(level='warning') model = BDF(log=log) mid = 10 G11 = G22 = G12 = G13 = G22 = G23 = G33 = 1.0 #nuxth = nuthz = nuzx = 0.3 mat2 = model.add_mat2(mid, G11, G12, G13, G22, G23, G33, rho=0., a1=None, a2=None, a3=None, tref=0., ge=0., St=None, Sc=None, Ss=None, mcsid=None, comment='mat2') mat2.write_card(size=16, is_double=False) mat2.validate() g11_table = 1 g12_table = 2 g13_table = 3 g22_table = 4 g23_table = 1 g33_table = 1 rho_table = 1 a1_table = 1 a2_table = 1 a3_table = 1 ge_table = 1 st_table = 1 sc_table = 1 ss_table = 1 matt2 = model.add_matt2(mid, g11_table, g12_table, g13_table, g22_table, g23_table, g33_table, rho_table, a1_table, a2_table, a3_table, ge_table, st_table, sc_table, ss_table, comment='matt2') matt2.validate() x = np.linspace(1., 10.) y = np.sin(x) + 5. tablem1 = model.add_tablem1(1, x, y, comment='tablem1') tablem1.write_card() x1 = 1.0 tablem2 = model.add_tablem2(2, x1, x, y, comment='tablem2') tablem2.write_card() x2 = 2.0 tablem3 = model.add_tablem3(3, x1, x2, x, y, comment='tablem3') tablem3.write_card() #x1 = 1.0 #x2 = 2.0 x3 = 3.0 x4 = 4.0 a = [5.0] tablem4 = model.add_tablem4(4, x1, x2, x3, x4, a, comment='tablem4') tablem4.write_card() model.validate() model.cross_reference() model.pop_xref_errors() matt2.write_card(size=16, is_double=False) save_load_deck(model)