Skip to content

Conversation

@paulromano
Copy link
Contributor

Description

This PR adds an optional bounding_boxes flag to the mesh material volume calculation so that each (mesh element, material) pair can also return an axis‑aligned bounding box. The primary implementation lives in Mesh::material_volumes; it uses low‑level atomic compare‑exchange intrinsics to achieve thread‑safe min/max updates for bounding box expansion. In the future, when we are able to utilize newer features in OpenMP 5, a lot of the ugly atomic-related code can be significantly simplified.

The main motivation for this feature is representing the decay photon source in mesh‑based R2S calculations. At present, R2SManager uses a MeshSource plus a domain constraint for each element‑material pair, which can be extremely inefficient when a material occupies only a tiny portion of an element. With bounding boxes available, the updated workflow here is to forgo MeshSource and instead build a Box source per element‑material combination, using the computed bounding box to restrict sampling while still applying the material domain constraint.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Copy link
Contributor

@GuySten GuySten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
@paulromano, do you think we should deprecate openmc.MeshSource in a follow-up PR?

@GuySten GuySten added the Merging Soon PR will be merged in < 24 hrs if no further comments are made. label Jan 26, 2026
@paulromano
Copy link
Contributor Author

No, I think MeshSource may still come in handy in other use cases so I don't think we should deprecate it.

@pshriwise @eepeterson did either of you want to review this before merging?

@GuySten GuySten merged commit f7a7341 into openmc-dev:develop Jan 29, 2026
17 checks passed
@paulromano paulromano deleted the mesh-mat-bbox branch January 30, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merging Soon PR will be merged in < 24 hrs if no further comments are made.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants