Fix inconsistent out-of-range evaluation between Tabulated1D scalar and array paths - #4074
Open
kawacukennedy wants to merge 1 commit into
Open
Conversation
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>
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
Evaluating
openmc.data.Tabulated1Don values outside its tabulated range currently gives different answers depending on whether the input is a scalar or an array: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.isclosechecks), 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.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 theq_*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.pycovering:sum_functionsbehavior 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
developas well).Fixes: #4041
Signed-off-by: Engineer kawacukent@gmail.com