Skip to content

Use size_t for indices in grid, layer, and fault_block - #1308

Merged
eivindjahren merged 8 commits into
mainfrom
grid_size_t
Oct 29, 2026
Merged

eivindjahren merged 8 commits into
mainfrom
grid_size_t

Conversation

@eivindjahren

@eivindjahren eivindjahren commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

This changes the actual number returned by Grid::coarse_groups when groups are non-contiguous. This seems reasonable as it is within the documentation of the function.

@eivindjahren
eivindjahren force-pushed the grid_size_t branch 3 times, most recently from 7de44ed to acb2f6c Compare October 28, 2026 11:16
@eivindjahren
eivindjahren requested a balanced review from Copilot October 28, 2026 11:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The pybind constructor still forwards int arguments to fields changed to size_t, causing narrowing that breaks binding compilation.

1 open issue
What changed in this PR

This PR migrates grid, layer, and fault-block indices to size_t, updating related APIs, Python bindings, and tests. It also changes coarse-group counts to report distinct groups rather than the highest group number.

Changes:

  • Replace signed indices and sentinel values with size_t and optional results across related C++ components.
  • Update Python interfaces and input validation, including None for out-of-column depth lookups.
  • Adapt regression tests for unsigned indices, invalid inputs, and sparse coarse-group numbering.
File Description
tests/​rd_tests/​test_rd_grid_regular.py Test out-of-column depth results.
tests/​rd_tests/​test_rd_grid_misc.py Update invalid-coordinate expectations.
tests/​rd_tests/​test_rd_grid_coarse.py Expect distinct coarse-group counts.
tests/​rd_tests/​test_grid.py Add malformed-input and unsigned-index tests.
tests/​rd_tests/​test_fault_blocks.py Test invalid layer and cell indices.
python/​resdata/​grid/​rd_grid.py Validate dimensions and handle optional results.
lib/​tests/​test_rd_region.cpp Adapt region tests to unsigned indices.
lib/​tests/​test_rd_grid_xyz_lookup.cpp Test optional coordinate-lookup results.
lib/​tests/​test_rd_grid_regular.cpp Adapt grid tests to revised APIs.
lib/​tests/​test_rd_grid_nnc_lgr.cpp Update indices and test negative refinement identifiers.
lib/​tests/​test_rd_grid_coarse.cpp Test sparse and extreme coarse-group numbers.
lib/​tests/​test_rd_grid_bounds_checking.cpp Use unsigned fixture dimensions and sizes.
lib/​tests/​test_nnc_info.cpp Use unsigned refinement identifiers.
lib/​tests/​test_layer.cpp Adapt layer tests and corner indexing.
lib/​tests/​test_fault_block_layer.cpp Update layer fixtures and bounds tests.
lib/​resdata/​tests/​rd_nnc_vector.cpp Update connection-vector types and assertions.
lib/​resdata/​tests/​rd_nnc_test.cpp Adapt connection lookup checks.
lib/​resdata/​tests/​rd_nnc_info_test.cpp Update connection metadata tests.
lib/​resdata/​tests/​rd_layer.cpp Use unsigned layer coordinates and lists.
lib/​resdata/​tests/​rd_grid_volume.cpp Update volume-test indices and formatting.
lib/​resdata/​tests/​rd_grid_reset_actnum.cpp Assert optional active-index results.
lib/​resdata/​tests/​rd_grid_lgr_name.cpp Update refinement-name lookup assertions.
lib/​resdata/​tests/​rd_grid_layer_contains.cpp Use unsigned coordinate lookup outputs.
lib/​resdata/​tests/​rd_grid_init_fwrite.cpp Update export loops and numeric conversions.
lib/​resdata/​tests/​rd_grid_export.cpp Use unsigned geometry buffer sizes.
lib/​resdata/​tests/​rd_grid_dx_dy_dz.cpp Update dimension-test indices.
lib/​resdata/​tests/​rd_grid_cell_contains_wellpath.cpp Adapt wellpath lookup results and diagnostics.
lib/​resdata/​tests/​rd_grid_add_nnc.cpp Update connection indices and assertions.
lib/​resdata/​tests/​rd_fault_block_layer.cpp Adapt fault-layer test indices.
lib/​resdata/​tests/​rd_dualp.cpp Update dual-porosity index assertions.
lib/​resdata/​tests/​rd_coarse_test.cpp Validate coarse bounds and optional indices.
lib/​resdata/​rd_subsidence.cpp Use unsigned cache sizes and loops.
lib/​resdata/​rd_region.cpp Migrate region indices and clamp signed intervals.
lib/​resdata/​rd_region_pybind.cpp Accept unsigned region coordinates.
lib/​resdata/​rd_grid_pybind.cpp Update index bindings and reject negative export indices.
lib/​resdata/​rd_grid_cache.cpp Use unsigned cached grid indices.
lib/​resdata/​rd_grav.cpp Update cache indexing and validate density identifiers.
lib/​resdata/​rd_grav_common.cpp Use unsigned gravity calculation indices.
lib/​resdata/​rd_coarse_cell.cpp Use optional indices and unsigned coarse-cell bounds.
lib/​resdata/​rd_box.cpp Adapt box traversal to optional active indices.
lib/​resdata/​nnc_vector.cpp Migrate connection indices and bounds-check access.
lib/​resdata/​nnc_info.cpp Use optional refinement-map entries.
lib/​resdata/​layer.cpp Migrate layer indexing and adjust boundary arithmetic.
lib/​resdata/​layer_pybind.cpp Accept unsigned layer dimensions and coordinates.
lib/​resdata/​fault_block.cpp Migrate cell indices and guard neighbor subtraction.
lib/​resdata/​fault_block_layer.cpp Use optional block-map entries and unsigned coordinates.
lib/​resdata/​fault_block_layer_pybind.cpp Accept unsigned layer indices.
lib/​private-include/​detail/​resdata/​rd_grid_zcorn.hpp Add unsigned corner-index helper.
lib/​private-include/​detail/​resdata/​rd_grid_cache.hpp Expose unsigned cache sizes and indices.
lib/​private-include/​detail/​resdata/​layer_cxx.hpp Update edge-tracing index types.
lib/​include/​resdata/​rd_region.hpp Update region index APIs and templates.
lib/​include/​resdata/​rd_grid.hpp Declare unsigned indices and optional lookup results.
lib/​include/​resdata/​rd_coarse_cell.hpp Expose revised coarse-cell bounds and indices.
lib/​include/​resdata/​rd_box.hpp Update box bounds and index lists.
lib/​include/​resdata/​nnc_vector.hpp Update connection-vector interfaces.
lib/​include/​resdata/​nnc_info.hpp Update connection metadata interfaces.
lib/​include/​resdata/​layer.hpp Declare unsigned layer coordinates and counts.
lib/​include/​resdata/​fault_block.hpp Update fault-cell fields and index interfaces.
lib/​include/​resdata/​fault_block_layer.hpp Update layer-index declarations.

Review effort: Balanced

Comment thread lib/include/resdata/fault_block.hpp

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Regression tests are missing for slice clamping and out-of-range intervals across all three axes, and for decreasing or mixed-direction diagonal interpolation at zero-coordinate boundaries.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread lib/resdata/layer.cpp Outdated
Comment thread lib/resdata/rd_region.cpp
@eivindjahren
eivindjahren requested a review from ajaust October 28, 2026 11:54
@eivindjahren eivindjahren moved this to Ready for Review in SCOUT Oct 28, 2026

@ajaust ajaust left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I left some comments.

Comment thread lib/resdata/rd_grid.cpp Outdated
Comment thread lib/resdata/tests/rd_grid_cell_contains_wellpath.cpp
Comment thread lib/resdata/layer.cpp Outdated
Comment thread lib/resdata/rd_region.cpp Outdated
@ajaust ajaust moved this from Ready for Review to Reviewed in SCOUT Oct 28, 2026
@eivindjahren
eivindjahren added this pull request to stack #1313 October 29, 2026 07:05
@eivindjahren
eivindjahren force-pushed the grid_size_t branch 2 times, most recently from 7d3aeff to 0514208 Compare October 29, 2026 07:34
Validate conversions from signed to unsigned at the Python boundary.
Functions now raise TypeError on negative indices.
Coarse groups are now kept in an unordered_map keyed by an int group id.
Negative CORSNUM values mean no group, and huge values no longer cause
out-of-bounds writes or unbounded allocation. rd_grid_get_num_coarse_groups
returns the number of groups present, and rd_grid_iget_coarse_group returns
nullptr for unknown ids. rd_grid_compare_coarse_cells now compares every group.

@ajaust ajaust left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 👍

@eivindjahren
eivindjahren merged commit 2f71554 into main Oct 29, 2026
13 checks passed
@eivindjahren
eivindjahren deleted the grid_size_t branch October 29, 2026 10:27
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in SCOUT Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants