pysdic.Connectivity.filter_elements#

Connectivity.filter_elements(mask, inplace=False)[source]#

Filter elements in the connectivity based on a boolean mask.

This method returns a new Connectivity object containing only the elements where the mask is True. The mask should be a 1D boolean NumPy array with the same length as the number of elements in the connectivity. All the properties associated with the elements are also filtered accordingly.

See also

Parameters:
  • mask (ArrayLike) – A 1D boolean NumPy array of shape \((N_e,)\) where \(N_e\) is the number of elements in the connectivity. Each element should be True to keep the corresponding element, or False to remove it.

  • inplace (bool, optional) – If True, modifies the current connectivity in place and returns itself. If False, returns a new Connectivity instance (default is False).

Returns:

A new Connectivity object containing only the filtered elements or the modified current instance if inplace is True.

Return type:

Connectivity

Raises:

ValueError – If the input mask is not a 1D boolean array of the correct length.

Examples

Create a Connectivity from a random NumPy array.

1import numpy as np
2from pysdic import Connectivity
3
4# Create a random connectivity with 100 elements
5random_elements = np.random.randint(0, 100, size=(100, 3))  # shape (100, 3)
6connectivity = Connectivity.from_array(random_elements)

Filtering elements with any vertex index greater than 50.

1# Create a boolean mask for elements with any vertex index greater than 50
2mask = (connectivity.elements > 50).any(axis=1)
3
4# Filter the connectivity using the mask
5filtered_connectivity = connectivity.filter_elements(mask)
6print(filtered_connectivity.elements)
7# Output: A NumPy array containing only the elements with any vertex index greater than 50