pysdic.Mesh.filter_connectivity#

Mesh.filter_connectivity(mask, force_inplace=False)[source]#

Filter the connectivity of the mesh by keeping only the elements corresponding to the True values in the mask.

This metod is an extension of the connectivity.filter_elements method that allows filtering the connectivity of the mesh while ensuring that the connectivity structure is maintained and validated. This method will ensure that the mask is 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 filtered elements). The properties of the filtered elements will be updated to keep only the properties of the kept elements and stored in the new connectivity object.

See also

Parameters:
  • mask (ArrayLike) – A boolean array of shape \((N_e,)\) where \(N_e\) is the number of elements in the mesh, indicating which elements to keep (True) or remove (False) from the mesh.

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

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

  • ValueError – If mask does not have the correct shape or is not a boolean array.

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")

Filter the connectivity of the mesh to keep only the first and third elements.

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