ElementMask
ElementMask
Bases: _BaseMask
A mask of element IDs with chainable attribute and spatial filters.
All methods return a new ElementMask instance, ensuring immutability at the API level.
Example
import numpy as np
from femora.components.mask.mask_base import MeshIndex, ElementMask
mesh_index = MeshIndex(
node_ids=np.array([0, 1, 2, 3]),
node_coords=np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [2.0, 2.0, 2.0]]),
node_ndf=np.array([3, 3, 3, 3]),
node_core_map=[[0], [0], [0], [0]],
element_ids=np.array([10, 11, 12]),
element_connectivity=[np.array([0, 1]), np.array([1, 2]), np.array([2, 3])],
element_centroids=np.array([[0.5, 0.0, 0.0], [0.5, 0.5, 0.0], [1.0, 1.5, 1.0]]),
element_types=np.array(["BEAM", "BEAM", "TRUSS"]),
material_tags=np.array([1, 2, 1]),
section_tags=np.array([1, 1, 2]),
region_tags=np.array([0, 1, 0]),
core_ids=np.array([0, 0, 1]),
element_id_to_index={10: 0, 11: 1, 12: 2}
)
all_elements = ElementMask(mesh_index, mesh_index.element_ids)
filtered_elements = all_elements.by_material(1)
print(filtered_elements.to_list())
# Output: [10, 12]
Methods:
by_ids
Intersects the current element mask with specific element IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[int]
|
A sequence of element IDs to retain. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing the intersection of the current
mask's IDs and the provided |
by_type
Filters elements by their type name (case-insensitive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The element type name to match. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing only elements whose type name
matches the provided |
by_material
Filters elements by their associated material tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
int
|
The integer material tag value to match. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing only elements that have the
specified material |
by_section
Filters elements by their associated section tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
int
|
The integer section tag value to match. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing only elements that have the
specified section |
by_region
Filters elements by their associated region tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
int
|
The integer region tag value to match. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing only elements that are associated
with the specified region |
by_core
Filters elements by their partition or core ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core
|
int
|
The integer core/partition identifier to match. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing only elements that belong to the specified core. |
by_bbox
by_bbox(xmin: float, xmax: float, ymin: float, ymax: float, zmin: float, zmax: float, *, use_centroid: bool = True) -> 'ElementMask'
Filters elements inside an axis-aligned bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
float
|
The minimum x-coordinate of the bounding box. |
required |
xmax
|
float
|
The maximum x-coordinate of the bounding box. |
required |
ymin
|
float
|
The minimum y-coordinate of the bounding box. |
required |
ymax
|
float
|
The maximum y-coordinate of the bounding box. |
required |
zmin
|
float
|
The minimum z-coordinate of the bounding box. |
required |
zmax
|
float
|
The maximum z-coordinate of the bounding box. |
required |
use_centroid
|
bool
|
If True (default), elements are filtered based on whether their centroid lies within the bounding box. If False, an element is included if any of its nodes lies within the bounding box. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing elements that are located within the specified bounding box. |
by_predicate
Filters elements using a custom predicate function.
The predicate function will be called for each element, and only elements for which the function returns True will be included in the new mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[int, ndarray, str, int, int, int], bool]
|
A callable that accepts six arguments:
- |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ElementMask |
'ElementMask'
|
A new mask containing only elements that pass the predicate. |
to_nodes
Converts to a node mask containing all nodes in the mesh.
This method currently returns all nodes found in the underlying
mesh, regardless of which elements are selected in the current
ElementMask. This behavior is due to an internal implementation
detail where it iterates over all mesh elements' connectivity.
Returns:
| Name | Type | Description |
|---|---|---|
NodeMask |
'NodeMask'
|
A new |
to_tags
Converts selected element IDs to OpenSees element tags.
This method offsets the existing explicit element IDs (which are already
considered tags within Femora) by a start_tag value, primarily for
compatibility with external tools like OpenSees that might use a
different tagging scheme or require a specific offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_tag
|
int | None
|
Optional. The value to add to each selected element ID.
If |
None
|
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: A list of OpenSees-compatible element tags for the
selected elements. These are the original element IDs plus the
|