Conversation
…ches A bounding box is computed for each CSG cell at initialization, enlarged slightly for roundoff, and the searches over the cells of a universe and over neighbor lists skip cells whose boxes do not contain the point before evaluating whether the cell contains it. Cells are checked in the same order as before, so the same cell is found, while expensive containment checks are replaced by a box test for cells that cannot contain the point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014RN7JroEkrbkLKVHbMDap9
GuySten
marked this pull request as ready for review
October 3, 2026 09:51
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Finding the cell that contains a point is a linear search: the cells of a universe (or of a z-plane partition), or the neighbor list of the cell being left, are checked in order with
Cell::contains, which evaluates the senses of the point with respect to the cell's surfaces. In universes with many cells, this search dominates the run time. In the Advanced Test Reactor model (5968 cells, the example used in #2593), cell search takes 42% of transport time. It takes 75% of a stochastic volume calculation and about 60% of coupled neutron-photon transport, where every secondary particle starts with an exhaustive search.This PR computes a bounding box for each CSG cell once at initialization, enlarged by a relative 1e-9 for roundoff in positions on the cell boundary. The cell searches in
Universe::find_celland in neighbor lists then skip any cell whose box does not contain the point before callingcontains.Cells are still checked in the same order and the same cell is found, so results are unchanged, even for overlapping cells. The only added cost is one box test (six comparisons) per cell visited, and it replaces a
containscall for every cell whose box does not contain the point. Search structures, neighbor lists, the z-plane partitioner and the input format are unchanged, and no settings are added.Compared with #2593, this is exact by construction: boxes come from the region expressions rather than from sampling, so no cell can be missed and no fallback search is needed. It also needs no parameters or files. #2593 restructures the search with octrees or kd-trees and can be faster on ATR. This PR is a small change that never reorders the search; a tree for very large universes could be built on top of it later.
Performance
Single thread, median of 2 runs. Times are for transport, or for the whole calculation in volume mode. All results are bitwise identical to
develop.Run-to-run variation on this machine is about ±4%.
Tests
tests/unit_tests/test_cell_search.pychecksopenmc.lib.find_cellagainst Python's evaluation of the regions at random points in two cases:The methods documentation describes the bounding box test in cell searches and neighbor lists.
Checklist