示例#1
0
def fill_vtk_unstructured_grid_results(model: pyNastranH5, vtk_ugrid: vtk.vtkUnstructuredGrid,
                                       eids: np.ndarray) -> None:
    point_data = vtk_ugrid.GetPointData()
    cell_data = vtk_ugrid.GetCellData()
    for i, res in model.results.items():
        if res.location == 'node':
            names, resultsi = res.get_results()
            for name, result in zip(names, resultsi):
                print(name)
                #name = 'cat'
                result.SetName(name)
                point_data.AddArray(result)

                # remove
                #point_data.SetActiveVectors(name)
                #point_data.SetVectors(result)
        elif res.location == 'element':
            res.eids = eids
            names, resultsi = res.get_results()
            for name, result in zip(names, resultsi):
                print(name)
                #name = 'cat'
                result.SetName(name)
                cell_data.AddArray(result)
                #cell_data.SetScalars(result)
        else:
            raise NotImplementedError(res)
def fill_vtk_unstructured_grid(geom_model: BDF,
                               vtk_ugrid: vtk.vtkUnstructuredGrid,
                               add_property=True,
                               add_material=True):
    #cell_type_point = 1 # vtk.vtkVertex().GetCellType()
    #cell_type_line = 3 # vtk.vtkLine().GetCellType()
    #cell_type_tri3 = 5
    #cell_type_tri6 = 22
    #cell_type_quad4 = 9
    #cell_type_quad8 = 23
    #cell_type_tetra4 = 10
    #cell_type_tetra10 = 24
    #cell_type_pyram5 = 14 # vtk.vtkPyramid().GetCellType()
    #cell_type_pyram13 = 27 # vtk.vtkQuadraticPyramid().GetCellType()
    #cell_type_hexa8 = 12
    #cell_type_hexa20 = 25
    #cell_type_penta6 = 13
    #cell_type_penta15 = 26
    #nodes, node_ids, nid_map, idtype = _load_nodes(geom_model)
    nodes = geom_model._nodes
    node_ids = geom_model._node_ids
    #nid_map = geom_model._nid_map
    idtype = geom_model._idtype
    vtk_points = numpy_to_vtk_points(nodes, points=None, dtype='<f', deep=1)

    vtk_ugrid.SetPoints(vtk_points)

    etype_nids, cell_offsets_array, cell_types_array, eids, pids = _load_elements(
        geom_model, node_ids, idtype=idtype)
    nelements = len(eids)

    # build the grid
    _elements_to_vtk(vtk_ugrid, etype_nids, cell_offsets_array, cell_types_array)

    # fill the grid with results
    #point_data = vtk_ugrid.GetPointData()

    cell_data = vtk_ugrid.GetCellData()
    eid_array = numpy_to_vtk(eids, deep=0, array_type=None)
    eid_array.SetName('ElementID')
    cell_data.AddArray(eid_array)

    if add_property:
        pid_array = numpy_to_vtk(pids, deep=0, array_type=None)
        pid_array.SetName('PropertyID')
        cell_data.AddArray(pid_array)

    #if add_property:
        #pid_array = numpy_to_vtk(pids, deep=0, array_type=None)
        #pid_array.SetName('PropertyID')
        #cell_data.AddArray(pid_array)

    if add_material:
        psolid_mids = np.full(nelements, -1, dtype='int64')
        pshell_mids = np.full((nelements, 4), -1, dtype='int64')
        thickness = np.full(nelements, np.nan, dtype='float32')
        upids = np.unique(pids)
        is_solid = False
        is_shell = False
        for pid in upids:
            ipid = np.where(pid == pids)
            prop = geom_model.properties[pid]
            if prop.type == 'PSOLID':
                is_solid = True
                psolid_mids[ipid] = prop.mid
            elif prop.type == 'PSHELL':
                is_shell = True
                thickness[ipid] = prop.t
                for imid, mid in enumerate([prop.mid1, prop.mid2, prop.mid3, prop.mid4]):
                    if mid is None:
                        continue
                    pshell_mids[ipid, imid] = mid
            else:
                geom_model.log.warning(f'skipping:\n{prop}')

        if is_solid:
            mid_array = numpy_to_vtk(psolid_mids, deep=0, array_type=None)
            mid_array.SetName('Solid Material')
            cell_data.AddArray(mid_array)

        if is_shell:
            thickness_array = numpy_to_vtk(thickness, deep=0, array_type=None)
            thickness_array.SetName('Shell Thickness')
            cell_data.AddArray(thickness_array)
            for imid in range(4):
                mids = pshell_mids[:, imid]
                shell_mid_array = numpy_to_vtk(mids, deep=0, array_type=None)
                thickness_array.SetName(f'Shell Material {imid+1}')
                cell_data.AddArray(shell_mid_array)
    #print(point_data)
    return eids