def write_case_control_cards(self): # Case Control cc = CaseControlDeck([]) for key, subcase in self.subcases.items(): cc.create_new_subcase(key) self.write_case_control_from_list(cc, key, subcase) self.model.case_control_deck = cc
def test_convert_bwb(self): """converts a bwb model""" bdf_filename = os.path.join(pkg_path, '..', 'models', 'bwb', 'bwb_saero.bdf') bdf_filename_out = os.path.join(pkg_path, '..', 'models', 'bwb', 'bwb_modes.bdf') bdf_filename_out2 = os.path.join(pkg_path, '..', 'models', 'bwb', 'bwb_modes_converted.bdf') model = read_bdf(bdf_filename, log=log, validate=False) model.sol = 103 lines = [ 'ECHO = NONE', 'SUBCASE 1', ' DISPLACEMENT(PLOT) = ALL', ' MPC = 1', ' SPC = 100', ' SUPORT1 = 1', ' METHOD = 42', ] card_lines = ['EIGRL', 42, None, None, 20] model.add_card(card_lines, 'EIGRL') model.case_control_deck = CaseControlDeck(lines, log=log) model.write_bdf(bdf_filename_out) units_from = ['in', 'lbm', 's'] #units_from = ['mm', 'Mg', 's'] units_to = ['m', 'kg', 's'] convert(model, units_to, units=units_from) model.write_bdf(bdf_filename_out2) os.remove(bdf_filename_out) os.remove(bdf_filename_out2)
def test_convert_sine(self): """converts a sine model""" model_path = os.path.join(pkg_path, '..', 'models', 'freq_sine') bdf_filename = os.path.join(model_path, 'good_sine.dat') bdf_filename_out = os.path.join(model_path, 'sine_modes.bdf') bdf_filename_out2 = os.path.join(model_path, 'sine_converted.bdf') model = read_bdf(bdf_filename, log=log, validate=False) model.sol = 103 lines = [ 'ECHO = NONE', 'SUBCASE 1', ' DISPLACEMENT(PLOT) = ALL', #'$ SPC = 100', ' METHOD = 42', ] card_lines = ['EIGRL', 42, None, None, 20] model.add_card(card_lines, 'EIGRL') model.case_control_deck = CaseControlDeck(lines, log=log) model.params['GRDPNT'] = PARAM('GRDPNT', 0) #del model.params['WTMASS'] model.write_bdf(bdf_filename_out) #units_from = ['in', 'lbm', 's'] units_from = ['mm', 'Mg', 's'] units_to = ['m', 'kg', 's'] convert(model, units_to, units=units_from) model.write_bdf(bdf_filename_out2) os.remove(bdf_filename_out) os.remove(bdf_filename_out2)
def write_cards(self): self.model.case_control_deck = CaseControlDeck([]) self._write_executive_control_cards() self._write_case_control_cards() self._write_params() # Validate self.model.validate()
def write_case_control_cards(self): # Case Control cc = CaseControlDeck([]) for key, subcase in self.subcases.items(): fmethod, method = self.write_cards_from_subcase(key) cc.create_new_subcase(key) self.write_case_control_from_list(cc, key, subcase) cc.add_parameter_to_local_subcase(1, 'FMETHOD = %d' % fmethod) # the flutter card id cc.add_parameter_to_local_subcase(1, 'METHOD = %d' % method) # the eigenval analysis card id self.model.case_control_deck = cc
def _create_nastran_loads(model: Abaqus, nastran_model: BDF): def xyz(): return np.zeros(3, dtype='float32') if nastran_model.case_control_deck is None: nastran_model.case_control_deck = CaseControlDeck( [], log=nastran_model.log) for istep, step in enumerate(model.steps): subcase_id = istep + 1 load_id = subcase_id if subcase_id in nastran_model.subcases: subcase = nastran_model.subcases[subcase_id] else: subcase = nastran_model.case_control_deck.create_new_subcase( subcase_id) for cload in step.cloads: subcase.add('LOAD', load_id, [], 'STRESS-type') #subcase['LOAD'] = load_id forces = defaultdict(xyz) moments = defaultdict(xyz) for cloadi in cload: nid, dof, mag = cloadi assert dof in [1, 2, 3], cload if dof in {1, 2, 3}: forces[nid][dof - 1] = mag elif dof in {4, 5, 6}: moments[nid][dof - 4] = mag else: raise NotImplementedError(cloadi) mag = 1.0 if len(forces): for nid, xyz in forces.items(): nastran_model.add_force(load_id, nid, mag, xyz, cid=0, comment='') if len(moments): for nid, xyz in moments.items(): nastran_model.add_moment(load_id, nid, mag, xyz, cid=0, comment='')
def test_thermal_1(self): """tests various thermal cards""" log = SimpleLogger(level='warning') model = BDF(log=log, debug=False) model.sol = 101 lines = [ 'SUBCASE 1', ' DISP(PLOT) = ALL', ' ANALYSIS = HEAT', 'BEGIN BULK', ] model.case_control_deck = CaseControlDeck(lines, log=None) model.add_grid(11, [0., 0., 0.]) model.add_grid(12, [1., 0., 0.]) model.add_grid(13, [1., 1., 0.]) model.add_grid(14, [0., 1., 0.]) model.add_grid(15, [0., 2., 0.]) eid = 1 pid = 1 mid = 1 nodes = [11, 12, 13, 14] model.add_cquad4(eid, pid, nodes, theta_mcid=0.0, zoffset=0., tflag=0, T1=1.0, T2=1.0, T3=1.0, T4=1.0, comment='') model.add_pshell(pid, mid1=1, t=0.1) eid = 10 nids = [11, 12, 13, 15] pid = 2 model.add_ctetra(eid, pid, nids) model.add_psolid(pid, mid) E = 3.0e7 G = None nu = 0.3 model.add_mat1(mid, E, G, nu) eid = 2 Type = 'AREA3' chbdyg = CHBDYG(eid, Type, nodes, iview_front=0, ivew_back=0, rad_mid_front=0, rad_mid_back=0, comment='chbdyg') with self.assertRaises(ValueError): chbdyg.validate() Type = 'AREA4' chbdyg = model.add_chbdyg(eid, Type, nodes, iview_front=0, ivew_back=0, rad_mid_front=0, rad_mid_back=0, comment='chbdyg') chbdyg.raw_fields() eid = 3 eid2 = 4 side = 1 chbdye = model.add_chbdye(eid, eid2, side, iview_front=0, ivew_back=0, rad_mid_front=0, rad_mid_back=0, comment='chbdye') chbdye.raw_fields() eid = 4 g1 = 11 g2 = 12 pid = 10 chbdyp = model.add_chbdyp(eid, pid, Type, g1, g2, g0=0, gmid=None, ce=0, iview_front=0, ivew_back=0, rad_mid_front=0, rad_mid_back=0, e1=None, e2=None, e3=None, comment='chbdyp') chbdyp.raw_fields() phbdy = model.add_phbdy(pid, af=None, d1=None, d2=None, comment='phbdy') phbdy.raw_fields() #--------------------------- ta = 2 ta1 = 2 pconid = 11 conv = model.add_conv(eid, pconid, ta, film_node=0, cntrlnd=0, comment='conv') conv.raw_fields() pconv = model.add_pconv(pconid, mid, form=0, expf=0.0, ftype=0, tid=None, chlen=None, gidin=None, ce=0, e1=None, e2=None, e3=None, comment='pconv') pconv.raw_fields() pconid = 12 convm = model.add_convm(eid, pconid, ta1, film_node=0, cntmdot=0, ta2=None, mdot=1.0, comment='convm') convm.raw_fields() coef = 0.023 pconvm = model.add_pconvm(pconid, mid, coef, form=0, flag=0, expr=0.0, exppi=0.0, exppo=0.0, comment='pconvm') pconvm.raw_fields() radmid = 42 absorb = 0.2 emissivity = 0.8 radm = model.add_radm(radmid, absorb, emissivity, comment='radm') radm.raw_fields() famb = 100. nodamb = 33 eids = [1] cntrlnd = 1000 radbc = model.add_radbc(nodamb, famb, cntrlnd, eids, comment='radbc') radbc.raw_fields() sid = 43 qvol = 17. control_point = 1001 elements = [1, 2] qvol = model.add_qvol(sid, qvol, control_point, elements, comment='qvol') qvol.raw_fields() q0 = 18. t_source = 19. eids = [2] qvect = model.add_qvect(sid, q0, eids, t_source, ce=0, vector_tableds=None, control_id=0, comment='qvect') qvect.raw_fields() q0 = 15.8 flag = 'POINT' grids = [-1] qhbdy = model.add_qhbdy(sid, flag, q0, grids, af=None, comment='qhbdy') qhbdy.raw_fields() qflux = 20. eids = [1] qbdy1 = model.add_qbdy1(sid, qflux, eids, comment='qbdy1') qbdy1.raw_fields() eid = 1 qfluxs = 12. qbdy2 = model.add_qbdy2(sid, eid, qfluxs, comment='qbdhy2') qbdy2.raw_fields() q0 = 14. cntrlnd = 57 eids = [1, 2] qbdy3 = model.add_qbdy3(sid, q0, cntrlnd, eids, comment='qbdy3') qbdy3.raw_fields() temperature = 13.3 model.add_tempd(sid, temperature, comment='tempd') temperatures = { 15: 37., 16: 38., } model.add_temp(sid, temperatures) #------------------------- 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) write_bdf_symmetric(model, bdf_filename4, encoding=None, size=8, is_double=False, enddata=None, close=False, plane='xz') #model.cross_reference() #print(bdf_filename.getvalue()) bdf_filename2.seek(0) model2 = read_bdf(bdf_filename2, xref=False, log=log, debug=False) model2.safe_cross_reference() save_load_deck(model, punch=False, run_convert=False, run_renumber=False, run_test_bdf=False, run_op2_reader=False)
def test_thermal_2(self): """tests TABLEHT, TABLEH1""" model = BDF(debug=False, log=None, mode='msc') model.sol = 159 model.case_control_deck = CaseControlDeck([], log=model.log) subcase = model.case_control_deck.create_new_subcase( 100) # type: Subcase subcase.add('DISP', 'ALL', ['PLOT'], 'STRESS-type') subcase.add('TSTEP', 10, [], 'STRESS-type') sid = 10 N = 40 DT = 0.1 NO = 40 model.add_tstep(sid, N, DT, NO) tid = 101 x = [1., 2., 3.] y = [10., 20., 30.] model.add_tableh1(tid, x, y, comment='tableh1') tid = 101 model.add_tableh1(tid, x, y, comment='tableh1') tid = 110 tableh1 = model.add_tableh1(tid, x, y, comment='tableh1') tableh1.raw_fields() tid_tableht = 85 x = [10., 25., 40.] y = [101, 102, 110] #This table is referenced only by PCONV entries that define #free convection boundary condition properties. tableht = model.add_tableht(tid_tableht, x, y, comment='tableht') tableht.raw_fields() pconv_id = 100 mid = None pconv = model.add_pconv(pconv_id, mid, form=0, expf=0.0, ftype=0, tid=tid_tableht, chlen=None, gidin=None, ce=0, e1=None, e2=None, e3=None, comment='pconv') pconv.raw_fields() # Every surface to which free convection is to be applied must # reference a PCONV entry. PCONV is referenced on the CONV Bulk Data entry. eid = 1 ta = 1 conv = model.add_conv(eid, pconv_id, ta, film_node=0, cntrlnd=0, comment='conv') conv.raw_fields() conv = model.add_conv(2, pconv_id, ta, film_node=0, cntrlnd=0, comment='conv') conv = model.add_conv(3, pconv_id, ta, film_node=0, cntrlnd=0, comment='conv') # CHBDYG, CHBDYE, or CHBDYP surface element identification number. eid_fem = 1 eid_conv = 1 side = 3 # TODO: 1-6 chbdye = model.add_chbdye(eid_fem, eid_conv, side, iview_front=0, iview_back=0, rad_mid_front=0, rad_mid_back=0, comment='chbdye') eid_fem = 2 nodes = [1, 2, 3] surface_type = 'AREA3' chbdyg = model.add_chbdyg(eid_fem, surface_type, nodes, iview_front=0, iview_back=0, rad_mid_front=0, rad_mid_back=0, comment='chbdyg') eid_fem = 3 pid_phybdy = 10 g1 = 1 g2 = None surface_type = 'POINT' chbdyp = model.add_chbdyp(eid_fem, pid_phybdy, surface_type, g1, g2, g0=0, gmid=None, ce=0, iview_front=0, iview_back=0, rad_mid_front=0, rad_mid_back=0, e1=None, e2=None, e3=None, comment='chbdyp') phbdy = model.add_phbdy(pid_phybdy, af=None, d1=None, d2=None, comment='phbdy') model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [0., 1., 0.]) chbdye.raw_fields() chbdyg.raw_fields() chbdyp.raw_fields() model.validate() save_load_deck(model)
def test_loads(self): """tests the ``get_load_arrays`` and ``_reduce_dload_case`` methods""" model = BDF(debug=True, log=None, mode='msc') subcase_id = 10 eid_map = None node_ids = [] normals = None lines = [] cc = CaseControlDeck(lines, log=None) #print(model.case_control_deck) model.case_control_deck = cc subcase = cc.create_new_subcase(subcase_id) out = get_load_arrays(model, subcase_id, eid_map, node_ids, normals, nid_map=None) is_loads, is_temperatures, temperature_data, load_data = out assert is_loads is False, is_loads assert is_temperatures is False, is_temperatures assert temperature_data == (None, None), temperature_data assert load_data == (None, None, None), load_data key = 'LOAD' value = 10 options = [] param_type = '???' with self.assertRaises(TypeError): subcase.add(key, value, options, param_type) param_type = 'STRESS-type' subcase.add(key, value, options, param_type) with self.assertRaises(KeyError): get_load_arrays(model, subcase_id, eid_map, node_ids, normals, nid_map=None, stop_on_failure=True) #is_loads, is_temperatures, temperature_data, load_data = out #assert is_loads is False, is_loads #assert is_temperatures is False, is_temperatures #assert temperature_data == (None, None), temperature_data #assert load_data == (None, None, None), load_data dload_case = [] dloads, scale_factors = model._reduce_dload_case( dload_case, scale=1., unallowed_dload_ids=None, skip_scale_factor0=False, msg='') assert dloads == [], dloads assert scale_factors == [], scale_factors del dloads, scale_factors # ---------------------------------------------------------------------- dload_id = 5 scale = 1. scale_factors = [2] load_ids = [3] dload = model.add_dload(dload_id, scale, scale_factors, load_ids) dload_case = [dload] with self.assertRaises(KeyError): model._reduce_dload_case(dload_case, scale=1., unallowed_dload_ids=None, skip_scale_factor0=False, msg='') excite_id = 100 tid = 2 model.add_tload1(dload_id, excite_id, tid, delay=0, Type='LOAD', us0=0.0, vs0=0.0, comment='') with self.assertRaises(KeyError): model._reduce_dload_case(dload_case, scale=1., unallowed_dload_ids=None, skip_scale_factor0=False, msg='')