pyvista.ExplicitStructuredGrid.neighbors#

ExplicitStructuredGrid.neighbors(
ind: int | VectorLike[int],
rel: str = 'connectivity',
) list[int][source]#

Return the indices of neighboring cells.

Parameters:
indint | VectorLike[int]

Cell IDs.

relstr, default: “connectivity”

Defines the neighborhood relationship. If 'topological', returns the (i-1, j, k), (i+1, j, k), (i, j-1, k), (i, j+1, k), (i, j, k-1) and (i, j, k+1) cells. If 'connectivity' (default), returns only the topological neighbors considering faces connectivity. If 'geometric', returns the cells in the (i-1, j), (i+1, j), (i,j-1) and (i, j+1) vertical cell groups whose faces intersect.

Returns:
list[int]

Indices of neighboring cells.

Examples

>>> import pyvista as pv
>>> from pyvista import examples
>>> grid = examples.load_explicit_structured()
>>> cell = grid.extract_cells(31)
>>> ind = grid.neighbors(31)
>>> neighbors = grid.extract_cells(ind)
>>> plotter = pv.Plotter()
>>> _ = plotter.add_axes()
>>> _ = plotter.add_mesh(cell, color='r', show_edges=True)
>>> _ = plotter.add_mesh(neighbors, color='w', show_edges=True)
>>> plotter.show()
../../../_images/pyvista-ExplicitStructuredGrid-neighbors-1_00_00.png