# Examples from pyvista.UnstructuredGrid.cell_connectivity
# ========================================================

# 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]

# Assign a new array to change it.
connectivity = hex_beam.cell_connectivity.copy()
connectivity[0] = 1
hex_beam.cell_connectivity = connectivity
hex_beam.cell_connectivity[:8]

# 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

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

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code
