예제 #1
0
def update_3d_beams(ugrid,
                    model: BDF,
                    bar_pid_to_eids: Dict[int, List[int]]) -> Any:
    node0 = 0
    points_list = []
    for pid, eids in bar_pid_to_eids.items():
        pid_ref = model.properties[pid]
        ptype = pid_ref.type
        bar_type = pid_ref.bar_type
        #if bar_type == {'BAR', 'TUBE', 'TUBE2', 'ROD'}:
            #continue

        if ptype == 'PBARL':
            dim1 = dim2 = pid_ref.dim
        elif ptype == 'PBEAML':
            dim1 = pid_ref.dim[0, :]
            dim2 = pid_ref.dim[-1, :]
        else:
            raise NotImplementedError(pid_ref)
            #dim1 = dim2 = None
            #return node0

        try:
            func = BEAM_SETUP_MAP[bar_type]
        except KeyError:
            raise NotImplementedError(pid_ref)
            #print('skipping 3d bar_type = %r' % bar_type)
            #return node0
        faces, points1, points2 = func(dim1, dim2)
        del faces

        for eid in eids:
            elem = model.elements[eid]
            (nid1, nid2) = elem.node_ids
            #bar_nids.update([nid1, nid2])
            node1 = model.nodes[nid1]
            node2 = model.nodes[nid2]
            n1 = node1.get_position()
            n2 = node2.get_position()

            # wa/wb are not considered in i_offset
            # they are considered in ihat
            i = n2 - n1
            Li = norm(i)
            ihat = i / Li

            unused_v, wa, wb, xform = rotate_v_wa_wb(
                model, elem,
                n1, n2, node1, node2,
                ihat, i, eid, Li, model.log)
            if wb is None:
                # one or more of v, wa, wb are bad
                continue

            pointsi = transform_points(n1+wa, n2+wb, points1, points2, xform)
            dnode = points1.shape[0] * 2
            node0 += dnode
            points_list.append(pointsi)
    if node0:
        points = _create_vtk_points_from_list(points_list)
        ugrid.SetPoints(points)
        ugrid.Modified()
    return
예제 #2
0
def create_3d_beams(model: BDF,
                    bar_pid_to_eids: Dict[int, List[int]]) -> Optional[vtk.vtkUnstructuredGrid]:
    if len(bar_pid_to_eids) == 0:
        return None
    ugrid = vtk.vtkUnstructuredGrid()
    node0 = 0
    points_list = []
    eids_bad = []
    for pid, eids in bar_pid_to_eids.items():
        pid_ref = model.properties[pid]
        ptype = pid_ref.type
        bar_type = pid_ref.beam_type
        if bar_type == {'BAR', 'TUBE', 'TUBE2', 'ROD', 'DBOX', 'HAT1', 'BOX1'}:
            continue

        if ptype == 'PBARL':
            dim1 = dim2 = pid_ref.dim
        elif ptype == 'PBEAML':
            dim1 = pid_ref.dim[0, :]
            dim2 = pid_ref.dim[-1, :]
        else:
            raise NotImplementedError(pid_ref)
            #dim1 = dim2 = None
            #return node0

        try:
            func = BEAM_SETUP_MAP[bar_type]
        except KeyError:
            raise NotImplementedError(pid_ref)
            #print('skipping 3d bar_type = %r' % bar_type)
            #return node0
        faces, points1, points2 = func(dim1, dim2)
        for eid in eids:
            elem = model.elements[eid]
            (nid1, nid2) = elem.node_ids
            #bar_nids.update([nid1, nid2])
            node1 = model.nodes[nid1]
            node2 = model.nodes[nid2]
            n1 = node1.get_position()
            n2 = node2.get_position()

            # wa/wb are not considered in i_offset
            # they are considered in ihat
            i = n2 - n1
            Li = norm(i)
            ihat = i / Li

            #if elem.pa != 0:
                #nid_release_map[nid1].append((eid, elem.pa))
            #if elem.pb != 0:
                #nid_release_map[nid2].append((eid, elem.pb))

            unused_v, wa, wb, xform = rotate_v_wa_wb(
                model, elem,
                n1, n2, node1, node2,
                ihat, i, eid, Li, model.log)
            if wb is None:
                # one or more of v, wa, wb are bad
                eids_bad.append(eid)
                continue

            yhat = xform[1, :]
            zhat = xform[2, :]
            pointsi = transform_points(n1+wa, n2+wb, points1, points2, xform)
            face_idlist = faces_to_element_facelist(faces, node0)
            ugrid.InsertNextCell(vtk.VTK_POLYHEDRON, face_idlist)

            dnode = points1.shape[0] * 2
            node0 += dnode
            points_list.append(pointsi)
            #--------------------------------------------
            #bar_typei = get_bar_type(ptype, pid_ref)
            #centroid = (n1 + n2) / 2.
            #bar_types[bar_typei][0].append(eid)
            #bar_types[bar_typei][1].append((centroid, centroid + yhat * Li * scale))
            #bar_types[bar_typei][2].append((centroid, centroid + zhat * Li * scale))

    if eids_bad:
        eids_bad.sort()
        model.log.warning(f'failed transform PBARL/PBEAML for eids={eids_bad}')
    points = _create_vtk_points_from_list(points_list)
    ugrid.SetPoints(points)
    ugrid.Modified()
    return ugrid