Skip to content

Fix inconsistent out-of-range evaluation between Tabulated1D scalar and array paths - #4074

Open
kawacukennedy wants to merge 1 commit into
openmc-dev:developfrom
kawacukennedy:fix/issue-4041-tabulated1d-out-of-range
Open

Fix inconsistent out-of-range evaluation between Tabulated1D scalar and array paths#4074
kawacukennedy wants to merge 1 commit into
openmc-dev:developfrom
kawacukennedy:fix/issue-4041-tabulated1d-out-of-range

Conversation

@kawacukennedy

Copy link
Copy Markdown

Description

Evaluating openmc.data.Tabulated1D on values outside its tabulated range currently gives different answers depending on whether the input is a scalar or an array:

>>> tab = openmc.data.Tabulated1D([1, 2, 3], [4, 5, 6], [], [2])
>>> tab(0)
4
>>> tab([0])
array([0])

The scalar path (_interpolate_scalar) returns the value at the nearest tabulated endpoint, while the array path in __call__ initializes the output with zeros and only fills points that fall inside an interpolation region, leaving out-of-range entries at zero.

This PR makes the array path assign the boundary values (y[0] / y[-1]) to out-of-range points so that both paths agree. This is also consistent with the existing precision handling at the domain edges (np.isclose checks), which already assigns endpoint values to near-edge points.

Changes

  • openmc/data/function.py:
    • Tabulated1D.__call__: out-of-range points now receive the value of the nearest tabulated endpoint, matching the scalar path.
    • Class docstring: documented the out-of-range behavior.
    • sum_functions: each tabulated component is now explicitly evaluated only where it is defined (points outside a component's own tabulated range contribute zero). This preserves the existing behavior of combined functions — e.g., FissionEnergyRelease.recoverable, total, and the q_* properties, which combine components that may cover different incident energy ranges on a union grid — independently of the new out-of-range semantics.

Testing

Added tests/unit_tests/test_function.py covering:

  • scalar/array agreement across, below, and above the tabulated range (the issue's regression case),
  • all five ENDF interpolation schemes,
  • multi-region functions,
  • exact-endpoint and floating-point-precision edge cases,
  • multidimensional input shape preservation,
  • sum_functions behavior for components with differing domains and for polynomial+tabulated combinations.

Local results: all 11 new tests pass; existing unit tests that exercise these code paths were compared before/after the change with identical outcomes (failures observed locally are due to no nuclear data being configured and are present on unmodified develop as well).

Fixes: #4041

Signed-off-by: Engineer kawacukent@gmail.com

Evaluating openmc.data.Tabulated1D on an array containing values outside
the tabulated range returned zeros for those points, while scalar
evaluation returns the value at the nearest tabulated endpoint.  Assign
boundary values to out-of-range points in the array evaluation path so
that both paths agree.

sum_functions is also updated to evaluate each tabulated component only
where it is defined, which preserves the behavior of combined functions
(e.g., fission energy release components) whose tabulated components
cover different incident energy ranges.

Fixes: openmc-dev#4041

Signed-off-by: Engineer <kawacukent@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scalar v.s. array input to openmc.data.Tabulated1D gives different results.

2 participants