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_elementsmethod 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
remove_connectivity()to remove specified elements from the mesh.keep_connectivity()to keep only specified elements in the mesh.Connectivityfor more information on the connectivity structure and element types.
- 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) – IfTrue, the connectivity will be filtered in place, modifying the original connectivity object. IfFalse, a new connectivity object will be created to store the filtered connectivity, leaving the original connectivity object unchanged. By defaultFalse.
- Raises:
TypeError – If
maskis not an array-like object or is not a boolean array. Ifforce_inplaceis not a boolean.ValueError – If
maskdoes not have the correct shape or is not a boolean array.
- Return type:
None
Examples
Create a simple
Meshinstance.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]]