UnstructuredGrid.cell_connectivity

UnstructuredGrid.cell_connectivity#

property UnstructuredGrid.cell_connectivity: NumpyArray[int][source]#

Return the connectivity array.

The connectivity array stores the point ids of every cell, one cell after another and without any padding. It is effectively cells without the padding. Use cell_offsets to determine where each cell begins and ends.

Changed in version 0.49: The property is now settable, and modifying the returned array in place is deprecated.

Warning

Modifying the returned array in place is deprecated. The array becomes read-only in v0.52, matching pyvista.PolyData.face_connectivity and pyvista.CellArray.cell_connectivity. Assign a new array to this property instead.

No runtime warning is emitted, since nothing can hook ndarray.__setitem__. This is a documentation-only deprecation, so do not expect a warning to tell you when the array is written to.

Returns:
numpy.ndarray

Point ids that define the cells.

Notes#

The returned array is still writeable, but modifying it in place is deprecated and it becomes read-only in v0.52. To change the connectivity, assign a new array to this property. The input is copied, so the grid never aliases an array that may be modified later. The new connectivity must remain consistent with the current cell_offsets; to replace both at once, assign to cells or build a new grid.

Unlike pyvista.PolyData.faces, cells does not accept a pyvista.CellArray, so a grid cannot wrap connectivity that the caller keeps a handle to. Every route here copies.

Examples#

Download Python source code | Download Jupyter notebook

Return the cell connectivity for the first two cells.

>>> import pyvista as pv
>>> from pyvista import examples
>>> hex_beam = pv.read(examples.hexbeamfile)
>>> hex_beam.cell_connectivity[:16]
array([ 0,  2,  8,  7, 27, 36, 90, 81,  2,  1,  4,  8, 36, 18, 54, 90]...)

Assign a new array to change it.

To change the number of cells, or the number of points in a cell of fixed size, build a new grid so that celltypes can change with it.

>>> grid = pv.UnstructuredGrid(
...     [8, 0, 2, 8, 7, 27, 36, 90, 81],
...     [pv.CellType.HEXAHEDRON],
...     hex_beam.points,
... )
>>> grid.n_cells
1

Note that arrays derived from the old topology are not recomputed by either approach and should be removed or regenerated.

See Also#

cell_offsets

Index into this array at which each cell begins.

cells

Cells in the legacy padded format.

pyvista.DataSet.get_cell
pyvista.PolyData.face_connectivity

Equivalent property for the faces of a polygonal mesh.

polyhedron_face_connectivity

Point ids for the faces of polyhedral cells, which VTK stores separately from the cell connectivity.