Example #1
0
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
Example #2
0
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
Example #3
0
def cart3d_to_tecplot(cart3d_filename, tecplot_filename):
    """
    Converts Cart3d to Tecplot
    """
    model = Cart3D()
    model.read_cart3d(cart3d_filename)
    tecplot = Tecplot()
    tecplot.xyz = model.points
    tecplot.tri_elements = model.elements
    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
Example #4
0
def ugrid_to_tecplot(ugrid_model, tecplot_filename=None, log=None, debug=False):
    """
    Converts a UGRID to a Tecplot ASCII file.

    Parameters
    ----------
    ugrid_filename : varies
        str : the input UGRID filename
        UGRID : the UGRID object
    tecplot_filename : str
        the output Tecplot filename
    log : logger; default=None
        a logger object
    """
    nnodes = len(ugrid_model.nodes)
    nodes = zeros((nnodes, 3), dtype='float64')
    ugrid_model.check_hanging_nodes()
    elements = []

    ntets = len(ugrid_model.tets)
    non_tets = len(ugrid_model.penta5s) + len(ugrid_model.penta6s) + len(ugrid_model.hexas)
    assert ntets + non_tets > 0, 'nsolids=%s' % (ntets + non_tets)

    tecplot = Tecplot(log=log, debug=debug)
    tecplot.xyz = ugrid_model.nodes

    if ntets and non_tets == 0:
        elements = ugrid_model.tets
        tecplot.tet_elements = elements - 1
    elif non_tets:
        for element in ugrid_model.tets:
            n1, n2, n3, n4 = element
            elements.append([n1, n2, n3, n4,
                             n4, n4, n4, n4])
        for element in ugrid_model.penta5s:
            n1, n2, n3, n4, n5 = element
            elements.append([n1, n2, n3, n4,
                             n5, n5, n5, n5])
        for element in ugrid_model.penta6s:
            n1, n2, n3, n4, n5, n6 = element
            elements.append([n1, n2, n3, n4,
                             n5, n6, n6, n6])
        for element in ugrid_model.hexas:
            n1, n2, n3, n4, n5, n6, n7, n8 = element
            elements.append([n1, n2, n3, n4,
                             n5, n6, n7, n8])
        elements = array(elements, dtype='int32') - 1
        tecplot.hexa_elements = elements
    else:
        raise RuntimeError()

    if tecplot_filename is not None:
        tecplot.write_tecplot(tecplot_filename)
    return tecplot
Example #5
0
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
Example #6
0
def cart3d_to_tecplot(cart3d_filename, tecplot_filename, log=None, debug=False):
    """
    Converts Cart3d to Tecplot
    """
    if isinstance(cart3d_filename, Cart3D):
        model = cart3d_filename
    else:
        model = read_cart3d(cart3d_filename, log=log, debug=debug)

    tecplot = Tecplot()
    tecplot.xyz = model.points
    tecplot.tri_elements = model.elements
    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
Example #7
0
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
Example #8
0
def cart3d_to_tecplot(cart3d_filename,
                      tecplot_filename,
                      log=None,
                      debug=False):
    """
    Converts Cart3d to Tecplot
    """
    if isinstance(cart3d_filename, Cart3D):
        model = cart3d_filename
    else:
        model = read_cart3d(cart3d_filename, log=log, debug=debug)

    tecplot = Tecplot()
    tecplot.xyz = model.points
    tecplot.tri_elements = model.elements
    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
def cart3d_to_tecplot(cart3d_filename,
                      tecplot_filename,
                      log=None,
                      debug=False):
    """
    Converts Cart3d to Tecplot
    """
    if isinstance(cart3d_filename, Cart3D):
        model = cart3d_filename
    else:
        model = read_cart3d(cart3d_filename, log=log, debug=debug)

    tecplot = Tecplot()
    tecplot.log = model.log
    zone = Zone(model.log)
    zone.headers_dict['VARIABLES'] = ['X', 'Y', 'Z']
    zone.xyz = model.points
    zone.tri_elements = model.elements + 1
    tecplot.zones = [zone]

    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
    zone.variables = variables
    tecplot_model.zones = [zone]
    return tecplot_model


def nastran_tables_to_tecplot_filenames(
        tecplot_filename_base: str,
        bdf_model: BDF,
        case,
        variables: Optional[List[str]] = None,
        ivars: Optional[List[int]] = None) -> None:
    if variables is None:
        variables = case.headers
    if ivars is None:
        ivars = np.arange(0, len(variables))

    tecplot_model = nastran_table_to_tecplot(bdf_model, case, variables)
    zone = tecplot_model.zones[0]
    for itime, time in enumerate(case._times):
        if '%' in tecplot_filename_base:
            tecplot_filename = tecplot_filename_base % time
        else:
            tecplot_filename = tecplot_filename_base

        # you can't combine the two lines or it transposes it...
        nodal_results = case.data[itime, :, :]
        zone.nodal_results = nodal_results[:, ivars]
        tecplot_model.write_tecplot(tecplot_filename,
                                    res_types=None,
                                    adjust_nids=False)
def nastran_to_tecplot_filename(bdf_filename, tecplot_filename, log=None, debug=False):
    """converts a BDF file to Tecplot format; supports solid elements"""
    model = BDF(log=log, debug=debug)
    model.read_bdf(bdf_filename)
    # tecplot = nastran_to_tecplot(model)

    #log.info('card_count = %s' % model.card_count)
    nnodes = len(model.nodes)
    nodes = np.zeros((nnodes, 3), dtype='float64')
    elements = []

    i = 0
    nodeid_to_i_map = {}
    for node_id, node in sorted(model.nodes.items()):
        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 unused_eid, element in sorted(model.elements.items()):
        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:
            model.log.info('skip etype=%r' % element.type)
            model.log.info(element)
    elements = np.array(elements, dtype='int32')

    tecplot = Tecplot(log=model.log)
    zone = Zone(model.log)
    zone.headers_dict['VARIABLES'] = ['X', 'Y', 'Z']
    zone.xyz = nodes
    zone.hexa_elements = elements
    zone.nodal_results = np.array([], dtype='float32')
    tecplot.zones = [zone]
    tecplot.write_tecplot(tecplot_filename)
    return tecplot
def ugrid_to_tecplot(ugrid_filename,
                     tecplot_filename=None,
                     log=None,
                     debug=False):
    """
    Converts a UGRID to a Tecplot ASCII file.

    Parameters
    ----------
    ugrid_filename : varies
        str : the input UGRID filename
        UGRID : the UGRID object
    tecplot_filename : str
        the output Tecplot filename
    log : logger; default=None
        a logger object
    debug : bool; default=False
        developer debug

    Returns
    -------
    tecplot_model : Tecplot()
        the Tecplot object
    """
    ugrid_model = get_ugrid_model(ugrid_filename, log=log, debug=debug)
    #nnodes = len(ugrid_model.nodes)
    #nodes = zeros((nnodes, 3), dtype='float64')
    ugrid_model.check_hanging_nodes()
    elements = []

    ntets = len(ugrid_model.tets)
    non_tets = len(ugrid_model.penta5s) + len(ugrid_model.penta6s) + len(
        ugrid_model.hexas)
    assert ntets + non_tets > 0, 'nsolids=%s' % (ntets + non_tets)

    tecplot = Tecplot(log=ugrid_model.log, debug=debug)
    zone = Zone(ugrid_model.log)
    zone.headers_dict['VARIABLES'] = ['X', 'Y', 'Z']
    zone.xyz = ugrid_model.nodes

    if ntets and non_tets == 0:
        elements = ugrid_model.tets
        zone.tet_elements = elements - 1
    elif non_tets:
        for element in ugrid_model.tets:
            n1, n2, n3, n4 = element
            elements.append([n1, n2, n3, n4, n4, n4, n4, n4])
        for element in ugrid_model.penta5s:
            n1, n2, n3, n4, n5 = element
            elements.append([n1, n2, n3, n4, n5, n5, n5, n5])
        for element in ugrid_model.penta6s:
            n1, n2, n3, n4, n5, n6 = element
            elements.append([n1, n2, n3, n4, n5, n6, n6, n6])
        for element in ugrid_model.hexas:
            n1, n2, n3, n4, n5, n6, n7, n8 = element
            elements.append([n1, n2, n3, n4, n5, n6, n7, n8])
        elements = np.array(elements, dtype='int32') - 1
        zone.hexa_elements = elements
    else:
        raise RuntimeError()

    if tecplot_filename is not None:
        tecplot.write_tecplot(tecplot_filename)
    tecplot.zones = [zone]
    return tecplot, zone