pyraScalars = vtk.vtkFloatArray() pyraScalars.SetNumberOfTuples(13) pyraScalars.InsertValue(0, 1.0) pyraScalars.InsertValue(1, 1.0) pyraScalars.InsertValue(2, 1.0) pyraScalars.InsertValue(3, 1.0) pyraScalars.InsertValue(4, 1.0) pyraScalars.InsertValue(5, 1.0) pyraScalars.InsertValue(6, 0.0) pyraScalars.InsertValue(7, 0.0) pyraScalars.InsertValue(8, 0.0) pyraScalars.InsertValue(9, 0.0) pyraScalars.InsertValue(10, 0.0) pyraScalars.InsertValue(11, 0.0) pyraScalars.InsertValue(12, 0.0) aPyramid = vtk.vtkQuadraticPyramid() for i in range(aPyramid.GetNumberOfPoints()): aPyramid.GetPointIds().SetId(i, i) aPyramidGrid = vtk.vtkUnstructuredGrid() aPyramidGrid.Allocate(1, 1) aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds()) aPyramidGrid.SetPoints(pyraPoints) aPyramidGrid.GetPointData().SetScalars(pyraScalars) # TriQuadratic pyramid TQpyraPoints = vtk.vtkPoints() TQpyraPoints.SetNumberOfPoints(19) TQpyraPointsCoords = np.array([ [12, 2, 0], [13, 2, 0], [13, 3, 0],
def add_vectorized_elements(model, nelements: int, idtype: str, log): dim_array = np.full(nelements, -1, dtype='int32') pids_array = np.zeros(nelements, 'int32') nnodes_array = np.full(nelements, -1, dtype='int32') #mids = np.zeros(nelements, 'int32') #material_coord = np.zeros(nelements, 'int32') #min_interior_angle = np.zeros(nelements, 'float32') #max_interior_angle = np.zeros(nelements, 'float32') #dideal_theta = np.zeros(nelements, 'float32') #max_skew_angle = np.zeros(nelements, 'float32') #max_warp_angle = np.zeros(nelements, 'float32') #max_aspect_ratio = np.zeros(nelements, 'float32') #area = np.zeros(nelements, 'float32') #area_ratio = np.zeros(nelements, 'float32') #taper_ratio = np.zeros(nelements, 'float32') #min_edge_length = np.zeros(nelements, 'float32') if len(model.ctria3): model.ctria3.quality() #if len(model.tria6): #model.tria6.quality() #if len(model.quad4): #model.quad4.quality() #if len(model.cquad8): #model.cquad8.quality() #if len(model.cquad): #model.cquad.quality() nids_list = [] # type: List[int] unused_ieid = 0 unused_cell_offset = 0 eids_array = np.zeros(nelements, dtype=idtype) cell_types_array = np.zeros(nelements, dtype=idtype) cell_offsets_array = np.zeros(nelements, dtype=idtype) results = { 'pid': pids_array, 'eid': eids_array, 'nnodes': nnodes_array, 'dim': dim_array, } cell_type_point = vtk.vtkVertex().GetCellType() cell_type_line = 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 = vtk.vtkPyramid().GetCellType() cell_type_pyram13 = vtk.vtkQuadraticPyramid().GetCellType() cell_type_hexa8 = 12 cell_type_hexa20 = 25 cell_type_penta6 = 13 cell_type_penta15 = 26 unused_all_eids = model.elements2.eids #print('type(eids) =', type(all_eids)) # list #print('all_eids =', all_eids) #ncelas1 = len(model.celas1) #ncelas2 = len(model.celas2) #ncelas3 = len(model.celas3) #ncelas4 = len(model.celas4) #ncdamp1 = len(model.cdamp1) #ncdamp2 = len(model.cdamp2) #ncdamp3 = len(model.cdamp3) #ncdamp4 = len(model.cdamp4) #ncdamp5 = len(model.cdamp5) #nconrod = len(model.conrod) #ncrod = len(model.crod) #nctube = len(model.ctube) #ncbar = len(model.cbar) #ncbeam = len(model.cbeam) #ncshear = len(model.cshear) #nctria3 = len(model.ctria3) #ncquad4 = len(model.cquad4) #nctria6 = len(model.ctria6) #ncquad8 = len(model.cquad8) #ncquad = len(model.cquad) #nctetra4 = len(model.ctetra4) #ncpenta6 = len(model.cpenta6) #nchexa8 = len(model.chexa8) #ncpyram5 = len(model.cpyram5) #nsolids = nctetra4 + ncpenta6 + nchexa8 ieid0 = 0 cell_offset0 = 0 nids_list = [] nodes = model.nodes ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.celas1, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.celas2, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.celas3, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.celas4, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cdamp1, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cdamp2, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cdamp3, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cdamp4, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cvisc, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.plotel, cell_type_line, nnodesi=2, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill_spring( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cbush, cell_type_line, cell_type_point) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.conrod, cell_type_line, nnodesi=2, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.crod, cell_type_line, nnodesi=2, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.ctube, cell_type_line, nnodesi=2, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cbar, cell_type_line, nnodesi=2, dimi=1) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cbeam, cell_type_line, nnodesi=2, dimi=1) #model.cbend ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cshear, cell_type_quad4, nnodesi=4, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.ctria3, cell_type_tri3, nnodesi=3, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cquad4, cell_type_quad4, nnodesi=4, dimi=2) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.ctria6, cell_type_tri6, nnodesi=6, dimi=2, allow0=True, cell_type_allow=cell_type_tri3) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cquad8, cell_type_quad8, nnodesi=8, dimi=2, allow0=True, cell_type_allow=cell_type_quad8) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cquad, cell_type_quad8, nnodesi=8, dimi=2, allow0=True, cell_type_allow=cell_type_quad8) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.ctriar, cell_type_tri6, nnodesi=6, dimi=2, allow0=True, cell_type_allow=cell_type_tri3) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cquadr, cell_type_tri6, nnodesi=6, dimi=2, allow0=True, cell_type_allow=cell_type_quad4) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.ctetra4, cell_type_tetra4, nnodesi=4, dimi=3) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cpenta6, cell_type_penta6, nnodesi=8, dimi=3) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.chexa8, cell_type_hexa8, nnodesi=8, dimi=3) ieid0, cell_offset0 = map_elements_vectorized_fill(log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cpyram5, cell_type_pyram5, nnodesi=8, dimi=3) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.ctetra10, cell_type_tetra10, nnodesi=4, dimi=3, allow0=True, cell_type_allow=cell_type_tetra4) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cpenta15, cell_type_penta15, nnodesi=8, dimi=3, allow0=True, cell_type_allow=cell_type_penta6) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.chexa20, cell_type_hexa20, nnodesi=8, dimi=3, allow0=True, cell_type_allow=cell_type_hexa8) ieid0, cell_offset0 = map_elements_vectorized_fill( log, ieid0, cell_offset0, nodes, nids_list, eids_array, pids_array, nnodes_array, dim_array, cell_types_array, cell_offsets_array, model.cpyram13, cell_type_pyram13, nnodesi=8, dimi=3, allow0=True, cell_type_allow=cell_type_pyram5) # model.chbdyg # model.chbdye # model.chbdyp return cell_types_array, cell_offsets_array, nids_list, eids_array, results
pyraScalars = vtk.vtkFloatArray() pyraScalars.SetNumberOfTuples(13) pyraScalars.InsertValue(0, 1.0) pyraScalars.InsertValue(1, 1.0) pyraScalars.InsertValue(2, 1.0) pyraScalars.InsertValue(3, 1.0) pyraScalars.InsertValue(4, 1.0) pyraScalars.InsertValue(5, 1.0) pyraScalars.InsertValue(6, 1.0) pyraScalars.InsertValue(7, 1.0) pyraScalars.InsertValue(8, 0.0) pyraScalars.InsertValue(9, 0.0) pyraScalars.InsertValue(10, 0.0) pyraScalars.InsertValue(11, 0.0) pyraScalars.InsertValue(12, 0.0) aPyramid = vtk.vtkQuadraticPyramid() aPyramid.GetPointIds().SetId(0, 0) aPyramid.GetPointIds().SetId(1, 1) aPyramid.GetPointIds().SetId(2, 2) aPyramid.GetPointIds().SetId(3, 3) aPyramid.GetPointIds().SetId(4, 4) aPyramid.GetPointIds().SetId(5, 5) aPyramid.GetPointIds().SetId(6, 6) aPyramid.GetPointIds().SetId(7, 7) aPyramid.GetPointIds().SetId(8, 8) aPyramid.GetPointIds().SetId(9, 9) aPyramid.GetPointIds().SetId(10, 10) aPyramid.GetPointIds().SetId(11, 11) aPyramid.GetPointIds().SetId(12, 12) aPyramidGrid = vtk.vtkUnstructuredGrid() aPyramidGrid.Allocate(1, 1)
def main(): titles = list() textMappers = list() textActors = list() uGrids = list() mappers = list() actors = list() renderers = list() uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticEdge())) titles.append("VTK_QUADRATIC_EDGE (= 21)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticTriangle())) titles.append("VTK_QUADRATIC_TRIANGLE (= 22)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticQuad())) titles.append("VTK_QUADRATIC_QUAD (= 23)") uGrids.append(MakeQuadraticPolygon()) titles.append("VTK_QUADRATIC_POLYGON (= 36)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticTetra())) titles.append("VTK_QUADRATIC_TETRA (= 24)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticHexahedron())) titles.append("VTK_QUADRATIC_HEXAHEDRON (= 25)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticWedge())) titles.append("VTK_QUADRATIC_WEDGE (= 26)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticPyramid())) titles.append("VTK_QUADRATIC_PYRAMID (= 27)") uGrids.append(MakeUnstructuredGrid(vtk.vtkBiQuadraticQuad())) titles.append("VTK_BIQUADRATIC_QUAD (= 28)") uGrids.append(MakeUnstructuredGrid(vtk.vtkTriQuadraticHexahedron())) titles.append("VTK_TRIQUADRATIC_HEXAHEDRON (= 29)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticLinearQuad())) titles.append("VTK_QUADRATIC_LINEAR_QUAD (= 30)") uGrids.append(MakeUnstructuredGrid(vtk.vtkQuadraticLinearWedge())) titles.append("VTK_QUADRATIC_LINEAR_WEDGE (= 31)") uGrids.append(MakeUnstructuredGrid(vtk.vtkBiQuadraticQuadraticWedge())) titles.append("VTK_BIQUADRATIC_QUADRATIC_WEDGE (= 32)") uGrids.append(MakeUnstructuredGrid( vtk.vtkBiQuadraticQuadraticHexahedron())) titles.append("VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON (= 33)") uGrids.append(MakeUnstructuredGrid(vtk.vtkBiQuadraticTriangle())) titles.append("VTK_BIQUADRATIC_TRIANGLE (= 34)") uGrids.append(MakeUnstructuredGrid(vtk.vtkCubicLine())) titles.append("VTK_CUBIC_LINE (= 35)") colors = vtk.vtkNamedColors() renWin = vtk.vtkRenderWindow() renWin.SetSize(600, 600) renWin.SetWindowName("Isoparametric Cell") iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) # Create one sphere for all sphere = vtk.vtkSphereSource() sphere.SetPhiResolution(21) sphere.SetThetaResolution(21) sphere.SetRadius(.08) # Create one text property for all textProperty = vtk.vtkTextProperty() textProperty.SetFontSize(10) textProperty.SetJustificationToCentered() # Create and link the mappers actors and renderers together. for i in range(0, len(uGrids)): print("Creating:", titles[i]) textMappers.append(vtk.vtkTextMapper()) textActors.append(vtk.vtkActor2D()) textMappers[i].GetTextProperty().SetFontSize(10) textMappers[i].GetTextProperty().ShadowOn() mappers.append(vtk.vtkDataSetMapper()) actors.append(vtk.vtkActor()) renderers.append(vtk.vtkRenderer()) mappers[i].SetInputData(uGrids[i]) actors[i].SetMapper(mappers[i]) actors[i].GetProperty().SetColor(colors.GetColor3d("Tomato")) actors[i].GetProperty().EdgeVisibilityOn() actors[i].GetProperty().SetLineWidth(3) actors[i].GetProperty().SetOpacity(.5) renderers[i].AddViewProp(actors[i]) textMappers[i].SetInput(titles[i]) textActors[i].SetMapper(textMappers[i]) textActors[i].SetPosition(50, 10) renderers[i].AddViewProp(textActors[i]) # Label the points labelMapper = vtk.vtkLabeledDataMapper() labelMapper.SetInputData(uGrids[i]) labelActor = vtk.vtkActor2D() labelActor.SetMapper(labelMapper) renderers[i].AddViewProp(labelActor) # Glyph the points pointMapper = vtk.vtkGlyph3DMapper() pointMapper.SetInputData(uGrids[i]) pointMapper.SetSourceConnection(sphere.GetOutputPort()) pointMapper.ScalingOff() pointMapper.ScalarVisibilityOff() pointActor = vtk.vtkActor() pointActor.SetMapper(pointMapper) pointActor.GetProperty().SetDiffuseColor(colors.GetColor3d("Banana")) pointActor.GetProperty().SetSpecular(.6) pointActor.GetProperty().SetSpecularColor(1.0, 1.0, 1.0) pointActor.GetProperty().SetSpecularPower(100) renderers[i].AddViewProp(pointActor) renWin.AddRenderer(renderers[i]) # Setup the viewports xGridDimensions = 4 yGridDimensions = 4 rendererSize = 240 renWin.SetSize(rendererSize * xGridDimensions, rendererSize * yGridDimensions) for row in range(0, yGridDimensions): for col in range(0, xGridDimensions): index = row * xGridDimensions + col # (xmin, ymin, xmax, ymax) viewport = [ float(col) / xGridDimensions, float(yGridDimensions - (row + 1)) / yGridDimensions, float(col + 1) / xGridDimensions, float(yGridDimensions - row) / yGridDimensions ] if index > (len(actors) - 1): # Add a renderer even if there is no actor. # This makes the render window background all the same color. ren = vtk.vtkRenderer() ren.SetBackground(colors.GetColor3d("SlateGray")) ren.SetViewport(viewport) renWin.AddRenderer(ren) continue renderers[index].SetViewport(viewport) renderers[index].SetBackground(colors.GetColor3d("SlateGray")) renderers[index].ResetCamera() renderers[index].GetActiveCamera().Azimuth(30) renderers[index].GetActiveCamera().Elevation(-30) renderers[index].ResetCameraClippingRange() iRen.Initialize() renWin.Render() iRen.Start()