def get_domain_with_node_ids(mesh_vtu, domain_id_list): # -- add copy of element point ids to mesh pointIdFilter = vtk.vtkIdFilter() pointIdFilter.SetInputData(mesh_vtu) pointIdFilter.SetPointIds(True) pointIdFilter.SetCellIds(False) pointIdFilter.SetIdsArrayName("originalPointIDs") pointIdFilter.Update() mesh = pointIdFilter.GetUnstructuredGridOutput() # -- NUMPY - VTK mesh_wrapped = dsa.WrapDataObject(mesh) # -- extract element block ids material_array_name = "ElementBlockIds" element_block_id_array = mesh_wrapped.CellData[material_array_name] # -- create empty array for selection element_selection_array_name = "ElementSelection" element_selection_array = np.zeros(algs.shape(element_block_id_array)[0]) # -- assign selection id = 1 for elements in domain_id_list for domain_id in domain_id_list: element_selection_array[element_block_id_array == domain_id] = 1 # -- add selection array to mesh mesh_wrapped.CellData.append(element_selection_array, element_selection_array_name) # -- extract parts of mesh that have been selected selector = vtk.vtkThreshold() selector.SetInputData(mesh) selector.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, element_selection_array_name) selector.ThresholdBetween(1, 1) selector.Update() subgrid = selector.GetOutput() return subgrid
def get_node_ids_from_domain_surface(mesh_vtu, domain_id_list): subgrid = get_domain_with_node_ids(mesh_vtu, domain_id_list) # -- extract surface surfaceFilter = vtk.vtkDataSetSurfaceFilter() surfaceFilter.SetInputData(subgrid) surfaceFilter.Update() surface = surfaceFilter.GetOutput() # -- extract node ids on surface id_mapping_surface_to_orig = {} id_mapping_orig_to_surface = {} if surface.GetNumberOfPoints() > 0: surface_wrapped = dsa.WrapDataObject(surface) extracted_point_ids_orig = surface_wrapped.PointData[ 'originalPointIDs'] extracted_point_ids_surface = range( algs.shape(extracted_point_ids_orig)[0]) id_mapping_surface_to_orig = dict( zip(extracted_point_ids_surface, extracted_point_ids_orig)) id_mapping_orig_to_surface = dict( zip(extracted_point_ids_orig, extracted_point_ids_surface)) else: print("No selection") # return id_mapping_surface_to_orig, id_mapping_orig_to_surface return list(extracted_point_ids_orig)
sphere = dsa.CompositeDataSet(g2.GetOutput()) vn = algs.vertex_normal(sphere) compare(algs.mag(vn) - 1, 1E-6) sn = algs.surface_normal(sphere) compare(algs.mag(sn) - 1, 1E-6) dot = algs.dot(vn, vn) assert dot.DataSet is sphere compare(dot - 1, 1E-6) assert algs.all(algs.cross(vn, vn) == [0, 0, 0]) fd = sphere.FieldData['field array'] assert algs.all(fd == 5) assert algs.shape(fd) == (22,) assert vn.DataSet is sphere # -------------------------------------- na = dsa.NoneArray # Test operators assert (1 + na - 1 - randomVec) is na # Test slicing and indexing assert na[:, 0] is na assert algs.where(na[:, 0] > 0) is na assert (na > 0) is na
sphere = dsa.CompositeDataSet(g2.GetOutput()) vn = algs.vertex_normal(sphere) assert algs.all(algs.mag(vn) - 1 < 1E-6) sn = algs.surface_normal(sphere) assert algs.all(algs.mag(sn) - 1 < 1E-6) dot = algs.dot(vn, vn) assert dot.DataSet is sphere assert algs.all(dot == 1) assert algs.all(algs.cross(vn, vn) == [0, 0, 0]) fd = sphere.FieldData['field array'] assert algs.all(fd == 5) assert algs.shape(fd) == (22,) assert vn.DataSet is sphere # -------------------------------------- na = dsa.NoneArray # Test operators assert (1 + na - 1 - randomVec) is na # Test slicing and indexing assert na[:, 0] is na assert algs.where(na[:, 0] > 0) is na assert (na > 0) is na