def test_compute_collisions_tree_2d(point): mesh_A = create_unit_square(MPI.COMM_WORLD, 3, 3) mesh_B = create_unit_square(MPI.COMM_WORLD, 5, 5) bgeom = mesh_B.geometry.x bgeom += point tree_A = BoundingBoxTree(mesh_A, mesh_A.topology.dim) tree_B = BoundingBoxTree(mesh_B, mesh_B.topology.dim) entities = compute_collisions(tree_A, tree_B) entities_A = np.sort(np.unique([q[0] for q in entities])) entities_B = np.sort(np.unique([q[1] for q in entities])) cells_A = find_colliding_cells(mesh_A, tree_B.get_bbox(tree_B.num_bboxes - 1)) cells_B = find_colliding_cells(mesh_B, tree_A.get_bbox(tree_A.num_bboxes - 1)) assert np.allclose(entities_A, cells_A) assert np.allclose(entities_B, cells_B)
def test_compute_collisions_tree_3d(point): mesh_A = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2) mesh_B = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2) bgeom = mesh_B.geometry.x bgeom += point tree_A = BoundingBoxTree(mesh_A, mesh_A.topology.dim) tree_B = BoundingBoxTree(mesh_B, mesh_B.topology.dim) entities = compute_collisions(tree_A, tree_B) entities_A = numpy.sort(numpy.unique([q[0] for q in entities])) entities_B = numpy.sort(numpy.unique([q[1] for q in entities])) cells_A = find_colliding_cells(mesh_A, tree_B.get_bbox(tree_B.num_bboxes - 1)) cells_B = find_colliding_cells(mesh_B, tree_A.get_bbox(tree_A.num_bboxes - 1)) assert numpy.allclose(entities_A, cells_A) assert numpy.allclose(entities_B, cells_B)
def test_sub_bbtree_box(ct, N): """Test that the bounding box of the stem of the bounding box tree is what we expect""" mesh = create_unit_cube(MPI.COMM_WORLD, N, N, N, cell_type=ct) tdim = mesh.topology.dim fdim = tdim - 1 facets = locate_entities_boundary(mesh, fdim, lambda x: np.isclose(x[1], 1.0)) f_to_c = mesh.topology.connectivity(fdim, tdim) cells = np.int32(np.unique([f_to_c.links(f)[0] for f in facets])) bbtree = BoundingBoxTree(mesh, tdim, cells) num_boxes = bbtree.num_bboxes if num_boxes > 0: bbox = bbtree.get_bbox(num_boxes - 1) assert np.isclose(bbox[0][1], (N - 1) / N) tree = BoundingBoxTree(mesh, tdim) assert num_boxes < tree.num_bboxes
def test_sub_bbtree_box(ct, N): """ Test that the bounding box of the stem of the bounding box tree is what we expect """ mesh = UnitCubeMesh(MPI.COMM_WORLD, N, N, N, cell_type=ct) tdim = mesh.topology.dim fdim = tdim - 1 def marker(x): return numpy.isclose(x[1], 1.0) facets = locate_entities_boundary(mesh, fdim, marker) f_to_c = mesh.topology.connectivity(fdim, tdim) cells = numpy.unique([f_to_c.links(f)[0] for f in facets]) bbtree = BoundingBoxTree(mesh, tdim, cells) num_boxes = bbtree.num_bboxes if num_boxes > 0: bbox = bbtree.get_bbox(num_boxes - 1) assert numpy.isclose(bbox[0][1], (N - 1) / N) tree = BoundingBoxTree(mesh, tdim) assert num_boxes < tree.num_bboxes