Beispiel #1
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
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
0
def nastran_to_tecplot(model):
    """assumes sequential nodes"""
    tecplot = Tecplot()

    nnodes = len(model.nodes)
    inode_max = max(model.nodes)
    if nnodes == inode_max:
        xyz = zeros((nnodes, 3), dtype='float64')
        i = 0
        for nid, node in sorted(iteritems(model.nodes)):
            xyz[i, :] = node.get_position()
            i += 1
        else:
            raise RuntimeError('sequential node IDs required; nnodes=%s inode_max=%s' % (nnodes, inode_max))
    tecplot.xyz = xyz

    nquads = model.card_count['CQUAD4'] if 'CQUAD4' in model.card_count else 0
    ntets = model.card_count['CTETRA'] if 'CTETRA' in model.card_count else 0
    #ntrias = model.card_count['CTRIA3'] if 'CTRIA3' in model.card_count else 0
    nhexas = model.card_count['CHEXA'] if 'CHEXA' in model.card_count else 0
    nelements = len(model.elements)
    tris = []
    quads = []
    tets = []
    hexas = []
    pentas = []
    #i = 0
    #pids = zeros(nelements, dtype='int32')
    #mids = zeros(nelements, dtype='int32')
    unhandled_types = set([])
    for eid, element in iteritems(model.elements):
        if element.type in ['CTRIA3']:
            tris.append(element.node_ids)
        elif element.type in ['CQUAD4']:
            quads.append(element.node_ids)
        elif element.type == 'CTETRA':
            tets.append(element.node_ids[:4])
        elif element.type == 'CPENTA':
            pentas.append(element.node_ids[:6])
        elif element.type == 'CHEXA':
            hexas.append(element.node_ids[:8])
        else:
            unhandled_types.add(element.type)
        #pid = element.Pid()
        #mid = element.Mid()
        #pids[i] = pid
        #mids[i] = mid
        #i += 1

    for etype in unhandled_types:
        print('ignoring %s' % etype)

    # only supports nodal results
    #tecplot.results = vstack([pids, mids])#.T
    #print(tecplot.results.shape)
    #tecplot.result_names = ['PropertyID', 'MaterialID']

    ntris = len(tris)
    nquads = len(quads)
    nshells = ntris + nquads

    ntets = len(tets)
    npentas = len(pentas)
    nhexas = len(hexas)
    nsolids = ntets + npentas + nhexas
    nnot_tris = nquads
    nnot_quads = ntris
    nnot_tets = npentas + nhexas
    nnot_hexas = ntets + npentas
    if ntris and not nnot_tris and not nsolids:
        tecplot.tri_elements = array(tris, dtype='int32')
    elif nquads and not nnot_quads and not nsolids:
        tecplot.quad_elements = array(quads, dtype='int32')
    elif ntets and not nnot_tets and not nshells:
        tecplot.tet_elements = array(tets, dtype='int32')
    elif nhexas and not nnot_hexas and not nshells:
        tecplot.hexa_elements = array(hexas, dtype='int32')
    elif not nshells:
        elements = zeros((nelements, 8), dtype='int32')
        if ntets:
            tets = array(tets, dtype='int32')
            elements[:ntets, :4] = tets
            elements[:ntets, 4] = elements[:ntets, 3]
            elements[:ntets, 5] = elements[:ntets, 3]
            elements[:ntets, 6] = elements[:ntets, 3]
            elements[:ntets, 7] = elements[:ntets, 3]
        if npentas:
            # penta6
            pentas = array(pentas, dtype='int32')
            elements[ntets:ntets + npentas, :6] = pentas
            elements[ntets:ntets + npentas, 6] = elements[:ntets, 5]
            elements[ntets:ntets + npentas, 7] = elements[:ntets, 5]
        if nhexas:
            hexas = array(hexas, dtype='int32')
            elements[ntets + npentas:ntets + npentas + nhexas, :6] = pentas
            elements[ntets + npentas:ntets + npentas + nhexas, 6] = elements[:ntets, 5]
            elements[ntets + npentas:ntets + npentas + nhexas, 7] = elements[:ntets, 5]
        tecplot.hexa_elements = array(elements)
    elif not nsolids:
        elements = zeros((nelements, 4), dtype='int32')
        tris = array(tris, dtype='int32')
        elements[:ntris, :3] = tris
        elements[:ntris, 4] = elements[:ntets, 3]

        quads = array(quads, dtype='int32')
        elements[ntris:, :] = quads
    else:
        msg = 'Only solids or shells are allowed (not both)\n'
        msg += '  nsolids=%s nshells=%s\n' % (nsolids, nshells)
        msg += '  ntris=%s nquads=%s\n' % (ntris, nquads)
        msg += '  ntets=%s npentas=%s nhexas=%s\n' % (ntets, npentas, nhexas)
        raise NotImplementedError(msg)
    return tecplot
Beispiel #7
0
def nastran_to_tecplot(model):
    """assumes sequential nodes"""
    tecplot = Tecplot()

    nnodes = len(model.nodes)
    inode_max = max(model.nodes)
    if nnodes == inode_max:
        xyz = zeros((nnodes, 3), dtype='float64')
        i = 0
        for nid, node in sorted(iteritems(model.nodes)):
            xyz[i, :] = node.get_position()
            i += 1
        else:
            raise RuntimeError(
                'sequential node IDs required; nnodes=%s inode_max=%s' %
                (nnodes, inode_max))
    tecplot.xyz = xyz

    nquads = model.card_count['CQUAD4'] if 'CQUAD4' in model.card_count else 0
    ntets = model.card_count['CTETRA'] if 'CTETRA' in model.card_count else 0
    #ntrias = model.card_count['CTRIA3'] if 'CTRIA3' in model.card_count else 0
    nhexas = model.card_count['CHEXA'] if 'CHEXA' in model.card_count else 0
    nelements = len(model.elements)
    tris = []
    quads = []
    tets = []
    hexas = []
    pentas = []
    #i = 0
    #pids = zeros(nelements, dtype='int32')
    #mids = zeros(nelements, dtype='int32')
    unhandled_types = set([])
    for eid, element in iteritems(model.elements):
        if element.type in ['CTRIA3']:
            tris.append(element.node_ids)
        elif element.type in ['CQUAD4']:
            quads.append(element.node_ids)
        elif element.type == 'CTETRA':
            tets.append(element.node_ids[:4])
        elif element.type == 'CPENTA':
            pentas.append(element.node_ids[:6])
        elif element.type == 'CHEXA':
            hexas.append(element.node_ids[:8])
        else:
            unhandled_types.add(element.type)
        #pid = element.Pid()
        #mid = element.Mid()
        #pids[i] = pid
        #mids[i] = mid
        #i += 1

    for etype in unhandled_types:
        print('ignoring %s' % etype)

    # only supports nodal results
    #tecplot.results = vstack([pids, mids])#.T
    #print(tecplot.results.shape)
    #tecplot.result_names = ['PropertyID', 'MaterialID']

    ntris = len(tris)
    nquads = len(quads)
    nshells = ntris + nquads

    ntets = len(tets)
    npentas = len(pentas)
    nhexas = len(hexas)
    nsolids = ntets + npentas + nhexas
    nnot_tris = nquads
    nnot_quads = ntris
    nnot_tets = npentas + nhexas
    nnot_hexas = ntets + npentas
    if ntris and not nnot_tris and not nsolids:
        tecplot.tri_elements = array(tris, dtype='int32')
    elif nquads and not nnot_quads and not nsolids:
        tecplot.quad_elements = array(quads, dtype='int32')
    elif ntets and not nnot_tets and not nshells:
        tecplot.tet_elements = array(tets, dtype='int32')
    elif nhexas and not nnot_hexas and not nshells:
        tecplot.hexa_elements = array(hexas, dtype='int32')
    elif not nshells:
        elements = zeros((nelements, 8), dtype='int32')
        if ntets:
            tets = array(tets, dtype='int32')
            elements[:ntets, :4] = tets
            elements[:ntets, 4] = elements[:ntets, 3]
            elements[:ntets, 5] = elements[:ntets, 3]
            elements[:ntets, 6] = elements[:ntets, 3]
            elements[:ntets, 7] = elements[:ntets, 3]
        if npentas:
            # penta6
            pentas = array(pentas, dtype='int32')
            elements[ntets:ntets + npentas, :6] = pentas
            elements[ntets:ntets + npentas, 6] = elements[:ntets, 5]
            elements[ntets:ntets + npentas, 7] = elements[:ntets, 5]
        if nhexas:
            hexas = array(hexas, dtype='int32')
            elements[ntets + npentas:ntets + npentas + nhexas, :6] = pentas
            elements[ntets + npentas:ntets + npentas + nhexas,
                     6] = elements[:ntets, 5]
            elements[ntets + npentas:ntets + npentas + nhexas,
                     7] = elements[:ntets, 5]
        tecplot.hexa_elements = array(elements)
    elif not nsolids:
        elements = zeros((nelements, 4), dtype='int32')
        tris = array(tris, dtype='int32')
        elements[:ntris, :3] = tris
        elements[:ntris, 4] = elements[:ntets, 3]

        quads = array(quads, dtype='int32')
        elements[ntris:, :] = quads
    else:
        msg = 'Only solids or shells are allowed (not both)\n'
        msg += '  nsolids=%s nshells=%s\n' % (nsolids, nshells)
        msg += '  ntris=%s nquads=%s\n' % (ntris, nquads)
        msg += '  ntets=%s npentas=%s nhexas=%s\n' % (ntets, npentas, nhexas)
        raise NotImplementedError(msg)
    return tecplot