Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose _bbox_coordinates of BoundingBoxTree to users #3600

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ordinary-slim
Copy link

@ordinary-slim ordinary-slim commented Jan 16, 2025

Addressing #3599. Expose _bbox_coordinates of BoundingBoxTree the same way _x of Geometry is exposed. I added a test with point-tree collisions before and after a translational motion.

@ordinary-slim ordinary-slim changed the title Expose bbox_coordinates of BoundingBoxTree to users Expose _bbox_coordinates of BoundingBoxTree to users Jan 17, 2025
- Avoiding copying of bounding boxes
- Early break in point_in_bbox
@ordinary-slim
Copy link
Author

I've been profiling compute_collisions with points and I found some opportunities for speed-ups:

  • Early break in point_in_bbox. Note that &= doesn't short-circuit and always evaluates the RHS so it's better to have a &= b && c in the same line rather than have it in two separate lines.
  • Avoid calling BoundingBoxTree.get_bbox as it spends a good deal of time in copy_n. I wrote a small workaround as a lambda function in compute_collisions with points but I think it would be cleaner if get_bbox returned a span of const rather than a new copy.

In this snippet of code

from dolfinx import mesh, geometry
import numpy as np
from mpi4py import MPI
from line_profiler import LineProfiler

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

def main():
    tdim = 3
    num_elems_side = 20
    domain = mesh.create_unit_cube(MPI.COMM_WORLD,
                                   num_elems_side, num_elems_side, num_elems_side,
                                   mesh.CellType.tetrahedron, dtype=np.float64)
    bbtree = geometry.bb_tree(domain, tdim, padding=0.0)
    rng = np.random.default_rng(0)
    num_points = 200000
    points = rng.random((num_points, 3))
    collisions = geometry.compute_collisions_points(bbtree, points)

if __name__=="__main__":
    lp = LineProfiler()
    lp_wrapper = lp(main)
    lp_wrapper()
    with open(f"profiling_rank{rank}.txt", 'w') as pf:
        lp.print_stats(stream=pf)

the line collisions = geometry.compute_collisions_points(bbtree, points) takes 2.4 seconds before these changes and 1.95 seconds after these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant