pysdic.Mesh.keep_connectivity#

Mesh.keep_connectivity(element_indices, force_inplace=False)[source]#

Keep only the specified elements in the mesh by specifying their indices in the connectivity array.

This method is an extension of the connectivity.keep_elements method that allows keeping only specified elements in the mesh while ensuring that the connectivity structure is maintained and validated. This method will ensure that the specified element indices are compatible with the existing mesh structure and will update the mesh’s connectivity accordingly.

Note

The new connectivity will be stored in a new connectivity object (Copy of the original connectivity object with only the kept elements). The properties of the kept elements will be updated to keep only the properties of the kept elements and stored in the new connectivity object.

See also

Parameters:
  • element_indices (ArrayLike) – An array of shape \((R,)\) containing the indices of the elements to keep in the mesh, where \(R\) is the number of elements to keep.

  • force_inplace (bool, optional) – If True, the connectivity will be updated in place, modifying the original connectivity object. If False, a new connectivity object will be created to store the updated connectivity, leaving the original connectivity object unchanged. By default False.

Raises:
  • TypeError – If element_indices is not an array-like object or is not an integer array. If force_inplace is not a boolean.

  • ValueError – If element_indices does not have the correct shape or contains invalid indices.

Return type:

None

Examples

Create a simple Mesh instance.

1import numpy as np
2from pysdic import Mesh, PointCloud
3
4points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
5connectivity = np.array([[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]])
6mesh3d = Mesh(points, connectivity, element_type="triangle_3")

Keep only the first and third elements in the mesh.

1element_indices = np.array([0, 2])
2mesh3d.keep_connectivity(element_indices)
3
4print(mesh3d.connectivity)
5# Output: Connectivity with 2 elements [[0, 1, 2], [0, 2, 3]]