Skip to content

NodeMask

NodeMask

NodeMask(mesh: MeshIndex, ids: ndarray)

Bases: _BaseMask

A mask of node IDs with chainable spatial and predicate-based filters.

All methods return a new NodeMask instance, ensuring immutability at the API level.

Example
import numpy as np
from femora.components.mask.mask_base import MeshIndex, NodeMask

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([0]),
    element_connectivity=[np.array([0, 1, 2])],
    element_centroids=np.array([[0.33, 0.33, 0.0]]),
    element_types=np.array(["TRIANGLE"]),
    material_tags=np.array([1]),
    section_tags=np.array([1]),
    region_tags=np.array([0]),
    core_ids=np.array([0]),
    element_id_to_index={0: 0}
)
all_nodes = NodeMask(mesh_index, mesh_index.node_ids)
filtered_nodes = all_nodes.by_bbox(0.5, 1.5, -0.5, 0.5, -0.5, 0.5)
print(filtered_nodes.to_list())
# Output: [1]

Methods:

by_ids

by_ids(ids: Sequence[int]) -> 'NodeMask'

Intersects the current node mask with specific node IDs.

Parameters:

Name Type Description Default
ids Sequence[int]

A sequence of node IDs to retain.

required

Returns:

Name Type Description
NodeMask 'NodeMask'

A new mask containing the intersection of the current mask's IDs and the provided ids.

Example
# assuming `mask` is a NodeMask holding [0, 1, 2]
filtered_mask = mask.by_ids([1, 3])
print(filtered_mask.to_list())
# Output: [1]

by_bbox

by_bbox(xmin: float, xmax: float, ymin: float, ymax: float, zmin: float, zmax: float) -> 'NodeMask'

Filters nodes 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

Returns:

Name Type Description
NodeMask 'NodeMask'

A new mask containing only nodes whose coordinates are within the specified bounding box.

Example
# assuming `all_nodes` is a NodeMask
filtered_nodes = all_nodes.by_bbox(0.5, 1.5, -0.5, 0.5, -0.5, 0.5)
print(filtered_nodes.to_list())
# Output: [1]

near_point

near_point(point: Tuple[float, float, float], radius: float) -> 'NodeMask'

Filters nodes within a specified distance from a given point.

Parameters:

Name Type Description Default
point Tuple[float, float, float]

The reference point (x, y, z) from which to measure the distance.

required
radius float

The radial distance threshold. Nodes within this radius will be included.

required

Returns:

Name Type Description
NodeMask 'NodeMask'

A new mask containing only nodes that are within the specified radial distance from the point.

Example
# Get nodes within radial distance of 0.5 from origin
filtered_nodes = all_nodes.near_point((0.0, 0.0, 0.0), 0.5)
print(filtered_nodes.to_list())
# Output: [0]

along_line

along_line(point1: Tuple[float, float, float], point2: Tuple[float, float, float], radius: float) -> 'NodeMask'

Filters nodes within a specified distance from a line segment.

The line segment is defined by two endpoints. Nodes within a cylindrical region around this segment will be included.

Parameters:

Name Type Description Default
point1 Tuple[float, float, float]

The first endpoint of the line segment (x, y, z).

required
point2 Tuple[float, float, float]

The second endpoint of the line segment (x, y, z).

required
radius float

The radial distance threshold from the line segment.

required

Returns:

Name Type Description
NodeMask 'NodeMask'

A new mask containing nodes that are within the cylindrical region around the line segment.

Example
# Get nodes along line segment from (0,0,0) to (1,0,0) within radius 0.2
filtered_nodes = all_nodes.along_line((0.0, 0.0, 0.0), (1.0, 0.0, 0.0), 0.2)
print(filtered_nodes.to_list())
# Output: [0, 1, 2]

to_tags

to_tags(start_tag: int | None = None) -> List[int]

Converts selected node IDs to OpenSees node tags.

This method applies an offset to the internal zero-based node IDs to generate application-specific node tags, typically for OpenSees.

Parameters:

Name Type Description Default
start_tag int | None

Optional. The starting node tag. If None, it attempts to retrieve the starting node tag from a Model instance; otherwise, it defaults to 1.

None

Returns:

Type Description
List[int]

List[int]: A list of OpenSees-compatible node tags for the selected nodes.

Example
# Convert node IDs to tag integers
print(selected_nodes.to_tags(start_tag=100))
# Output: [100, 101]