Beispiel #1
0
def nastran_to_ugrid(bdf_filename, ugrid_filename_out=None, properties=None,
                     check_shells=True, check_solids=True):
    """
    set xref=False

    Parameters
    ----------
    bdf_filename : varies
        str : a bdf filename
        BDF() : a BDF object
    ugrid_filename_out : str (default=None -> ???)
        the path to the ugrid_filename
    properties : dict???
        ???
    check_shells : bool (default=True)
        verify that there is at least one shell element
    check_solids : bool (default=True)
        verify that there is at least one solid element
    """
    if isinstance(bdf_filename, str):
        bdf_model = read_bdf(bdf_filename)
    else:
        bdf_model = bdf_filename

    # pids_to_inlcude = []
    # for pid, prop in iteritems(model.properties):
        # if prop.type == 'PSHELL':
            # pids_to_include.append(pid)
    if properties is not None:
        for pid, pid_new in iteritems(properties):
            bdf_model.properties[pid].pid = pid_new

    card_types = ['CQUAD4', 'CTRIA3', 'CTETRA', 'CHEXA', 'GRID', 'CPENTA', 'CPYRAM']
    out = bdf_model.get_card_ids_by_card_types(card_types)
    node_ids = out['GRID']
    ctria3 = out['CTRIA3']
    cquad4 = out['CQUAD4']

    ctetra = out['CTETRA']
    cpyram = out['CPYRAM']
    cpenta = out['CPENTA']
    chexa = out['CHEXA']

    nnodes = len(node_ids)
    ntris = len(ctria3)
    nquads = len(cquad4)
    nshells = ntris + nquads
    ntetra = len(ctetra)
    npyram = len(cpyram)
    npenta = len(cpenta)
    nhexa = len(chexa)
    nsolids = ntetra + npyram + npenta + nhexa
    if nnodes == 0:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' % (nnodes, nshells, nsolids))
    if nshells == 0 and check_shells:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' % (nnodes, nshells, nsolids))
    if nsolids == 0 and check_solids:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' % (nnodes, nshells, nsolids))

    nodes = bdf_model.nodes
    elements = bdf_model.elements
    xyz_cid0 = array([nodes[nid].xyz for nid in node_ids], dtype='float64')

    pids = []
    model = UGRID()
    model.nodes = xyz_cid0
    if ntris:
        model.tris = array([elements[eid].node_ids for eid in ctria3], dtype='int32')
        ptris = array([elements[eid].Pid() for eid in ctria3], dtype='int32')
        pids.append(ptris)
    if nquads:
        model.quads = array([elements[eid].node_ids for eid in cquad4], dtype='int32')
        pquads = array([elements[eid].Pid() for eid in cquad4], dtype='int32')
        pids.append(pquads)

    if check_shells:
        if len(pids) == 1:
            model.pids = pids[0]
        elif len(pids) == 2:
            model.pids = hstack(pids)
        else:
            raise RuntimeError(pids)

    if ntetra:
        model.tets = array([elements[eid].node_ids for eid in ctetra], dtype='int32')
    if npyram:
        model.penta5s = array([elements[eid].node_ids for eid in cpyram], dtype='int32')
    if nhexa:
        model.penta6s = array([elements[eid].node_ids for eid in cpenta], dtype='int32')
    if nhexa:
        model.hexas = array([elements[eid].node_ids for eid in chexa], dtype='int32')

    model.log.debug('ugrid_filename_out = %r' % ugrid_filename_out)
    if ugrid_filename_out is not None:
        model.write_ugrid(ugrid_filename_out, check_shells=check_shells)
    return model
def nastran_to_ugrid(bdf_model, ugrid_filename_out=None, properties=None,
                     check_shells=True, check_solids=True):
    """
    set xref=False
    """
    # pids_to_inlcude = []
    # for pid, prop in iteritems(model.properties):
        # if prop.type == 'PSHELL':
            # pids_to_include.append(pid)
    if properties is not None:
        for pid, pid_new in iteritems(properties):
            bdf_model.properties[pid].pid = pid_new

    card_types = ['CQUAD4', 'CTRIA3', 'CTETRA', 'CHEXA', 'GRID', 'CPENTA', 'CPYRAM']
    out = bdf_model.get_card_ids_by_card_types(card_types)
    node_ids = out['GRID']
    ctria3 = out['CTRIA3']
    cquad4 = out['CQUAD4']

    ctetra = out['CTETRA']
    cpyram = out['CPYRAM']
    cpenta = out['CPENTA']
    chexa = out['CHEXA']

    nnodes = len(node_ids)
    ntris = len(ctria3)
    nquads = len(cquad4)
    nshells = ntris + nquads
    ntetra = len(ctetra)
    npyram = len(cpyram)
    npenta = len(cpenta)
    nhexa = len(chexa)
    nsolids = ntetra + npyram + npenta + nhexa
    if nnodes == 0:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' % (nnodes, nshells, nsolids))
    if nshells == 0 and check_shells:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' % (nnodes, nshells, nsolids))
    if nsolids == 0 and check_solids:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' % (nnodes, nshells, nsolids))

    nodes = bdf_model.nodes
    elements = bdf_model.elements
    xyz_cid0 = array([nodes[nid].xyz for nid in node_ids], dtype='float64')

    pids = []
    model = UGRID()
    model.nodes = xyz_cid0
    if ntris:
        model.tris = array([elements[eid].node_ids for eid in ctria3], dtype='int32')
        ptris = array([elements[eid].Pid() for eid in ctria3], dtype='int32')
        pids.append(ptris)
    if nquads:
        model.quads = array([elements[eid].node_ids for eid in cquad4], dtype='int32')
        pquads = array([elements[eid].Pid() for eid in cquad4], dtype='int32')
        pids.append(pquads)
    if len(pids) == 1:
        model.pids = pids[0]
    elif len(pids) == 2:
        model.pids = hstack(pids)
    else:
        raise RuntimeError(pids)

    if ntetra:
        model.tets = array([elements[eid].node_ids for eid in ctetra], dtype='int32')
    if npyram:
        model.penta5s = array([elements[eid].node_ids for eid in cpyram], dtype='int32')
    if nhexa:
        model.penta6s = array([elements[eid].node_ids for eid in cpenta], dtype='int32')
    if nhexa:
        model.hexas = array([elements[eid].node_ids for eid in chexa], dtype='int32')

    if ugrid_filename_out is not None:
        model.write_ugrid(ugrid_filename_out)
    return model
def nastran_to_ugrid(bdf_filename,
                     ugrid_filename_out=None,
                     properties=None,
                     check_shells=True,
                     check_solids=True):
    """
    set xref=False

    Parameters
    ----------
    bdf_filename : varies
        str : a bdf filename
        BDF() : a BDF object
    ugrid_filename_out : str (default=None -> ???)
        the path to the ugrid_filename
    properties : dict???
        ???
    check_shells : bool (default=True)
        verify that there is at least one shell element
    check_solids : bool (default=True)
        verify that there is at least one solid element
    """
    if isinstance(bdf_filename, str):
        bdf_model = read_bdf(bdf_filename)
    else:
        bdf_model = bdf_filename

    # pids_to_inlcude = []
    # for pid, prop in iteritems(model.properties):
    # if prop.type == 'PSHELL':
    # pids_to_include.append(pid)
    if properties is not None:
        for pid, pid_new in iteritems(properties):
            bdf_model.properties[pid].pid = pid_new

    card_types = [
        'CQUAD4', 'CTRIA3', 'CTETRA', 'CHEXA', 'GRID', 'CPENTA', 'CPYRAM'
    ]
    out = bdf_model.get_card_ids_by_card_types(card_types)
    node_ids = out['GRID']
    ctria3 = out['CTRIA3']
    cquad4 = out['CQUAD4']

    ctetra = out['CTETRA']
    cpyram = out['CPYRAM']
    cpenta = out['CPENTA']
    chexa = out['CHEXA']

    nnodes = len(node_ids)
    ntris = len(ctria3)
    nquads = len(cquad4)
    nshells = ntris + nquads
    ntetra = len(ctetra)
    npyram = len(cpyram)
    npenta = len(cpenta)
    nhexa = len(chexa)
    nsolids = ntetra + npyram + npenta + nhexa
    if nnodes == 0:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' %
                           (nnodes, nshells, nsolids))
    if nshells == 0 and check_shells:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' %
                           (nnodes, nshells, nsolids))
    if nsolids == 0 and check_solids:
        raise RuntimeError('nnodes=%i nshells=%i nsolids=%i' %
                           (nnodes, nshells, nsolids))

    nodes = bdf_model.nodes
    elements = bdf_model.elements
    xyz_cid0 = array([nodes[nid].xyz for nid in node_ids], dtype='float64')

    pids = []
    model = UGRID()
    model.nodes = xyz_cid0
    if ntris:
        model.tris = array([elements[eid].node_ids for eid in ctria3],
                           dtype='int32')
        ptris = array([elements[eid].Pid() for eid in ctria3], dtype='int32')
        pids.append(ptris)
    if nquads:
        model.quads = array([elements[eid].node_ids for eid in cquad4],
                            dtype='int32')
        pquads = array([elements[eid].Pid() for eid in cquad4], dtype='int32')
        pids.append(pquads)

    if check_shells:
        if len(pids) == 1:
            model.pids = pids[0]
        elif len(pids) == 2:
            model.pids = hstack(pids)
        else:
            raise RuntimeError(pids)

    if ntetra:
        model.tets = array([elements[eid].node_ids for eid in ctetra],
                           dtype='int32')
    if npyram:
        model.penta5s = array([elements[eid].node_ids for eid in cpyram],
                              dtype='int32')
    if nhexa:
        model.penta6s = array([elements[eid].node_ids for eid in cpenta],
                              dtype='int32')
    if nhexa:
        model.hexas = array([elements[eid].node_ids for eid in chexa],
                            dtype='int32')

    model.log.debug('ugrid_filename_out = %r' % ugrid_filename_out)
    if ugrid_filename_out is not None:
        model.write_ugrid(ugrid_filename_out, check_shells=check_shells)
    return model