def test_cells_dict_utils(): # No pyvista object with pytest.raises(ValueError): cells.get_mixed_cells(None) with pytest.raises(ValueError): cells.get_mixed_cells(np.zeros(shape=[3, 3])) cells_arr = np.array([3, 0, 1, 2, 3, 3, 4, 5]) cells_types = np.array([vtk.VTK_TRIANGLE] * 2) assert np.all( cells.generate_cell_offsets(cells_arr, cells_types) == cells.generate_cell_offsets(cells_arr, cells_types)) # Non-integer type with pytest.raises(ValueError): cells.generate_cell_offsets(cells_arr, cells_types.astype(np.float32)) with pytest.raises(ValueError): cells.generate_cell_offsets_loop(cells_arr, cells_types.astype(np.float32)) # Inconsistency of cell array lengths with pytest.raises(ValueError): cells.generate_cell_offsets(np.array(cells_arr.tolist() + [6]), cells_types) with pytest.raises(ValueError): cells.generate_cell_offsets_loop(np.array(cells_arr.tolist() + [6]), cells_types) with pytest.raises(ValueError): cells.generate_cell_offsets( cells_arr, np.array(cells_types.tolist() + [vtk.VTK_TRIANGLE])) with pytest.raises(ValueError): cells.generate_cell_offsets_loop( cells_arr, np.array(cells_types.tolist() + [vtk.VTK_TRIANGLE])) # Unknown cell type np.all( cells.generate_cell_offsets(cells_arr, cells_types) == cells.generate_cell_offsets(cells_arr, np.array([255, 255])))
def cells_dict(self): """Return a dictionary that contains all cells mapped from cell types. This function returns a np.ndarray for each cell type in an ordered fashion. Note that this function only works with element types of fixed sizes Returns ------- cells_dict : dict A dictionary mapping containing all cells of this unstructured grid. Structure: vtk_enum_type (int) -> cells (np.ndarray) """ return get_mixed_cells(self)