Skip to content

Implement SphericalMesh.get_indices_at_coords#3919

Open
EdenRochmanSharabi wants to merge 1 commit intoopenmc-dev:developfrom
EdenRochmanSharabi:spherical-mesh-get-indices-at-coords
Open

Implement SphericalMesh.get_indices_at_coords#3919
EdenRochmanSharabi wants to merge 1 commit intoopenmc-dev:developfrom
EdenRochmanSharabi:spherical-mesh-get-indices-at-coords

Conversation

@EdenRochmanSharabi
Copy link
Copy Markdown

Summary

Implements SphericalMesh.get_indices_at_coords, resolving the remaining work
from #3867 (RectilinearMesh was 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, and
returns bin indices via np.searchsorted. Follows the same pattern as
CylindricalMesh.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: Replace NotImplementedError stub with full implementation
  • tests/unit_tests/test_mesh.py: Add test_SphericalMesh_get_indices_at_coords

Tests

  • Basic single-bin lookups along each axis
  • Multi-bin angular grids (theta and phi bin assignment)
  • Non-default origin
  • Boundary values (point on grid edge)
  • Degenerate r=0 case
  • Out-of-bounds ValueError for r, theta, and phi
  • Diagonal point verifying all three coordinates computed correctly

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.
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