def nastran_to_tecplot_filename(bdf_filename, tecplot_filename, log=None): model = BDF(log=log) model.read_bdf(bdf_filename) # tecplot = nastran_to_tecplot(model) #log.info('card_count = %s' % model.card_count) nnodes = len(model.nodes) nodes = zeros((nnodes, 3), dtype='float64') elements = [] i = 0 nodeid_to_i_map = {} for node_id, node in sorted(iteritems(model.nodes)): xyz = node.get_position() nodes[i, :] = xyz nodeid_to_i_map[node_id] = i i += 1 assert len(model.nodes) == i, 'model.nodes=%s i=%s' % (len(model.nodes), i) for eid, element in sorted(iteritems(model.elements)): if element.type in ['CTETRA']: n1, n2, n3, n4 = element.node_ids i1, i2, i3, i4 = nodeid_to_i_map[n1], nodeid_to_i_map[ n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4] elements.append([i1, i2, i3, i4, i4, i4, i4, i4]) elif element.type in ['CPENTA']: n1, n2, n3, n4, n5, n6 = element.node_ids i1, i2, i3, i4, i5, i6 = (nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4], nodeid_to_i_map[n5], nodeid_to_i_map[n6]) elements.append([i1, i2, i3, i4, i5, i6, i6, i6]) elif element.type in ['CPYRAM']: n1, n2, n3, n4, n5 = element.node_ids i1, i2, i3, i4, i5 = (nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4], nodeid_to_i_map[n5]) elements.append([i1, i2, i3, i4, i5, i5, i5, i5]) elif element.type in ['CHEXA']: n1, n2, n3, n4, n5, n6, n7, n8 = element.node_ids i1, i2, i3, i4, i5, i6, i7, i8 = (nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4], nodeid_to_i_map[n5], nodeid_to_i_map[n6], nodeid_to_i_map[n7], nodeid_to_i_map[n8]) elements.append([i1, i2, i3, i4, i5, i6, i7, i8]) else: self.log.info('skip etype=%r' % element.type) self.log.info(element) elements = array(elements, dtype='int32') tecplot = Tecplot() tecplot.xyz = nodes tecplot.hexa_elements = elements tecplot.write_tecplot(tecplot_filename) tecplot.results = array([], dtype='float32') return tecplot
def nastran_to_tecplot_filename(bdf_filename, tecplot_filename, log=None): model = BDF(log=log) model.read_bdf(bdf_filename) # tecplot = nastran_to_tecplot(model) #log.info('card_count = %s' % model.card_count) nnodes = len(model.nodes) nodes = zeros((nnodes, 3), dtype='float64') elements = [] i = 0 nodeid_to_i_map = {} for node_id, node in sorted(iteritems(model.nodes)): xyz = node.get_position() nodes[i, :] = xyz nodeid_to_i_map[node_id] = i i += 1 assert len(model.nodes) == i, 'model.nodes=%s i=%s' % (len(model.nodes), i) for eid, element in sorted(iteritems(model.elements)): if element.type in ['CTETRA']: n1, n2, n3, n4 = element.node_ids i1, i2, i3, i4 = nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4] elements.append([i1, i2, i3, i4, i4, i4, i4, i4]) elif element.type in ['CPENTA']: n1, n2, n3, n4, n5, n6 = element.node_ids i1, i2, i3, i4, i5, i6 = ( nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4], nodeid_to_i_map[n5], nodeid_to_i_map[n6]) elements.append([i1, i2, i3, i4, i5, i6, i6, i6]) elif element.type in ['CPYRAM']: n1, n2, n3, n4, n5 = element.node_ids i1, i2, i3, i4, i5 = ( nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4], nodeid_to_i_map[n5]) elements.append([i1, i2, i3, i4, i5, i5, i5, i5]) elif element.type in ['CHEXA']: n1, n2, n3, n4, n5, n6, n7, n8 = element.node_ids i1, i2, i3, i4, i5, i6, i7, i8 = ( nodeid_to_i_map[n1], nodeid_to_i_map[n2], nodeid_to_i_map[n3], nodeid_to_i_map[n4], nodeid_to_i_map[n5], nodeid_to_i_map[n6], nodeid_to_i_map[n7], nodeid_to_i_map[n8]) elements.append([i1, i2, i3, i4, i5, i6, i7, i8]) else: self.log.info('skip etype=%r' % element.type) self.log.info(element) elements = array(elements, dtype='int32') tecplot = Tecplot() tecplot.xyz = nodes tecplot.hexa_elements = elements tecplot.write_tecplot(tecplot_filename) tecplot.results = array([], dtype='float32') return tecplot
def merge_tecplot_files(tecplot_filenames, tecplot_filename_out=None, log=None): """merges one or more tecplot files""" assert isinstance(tecplot_filenames, (list, tuple)), type(tecplot_filenames) assert len(tecplot_filenames) > 0, tecplot_filenames xyz = [] tri_elements = [] quad_elements = [] tet_elements = [] hexa_elements = [] results = [] nnodes = 0 model = Tecplot(log=log) if len(tecplot_filenames) == 1: model.read_tecplot(tecplot_filenames[0]) if tecplot_filename_out is not None: model.write_tecplot(tecplot_filename_out) return model for tecplot_filename in tecplot_filenames: model.log.info('reading %s' % tecplot_filename) model.read_tecplot(tecplot_filename) xyz.append(model.xyz) if len(model.tri_elements): tri_elements.append(model.tri_elements + nnodes) if len(model.quad_elements): quad_elements.append(model.quad_elements + nnodes) if len(model.tet_elements): tet_elements.append(model.tet_elements + nnodes) if len(model.hexa_elements): hexa_elements.append(model.hexa_elements + nnodes) results.append(model.results) nnodes += model.nnodes model.xyz = vstack(xyz) if tri_elements: model.tri_elements = vstack(tri_elements) if quad_elements: model.quad_elements = vstack(quad_elements) if tet_elements: model.tet_elements = vstack(tet_elements) if hexa_elements: model.hexa_elements = vstack(hexa_elements) model.results = vstack(results) if tecplot_filename_out is not None: model.write_tecplot(tecplot_filename_out) return model
def merge_tecplot_files(tecplot_filenames, tecplot_filename_out=None, log=None): assert isinstance(tecplot_filenames, (list, tuple)), type(tecplot_filenames) assert len(tecplot_filenames) > 0, tecplot_filenames xyz = [] tri_elements = [] quad_elements = [] tet_elements = [] hexa_elements = [] results = [] nnodes = 0 model = Tecplot(log=log) if len(tecplot_filenames) == 1: model.read_tecplot(tecplot_filenames[0]) if tecplot_filename_out is not None: model.write_tecplot(tecplot_filename_out) return model for tecplot_filename in tecplot_filenames: model.log.info('reading %s' % tecplot_filename) model.read_tecplot(tecplot_filename) xyz.append(model.xyz) if len(model.tri_elements): tri_elements.append(model.tri_elements + nnodes) if len(model.quad_elements): quad_elements.append(model.quad_elements + nnodes) if len(model.tet_elements): tet_elements.append(model.tet_elements + nnodes) if len(model.hexa_elements): hexa_elements.append(model.hexa_elements + nnodes) results.append(model.results) nnodes += model.nnodes model.xyz = vstack(xyz) if tri_elements: model.tri_elements = vstack(tri_elements) if quad_elements: model.quad_elements = vstack(quad_elements) if tet_elements: model.tet_elements = vstack(tet_elements) if hexa_elements: model.hexa_elements = vstack(hexa_elements) model.results = vstack(results) if tecplot_filename_out is not None: model.write_tecplot(tecplot_filename_out) return model