Skip to content

Commit 15f647e

Browse files
committed
Non-defaulted padding in BoundingBoxTree python constructor
1 parent 9420238 commit 15f647e

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

python/dolfinx/geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def create_global_tree(self, comm) -> BoundingBoxTree:
103103
def bb_tree(
104104
mesh: Mesh,
105105
dim: int,
106-
entities: typing.Optional[npt.NDArray[np.int32]] = None,
107106
padding: float = 0.0,
107+
entities: typing.Optional[npt.NDArray[np.int32]] = None,
108108
) -> BoundingBoxTree:
109109
"""Create a bounding box tree for use in collision detection.
110110

python/test/unit/fem/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def e3(x):
9090
u3.interpolate(e3)
9191

9292
x0 = (mesh.geometry.x[0] + mesh.geometry.x[1]) / 2.0
93-
tree = bb_tree(mesh, mesh.geometry.dim)
93+
tree = bb_tree(mesh, mesh.geometry.dim, 0.0)
9494
cell_candidates = compute_collisions_points(tree, x0)
9595
cell = compute_colliding_cells(mesh, cell_candidates, x0).array
9696
assert len(cell) > 0

python/test/unit/fem/test_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def f_test2(x):
10251025
u1_exact.x.scatter_forward()
10261026

10271027
# Find the single cell in mesh1 which is overlapped by mesh2
1028-
tree1 = bb_tree(mesh1, mesh1.topology.dim)
1028+
tree1 = bb_tree(mesh1, mesh1.topology.dim, 0.0)
10291029
cells_overlapped1 = compute_collisions_points(
10301030
tree1, np.array([p0_mesh2, p0_mesh2, 0.0]) / 2
10311031
).array

python/test/unit/geometry/test_bounding_box_tree.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def rotation_matrix(axis, angle):
150150
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
151151
def test_empty_tree(dtype):
152152
mesh = create_unit_interval(MPI.COMM_WORLD, 16, dtype=dtype)
153-
bbtree = bb_tree(mesh, mesh.topology.dim, np.array([], dtype=dtype))
153+
bbtree = bb_tree(mesh, mesh.topology.dim, 0.0, np.array([], dtype=dtype))
154154
assert bbtree.num_bboxes == 0
155155

156156

@@ -167,7 +167,7 @@ def test_compute_collisions_point_1d(dtype):
167167

168168
# Compute collision
169169
tdim = mesh.topology.dim
170-
tree = bb_tree(mesh, tdim)
170+
tree = bb_tree(mesh, tdim, 0.0)
171171
entities = compute_collisions_points(tree, p)
172172
assert len(entities.array) == 1
173173

@@ -212,8 +212,8 @@ def locator_B(x):
212212
cells_B = np.sort(np.unique(np.hstack([v_to_c.links(vertex) for vertex in vertices_B])))
213213

214214
# Find colliding entities using bounding box trees
215-
tree_A = bb_tree(mesh_A, mesh_A.topology.dim)
216-
tree_B = bb_tree(mesh_B, mesh_B.topology.dim)
215+
tree_A = bb_tree(mesh_A, mesh_A.topology.dim, 0.0)
216+
tree_B = bb_tree(mesh_B, mesh_B.topology.dim, 0.0)
217217
entities = compute_collisions_trees(tree_A, tree_B)
218218
entities_A = np.sort(np.unique([q[0] for q in entities]))
219219
entities_B = np.sort(np.unique([q[1] for q in entities]))
@@ -229,8 +229,8 @@ def test_compute_collisions_tree_2d(point, dtype):
229229
mesh_B = create_unit_square(MPI.COMM_WORLD, 5, 5, dtype=dtype)
230230
bgeom = mesh_B.geometry.x
231231
bgeom += point
232-
tree_A = bb_tree(mesh_A, mesh_A.topology.dim)
233-
tree_B = bb_tree(mesh_B, mesh_B.topology.dim)
232+
tree_A = bb_tree(mesh_A, mesh_A.topology.dim, 0.0)
233+
tree_B = bb_tree(mesh_B, mesh_B.topology.dim, 0.0)
234234
entities = compute_collisions_trees(tree_A, tree_B)
235235

236236
entities_A = np.sort(np.unique([q[0] for q in entities]))
@@ -251,8 +251,8 @@ def test_compute_collisions_tree_3d(point, dtype):
251251
bgeom = mesh_B.geometry.x
252252
bgeom += point
253253

254-
tree_A = bb_tree(mesh_A, mesh_A.topology.dim)
255-
tree_B = bb_tree(mesh_B, mesh_B.topology.dim)
254+
tree_A = bb_tree(mesh_A, mesh_A.topology.dim, 0.0)
255+
tree_B = bb_tree(mesh_B, mesh_B.topology.dim, 0.0)
256256
entities = compute_collisions_trees(tree_A, tree_B)
257257
entities_A = np.sort(np.unique([q[0] for q in entities]))
258258
entities_B = np.sort(np.unique([q[1] for q in entities]))
@@ -269,7 +269,7 @@ def test_compute_closest_entity_1d(dim, dtype):
269269
N = 16
270270
points = np.array([[-ref_distance, 0, 0], [2 / N, 2 * ref_distance, 0]], dtype=dtype)
271271
mesh = create_unit_interval(MPI.COMM_WORLD, N, dtype=dtype)
272-
tree = bb_tree(mesh, dim)
272+
tree = bb_tree(mesh, dim, 0.0)
273273
num_entities_local = (
274274
mesh.topology.index_map(dim).size_local + mesh.topology.index_map(dim).num_ghosts
275275
)
@@ -303,7 +303,7 @@ def test_compute_closest_entity_2d(dim, dtype):
303303
points = np.array([-1.0, -0.01, 0.0], dtype=dtype)
304304
mesh = create_unit_square(MPI.COMM_WORLD, 15, 15, dtype=dtype)
305305
mesh.topology.create_entities(dim)
306-
tree = bb_tree(mesh, dim)
306+
tree = bb_tree(mesh, dim, 0.0)
307307
num_entities_local = (
308308
mesh.topology.index_map(dim).size_local + mesh.topology.index_map(dim).num_ghosts
309309
)
@@ -335,7 +335,7 @@ def test_compute_closest_entity_3d(dim, dtype):
335335
mesh = create_unit_cube(MPI.COMM_WORLD, 8, 8, 8, dtype=dtype)
336336
mesh.topology.create_entities(dim)
337337

338-
tree = bb_tree(mesh, dim)
338+
tree = bb_tree(mesh, dim, 0.0)
339339
num_entities_local = (
340340
mesh.topology.index_map(dim).size_local + mesh.topology.index_map(dim).num_ghosts
341341
)
@@ -368,7 +368,7 @@ def test_compute_closest_sub_entity(dim, dtype):
368368
mesh = create_unit_cube(MPI.COMM_WORLD, 8, 8, 8, dtype=dtype)
369369
mesh.topology.create_entities(dim)
370370
left_entities = locate_entities(mesh, dim, lambda x: x[0] <= xc)
371-
tree = bb_tree(mesh, dim, left_entities)
371+
tree = bb_tree(mesh, dim, 0.0, left_entities)
372372
midpoint_tree = create_midpoint_tree(mesh, dim, left_entities)
373373
closest_entities = compute_closest_entity(tree, midpoint_tree, mesh, points)
374374

@@ -396,7 +396,7 @@ def test_surface_bbtree(dtype):
396396
tdim = mesh.topology.dim
397397
f_to_c = mesh.topology.connectivity(tdim - 1, tdim)
398398
cells = np.array([f_to_c.links(f)[0] for f in sf], dtype=np.int32)
399-
bbtree = bb_tree(mesh, tdim, cells)
399+
bbtree = bb_tree(mesh, tdim, 0.0, cells)
400400

401401
# test collision (should not collide with any)
402402
p = np.array([0.5, 0.5, 0.5])
@@ -413,7 +413,7 @@ def test_sub_bbtree_codim1(dtype):
413413
top_facets = locate_entities_boundary(mesh, fdim, lambda x: np.isclose(x[2], 1))
414414
f_to_c = mesh.topology.connectivity(tdim - 1, tdim)
415415
cells = np.array([f_to_c.links(f)[0] for f in top_facets], dtype=np.int32)
416-
bbtree = bb_tree(mesh, tdim, cells)
416+
bbtree = bb_tree(mesh, tdim, 0.0, cells)
417417

418418
# Compute a BBtree for all processes
419419
process_bbtree = bbtree.create_global_tree(mesh.comm)
@@ -441,7 +441,7 @@ def test_serial_global_bb_tree(dtype, comm):
441441
# entity tree with a serial mesh
442442
x = np.array([[2.0, 2.0, 3.0], [0.3, 0.2, 0.1]], dtype=dtype)
443443

444-
tree = bb_tree(mesh, mesh.topology.dim)
444+
tree = bb_tree(mesh, mesh.topology.dim, 0.0)
445445
global_tree = tree.create_global_tree(mesh.comm)
446446

447447
tree_col = compute_collisions_points(tree, x)
@@ -465,12 +465,12 @@ def test_sub_bbtree_box(ct, N, dtype):
465465
facets = locate_entities_boundary(mesh, fdim, lambda x: np.isclose(x[1], 1.0))
466466
f_to_c = mesh.topology.connectivity(fdim, tdim)
467467
cells = np.int32(np.unique([f_to_c.links(f)[0] for f in facets]))
468-
bbtree = bb_tree(mesh, tdim, cells)
468+
bbtree = bb_tree(mesh, tdim, 0.0, cells)
469469
num_boxes = bbtree.num_bboxes
470470
if num_boxes > 0:
471471
bbox = bbtree.get_bbox(num_boxes - 1)
472472
assert np.isclose(bbox[0][1], (N - 1) / N)
473-
tree = bb_tree(mesh, tdim)
473+
tree = bb_tree(mesh, tdim, 0.0)
474474
assert num_boxes < tree.num_bboxes
475475

476476

@@ -489,13 +489,13 @@ def test_surface_bbtree_collision(dtype):
489489

490490
# Compute unique set of cells (some will be counted multiple times)
491491
cells = np.array(list(set([f_to_c.links(f)[0] for f in sf])), dtype=np.int32)
492-
bbtree1 = bb_tree(mesh1, tdim, cells)
492+
bbtree1 = bb_tree(mesh1, tdim, 0.0, cells)
493493

494494
mesh2.topology.create_connectivity(mesh2.topology.dim - 1, mesh2.topology.dim)
495495
sf = exterior_facet_indices(mesh2.topology)
496496
f_to_c = mesh2.topology.connectivity(tdim - 1, tdim)
497497
cells = np.array(list(set([f_to_c.links(f)[0] for f in sf])), dtype=np.int32)
498-
bbtree2 = bb_tree(mesh2, tdim, cells)
498+
bbtree2 = bb_tree(mesh2, tdim, 0.0, cells)
499499

500500
collisions = compute_collisions_trees(bbtree1, bbtree2)
501501
assert len(collisions) == 1
@@ -528,7 +528,7 @@ def test_determine_point_ownership(dim, affine, dtype):
528528
)
529529
cell_map = mesh.topology.index_map(tdim)
530530

531-
tree = bb_tree(mesh, mesh.topology.dim, np.arange(cell_map.size_local))
531+
tree = bb_tree(mesh, mesh.topology.dim, 0.0, np.arange(cell_map.size_local))
532532
num_global_cells = num_cells_side**tdim
533533
if affine:
534534
num_global_cells *= 2 * (3 ** (tdim - 2))

python/test/unit/geometry/test_gjk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_collision_2nd_order_triangle(dtype):
193193
sample_points = np.array([[0.1, 0.3, 0.0], [0.2, 0.5, 0.0], [0.6, 0.6, 0.0]])
194194

195195
# Create boundingboxtree
196-
tree = geometry.bb_tree(mesh, mesh.geometry.dim)
196+
tree = geometry.bb_tree(mesh, mesh.geometry.dim, 0.0)
197197
cell_candidates = geometry.compute_collisions_points(tree, sample_points)
198198
colliding_cells = geometry.compute_colliding_cells(mesh, cell_candidates, sample_points)
199199
# Check for collision

python/test/unit/mesh/test_manifold_point_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_manifold_point_search():
1818
cells = np.array([[0, 1, 2], [0, 1, 3]], dtype=np.int64)
1919
domain = ufl.Mesh(element("Lagrange", "triangle", 1, shape=(2,)))
2020
mesh = create_mesh(MPI.COMM_WORLD, cells, vertices, domain)
21-
bb = bb_tree(mesh, mesh.topology.dim)
21+
bb = bb_tree(mesh, mesh.topology.dim, 0.0)
2222

2323
# Find cell colliding with point
2424
points = np.array([[0.5, 0.25, 0.75], [0.25, 0.5, 0.75]], dtype=default_real_type)

0 commit comments

Comments
 (0)