dolfinx.geometry
Methods for geometric searches and operations.
Functions
|
Create a bounding box tree for use in collision detection. |
|
Compute closest mesh entity to a point. |
|
From a mesh, find which cells collide with a set of points. |
|
Compute collisions between points and leaf bounding boxes. |
|
Compute all collisions between two bounding box trees. |
|
Compute the distance between two convex bodies p and q, each defined by a set of points. |
|
Create a bounding box tree for the midpoints of a subset of entities. |
|
Build point ownership data for a mesh-points pair. |
|
Compute the squared distance between a point and a mesh entity. |
Classes
|
Bounding box trees used in collision detection. |
|
Convenience class for storing data related to the ownership of points. |
- class dolfinx.geometry.BoundingBoxTree(tree)[source]
Bases:
object
Bounding box trees used in collision detection.
Wrap a C++ BoundingBoxTree.
Note
- This initializer should not be used in user code. Use
bb_tree
.
- property bbox_coordinates: ndarray[tuple[int, ...], dtype[float32]] | ndarray[tuple[int, ...], dtype[float64]]
Coordinates of lower and upper corners of bounding boxes.
Note
Rows 2*ibbox and 2*ibbox+1 correspond to the lower and upper corners of bounding box ibbox, respectively.
- create_global_tree(comm) BoundingBoxTree [source]
- get_bbox(i) ndarray[tuple[int, ...], dtype[floating]] [source]
Get lower and upper corners of the ith bounding box.
- Parameters:
i – Index of the box.
- Returns:
The ‘lower’ and ‘upper’ points of the bounding box. Shape is
(2, 3)
,
- property num_bboxes: int
Number of bounding boxes.
- class dolfinx.geometry.PointOwnershipData(ownership_data)[source]
Bases:
object
Convenience class for storing data related to the ownership of points.
Wrap a C++ PointOwnershipData.
- property dest_cells: ndarray[tuple[int, ...], dtype[int32]]
Cell indices (local to process) where each entry of
dest_points
is located.
- property dest_owner: ndarray[tuple[int, ...], dtype[int32]]
Ranks that sent
dest_points
to current process.
- property dest_points: ndarray[tuple[int, ...], dtype[floating]]
Points owned by current rank.
- property src_owner: ndarray[tuple[int, ...], dtype[int32]]
Ranks owning each point sent into ownership determination for current process.
- dolfinx.geometry.bb_tree(mesh: Mesh, dim: int, *, padding: float = 0.0, entities: npt.NDArray[np.int32] | None = None) BoundingBoxTree [source]
Create a bounding box tree for use in collision detection.
- Parameters:
mesh – The mesh.
dim – Dimension of the mesh entities to build bounding box for.
padding – Padding for each bounding box.
entities – List of entity indices (local to process). If not supplied, all owned and ghosted entities are used.
- Returns:
Bounding box tree.
- dolfinx.geometry.compute_closest_entity(tree: BoundingBoxTree, midpoint_tree: BoundingBoxTree, mesh: Mesh, points: npt.NDArray[np.floating]) npt.NDArray[np.int32] [source]
Compute closest mesh entity to a point.
- Parameters:
tree – bounding box tree for the entities.
midpoint_tree – A bounding box tree with the midpoints of all the mesh entities. This is used to accelerate the search.
mesh – The mesh.
points – The points to check for collision,
shape=(num_points,3)
.
- Returns:
Mesh entity index for each point in
points
. Returns -1 for a point if the bounding box tree is empty.
- dolfinx.geometry.compute_colliding_cells(mesh: Mesh, candidates: AdjacencyList, x: npt.NDArray[np.floating]) AdjacencyList [source]
From a mesh, find which cells collide with a set of points.
- Parameters:
mesh – The mesh.
candidate_cells – Adjacency list of candidate colliding cells for the ith point in
x
.points – The points to check for collision
shape=(num_points, 3)
,
- Returns:
Adjacency list where the ith node is the list of entities that collide with the ith point.
- dolfinx.geometry.compute_collisions_points(tree: BoundingBoxTree, x: ndarray[tuple[int, ...], dtype[floating]]) AdjacencyList [source]
Compute collisions between points and leaf bounding boxes.
Bounding boxes can overlap, therefore points can collide with more than one box.
- Parameters:
tree – Bounding box tree.
x – Points (
shape=(num_points, 3)
).
- Returns:
For each point, the bounding box leaves that collide with the point.
- dolfinx.geometry.compute_collisions_trees(tree0: BoundingBoxTree, tree1: BoundingBoxTree) ndarray[tuple[int, ...], dtype[int32]] [source]
Compute all collisions between two bounding box trees.
- Parameters:
tree0 – First bounding box tree.
tree1 – Second bounding box tree.
- Returns:
List of pairs of intersecting box indices from each tree. Shape is
(num_collisions, 2)
.
- dolfinx.geometry.compute_distance_gjk(p: ndarray[tuple[int, ...], dtype[floating]], q: ndarray[tuple[int, ...], dtype[floating]]) ndarray[tuple[int, ...], dtype[floating]] [source]
Compute the distance between two convex bodies p and q, each defined by a set of points.
Uses the Gilbert-Johnson-Keerthi (GJK) distance algorithm.
- Parameters:
p – Body 1 list of points (
shape=(num_points, gdim)
).q – Body 2 list of points (
shape=(num_points, gdim)
).
- Returns:
Shortest vector between the two bodies.
- dolfinx.geometry.create_midpoint_tree(mesh: Mesh, dim: int, entities: npt.NDArray[np.int32]) BoundingBoxTree [source]
Create a bounding box tree for the midpoints of a subset of entities.
- Parameters:
mesh – The mesh.
dim – Topological dimension of the entities.
entities – Indices of mesh entities to include.
- Returns:
Bounding box tree for midpoints of cell entities.
- dolfinx.geometry.determine_point_ownership(mesh: Mesh, points: npt.NDArray[np.floating], padding: float, cells: npt.NDArray[np.int32] | None = None) PointOwnershipData [source]
Build point ownership data for a mesh-points pair.
First, potential collisions are found by computing intersections between the bounding boxes of the cells and the set of points. Then, actual containment pairs are determined using the GJK algorithm.
- Parameters:
mesh – The mesh
points – Points to check for collision,
shape=(num_points, gdim)
padding – Amount of absolute padding of bounding boxes of the mesh. Each bounding box of the mesh is padded with this amount, to increase the number of candidates, avoiding rounding errors in determining the owner of a point if the point is on the surface of a cell in the mesh.
cells – Cells to check for ownership If
None
then all cells are considered.
- Returns:
Point ownership data
Note
dest_owner
is sortedsrc_owner
is -1 if no colliding process is found- A large padding value will increase the run-time of the code
by orders of magnitude. General advice is to use a padding on the scale of the cell size.
- dolfinx.geometry.squared_distance(mesh: Mesh, dim: int, entities: npt.NDArray[np.int32], points: npt.NDArray[np.floating]) npt.NDArray[np.floating] [source]
Compute the squared distance between a point and a mesh entity.
The distance is computed between the ith input points and the ith input entity.
- Parameters:
mesh – Mesh containing the entities.
dim – Topological dimension of the mesh entities.
entities – Indices of the mesh entities (local to process).
points – Points to compute the shortest distance from (
shape=(num_points, 3)
).
- Returns:
Squared shortest distance from
points[i]
toentities[i]
.