Implement SphericalMesh.get_indices_at_coords#3919
Open
EdenRochmanSharabi wants to merge 1 commit intoopenmc-dev:developfrom
Open
Implement SphericalMesh.get_indices_at_coords#3919EdenRochmanSharabi wants to merge 1 commit intoopenmc-dev:developfrom
EdenRochmanSharabi wants to merge 1 commit intoopenmc-dev:developfrom
Conversation
Resolves the remaining work from openmc-dev#3867. Converts Cartesian (x, y, z) input to spherical (r, theta, phi) relative to the mesh origin, validates against grid bounds, and returns bin indices via np.searchsorted. Handles the degenerate r=0 case where angular coordinates are undefined. Adds comprehensive unit tests covering basic lookups, multi-bin angular grids, non-default origin, boundary values, r=0, and out-of-bounds errors for each axis.
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.
Summary
Implements
SphericalMesh.get_indices_at_coords, resolving the remaining workfrom #3867 (
RectilinearMeshwas already done in #3824).The method accepts Cartesian (x, y, z) coordinates, converts to spherical
(r, theta, phi) relative to
self.origin, validates against grid bounds, andreturns bin indices via
np.searchsorted. Follows the same pattern asCylindricalMesh.get_indices_at_coords.Handles the degenerate case where r=0 (theta and phi are mathematically
undefined) by defaulting both to 0.0.
Changes
openmc/mesh.py: ReplaceNotImplementedErrorstub with full implementationtests/unit_tests/test_mesh.py: Addtest_SphericalMesh_get_indices_at_coordsTests