Exemplo n.º 1
0
def make_monpnt1s_from_cids(model: BDF,
                            nids,
                            cids,
                            cid_to_inids,
                            delete_unused_coords=True):
    """
    Creates MONPNT1s, AECOMPs, and SET1s by a series of coordinate systems

    Parameters
    ----------
    model :: BDF()
        the model object
    nids : (nnodes, ) int ndarray
        all the nodes in the model
    cid_to_inids : Dict[cid]=inids
        cid : int
            coord id
        inids : (nnodes_in_cid, ) int ndarray
            the indicies in nids in sorted order
    cids : List[int]
        cids to create
    delete_unused_coords : bool; default=True
        delete coordinate systems from the model that aren't used

    Notes
    -----
    Doesn't write duplicate sets
    """
    nnodes_old = 0
    origin_old = np.zeros(3)
    for cid in cids:
        origin = model.coords[cid].origin
        xyz = origin
        inids = cid_to_inids[cid]
        nidsi = nids[inids]
        nnodes = len(nidsi)
        if nnodes == 0:
            del model.coords[cid]
            continue

        # a coordinate system is the same and can be skipped if all the
        # data about is is the same
        #
        # TODO: this is not good enough in the general case, but is probably
        #       ok practically
        if nnodes == nnodes_old and np.allclose(origin_old, origin):
            if delete_unused_coords:
                del model.coords[cid]
            continue

        label = 'xyz %s %s %s' % (xyz[0], xyz[1], xyz[2])
        #aecomp = cid

        ids = nidsi
        model.add_set1(cid, ids, is_skin=False, comment='')
        aecomp_name = 'ae%i' % cid
        list_type = 'SET1'
        lists = [cid]
        model.add_aecomp(aecomp_name, list_type, lists, comment='')

        name = 'c%i' % cid
        axes = '123456'
        model.add_monpnt1(name,
                          label,
                          axes,
                          aecomp_name, [0., 0., 0.],
                          cp=cid,
                          cd=None,
                          comment='')
        nnodes_old = nnodes
        origin_old = origin