def test_write_path(self): include_name = r'C:\NASA\formats\pynastran_v0.6\pyNastran\bdf\writePath.py' msg1 = write_include(include_name, is_windows=True) sline1 = _split_path(include_name, is_windows=True) include_name = r'/opt/NASA/formats/pynastran_v0.6/pyNastran/bdf/writePath.py' msg2 = write_include(include_name, is_windows=False) sline2 = _split_path(include_name, is_windows=False) include_name = r'/opt/NASA/test1/test2/test3/test4/formats/pynastran_v0.6/pyNastran/bdf/writePath.py' msg3 = write_include(include_name, is_windows=False) sline3 = _split_path(include_name, is_windows=False) include_name = r'opt/NASA/test1/test2/test3/test4/formats/pynastran_v0.6/pyNastran/bdf/writePath.py' msg4 = write_include(include_name, is_windows=True) sline4 = _split_path(include_name, is_windows=True) msg1_expected = r"INCLUDE 'C:\\NASA\formats\pynastran_v0.6\pyNastran\bdf\writePath.py'" + '\n' msg2_expected = "INCLUDE '/opt/NASA/formats/pynastran_v0.6/pyNastran/bdf/writePath.py'\n" msg3_expected = ( "INCLUDE '/opt/NASA/test1/test2/test3/test4/formats/pynastran_v0.6/\n" " pyNastran/bdf/writePath.py'\n") msg4_expected = ( r"INCLUDE 'opt\NASA\test1\test2\test3\test4\formats\pynastran_v0.6" + '\\\n' + r" pyNastran\bdf\writePath.py'" + '\n') assert msg1 == msg1_expected, 'test1 actual:\n%r\nexpected:\n%r\n%s' % ( msg1, msg1_expected, str(sline1)) assert msg2 == msg2_expected, 'test2 actual:\n%r\nexpected:\n%r\n%s' % ( msg2, msg2_expected, str(sline2)) assert msg3 == msg3_expected, 'test3 actual:\n%r\nexpected:\n%r\n%s' % ( msg3, msg3_expected, str(sline3)) assert msg4 == msg4_expected, 'test4 actual:\n%s\nexpected:\n%s\n%s' % ( msg4, msg4_expected, str(sline4))
def test_write_path(self): if is_windows: include_name = r'C:\NASA\formats\pynastran_v0.6\pyNastran\bdf\writePath.py' msg1 = write_include(include_name, is_windows=True) sline1 = _split_path(include_name) include_name = r'/opt/NASA/formats/pynastran_v0.6/pyNastran/bdf/writePath.py' msg2 = write_include(include_name, is_windows=False) sline2 = _split_path(include_name) include_name = r'/opt/NASA/test1/test2/test3/test4/formats/pynastran_v0.6/pyNastran/bdf/writePath.py' msg3 = write_include(include_name, is_windows=False) sline3 = _split_path(include_name) include_name = r'opt/NASA/test1/test2/test3/test4/formats/pynastran_v0.6/pyNastran/bdf/writePath.py' msg4 = write_include(include_name, is_windows=True) sline4 = _split_path(include_name) msg1_expected = r'INCLUDE C:\\NASA\formats\pynastran_v0.6\pyNastran\bdf\writePath.py' '\n' msg2_expected = 'INCLUDE /opt/NASA/formats/pynastran_v0.6/pyNastran/bdf/writePath.py\n' msg3_expected = ('INCLUDE /opt/NASA/test1/test2/test3/test4/formats/pynastran_v0.6/\n' ' pyNastran/bdf/writePath.py\n') msg4_expected = (r'INCLUDE opt\NASA\test1\test2\test3\test4\formats\pynastran_v0.6' '\\\n' r' pyNastran\bdf\writePath.py' '\n') assert msg1 == msg1_expected, 'test1 actual:\n%r\nexpected:\n%r\n%s' % (msg1, msg1_expected, str(sline1)) assert msg2 == msg2_expected, 'test2 actual:\n%r\nexpected:\n%r\n%s' % (msg2, msg2_expected, str(sline2)) assert msg3 == msg3_expected, 'test3 actual:\n%r\nexpected:\n%r\n%s' % (msg3, msg3_expected, str(sline3)) assert msg4 == msg4_expected, 'test4 actual:\n%r\nexpected:\n%r\n%s' % (msg4, msg4_expected, str(sline4))
def _write_bdf_includes(self, out_filenames, bdf_files, relative_dirname=None, is_windows=True): """ Writes the INCLUDE files Parameters ---------- out_filenames : dict[fname] : fname2 fname_in - the nominal bdf that was read fname_out - the bdf that will be written relative_dirname : str; default=None -> os.curdir A relative path to reference INCLUDEs. '' : relative to the main bdf None : use the current directory path : absolute path is_windows : bool; default=None True/False : Windows has a special format for writing INCLUDE files, so the format for a BDF that will run on Linux and Windows is different. None : Check the platform """ if relative_dirname is None: relative_dirname = os.curdir elif relative_dirname == '': out_filename0 = list(out_filenames.keys())[0] relative_dirname = os.path.dirname(os.path.abspath(out_filename0)) self.log.debug('relative_dirname = %s' % relative_dirname) self.log.debug('include_filenames:') for ifile, include_filenames in self.include_filenames.items(): self.log.debug('ifile=%i %s' % (ifile, include_filenames)) assert len(include_filenames) > 0, include_filenames bdf_file = bdf_files[ifile] if bdf_file is None: continue #self.log.info('ifile=%s include_files=%s' % (ifile, include_filenames)) for include_filename in include_filenames: assert len(include_filename) > 0, include_filename #print('***', include_filename, '***') mapped_include_filename = include_filename if include_filename in out_filenames: mapped_include_filename = out_filenames[include_filename] if relative_dirname == '': # absolute path rel_include_filename = mapped_include_filename else: rel_include_filename = os.path.relpath( mapped_include_filename, relative_dirname) bdf_file.write( write_include(rel_include_filename, is_windows=is_windows))
def _write_bdf_includes(self, bdf_files, relative_dirname=None, is_windows=True): """writes the INCLUDE files""" if relative_dirname is None: relative_dirname = os.curdir for ifile, include_filenames in self.include_filenames.items(): assert len(include_filenames) > 0, include_filenames bdf_file = bdf_files[ifile] if bdf_file is None: continue for include_filename in include_filenames: assert len(include_filename) > 0, include_filename #print('***', include_filename, '***') if relative_dirname == '': # absolute path rel_include_filename = include_filename else: rel_include_filename = os.path.relpath(include_filename, relative_dirname) bdf_file.write(write_include(rel_include_filename, is_windows=is_windows))
def setup_contact(main_bdf, contact_bdf, contact_surfaces): main_bdf2 = 'main2.bdf' model_main = BDF() model_main.read_bdf(main_bdf) # ------------------------------------------------------------------------ # update the case control deck cc = model_main.case_control_deck subcase_ids = cc.get_subcase_list() subcase_ids.pop(0) subcase0_id = subcase_ids[0] cc.add_parameter_to_local_subcase(subcase0_id, 'FORCE(SORT1, REAL) = ALL') print(cc) model_main.write_bdf('junk.bdf') #sys.exit() # ------------------------------------------------------------------------ # update the main bdf with the INCLUDE fiel contact_include = write_include(contact_bdf) model_main.rejects.append([contact_include]) # ------------------------------------------------------------------------ eid_start = get_max_eid(model_main) + 1 # elements + 1 -> starting ID eid = eid_start # ------------------------------------------------------------------------ # apply springs based on distance with open(contact_bdf, 'w') as f: eid_groups = [] nodes_groups = [] neids = [] i = 0 for contact_surface in contact_surfaces: nids_group1 = contact_surface['group1_nodes'] nids_group2 = contact_surface['group2_nodes'] stiffness = contact_surface['stiffness'] dof = contact_surface['dof'] cid = contact_surface['cid'] print("nids_group1 = %s" % nids_group1) #model_left = BDF(debug=False) #model_left.read_bdf(left_bdf) #model_right = BDF(debug=False) #model_right.read_bdf(right_bdf) # change nodes from cid=0 to cid=N nodes_left = update_nodes_cid(model_main, nids_group1, cid) nodes_right = update_nodes_cid(model_main, nids_group2, cid) # find 5 closest nodes; TODO: update this... spring_sets = { # left # right 1: [2, 4, 5], 2: [10, 3], } c1 = c2 = dof neids_start = eid #i = 0 if i > 0: f.write( '$-------------------------------------------------------\n' ) f.write('$ contact set %i\n' % i) for g1, spring_nodes in sorted(iteritems(spring_sets)): f.write('$ g1=%i, dof=%i\n' % (g1, dof)) for g2 in spring_nodes: celas = ['CELAS2', eid, stiffness, g1, c1, g2, c2] f.write(print_card(celas)) eid += 1 #i += 1 neid = eid - neids_start eid_group = (neids_start, neid) eid_groups.append(eid_group) nodes_group = (nodes_left, nodes_right) nodes_groups.append(nodes_group) neids.append(neid) i += 1 f.close() # ------------------------------------------------------------------------ # we put this at the bottom b/c we need to update the node coordinate systems model_main.write_bdf(main_bdf2) del model_main # ------------------------------------------------------------------------ # set the initial stiffnesses stiffnesses = zeros(sum(neids), 'float64') errors = ones(sum(neids), 'float64') ieid = 0 for neid, contact_surface in zip(neids, contact_surfaces): nids_group1 = contact_surface['group1_nodes'] #nids_group2 = contact_surface['group2_nodes'] stiffness = contact_surface['stiffness'] #dof = contact_surface['dof'] #cid = contact_surface['cid'] #(nids_group1, nids_group2, dof, stiffness, cid, glue, initial_gap, max_deflection_error) = #'group1_nodes' : group1_nodes, #'group2_nodes' : group2_nodes, #'dof' : 1, # dof in contact (1, 2, 3, 4, 5, 6) - nodes in group1/2 #'K' : 1.e8, # stiffness of contact interface #'cid' : 1, # direction of contact #'glue' : False, # #'initial_gap' : 0.0, #'max_deflection_error' : max_deflection_error, #left_bdf, right_bdf, dof, stiffness, cid, glue, initial_gap = contact_surface stiffnesses[ieid:ieid + neid] = stiffness ieid += neid return eid_groups, nodes_groups, stiffnesses, errors