Skip to content

Fix GCONSUMP efficiency factor application#6737

Merged
hakonhagland merged 2 commits into
OPM:masterfrom
hakonhagland:gconsump_eff
Jan 22, 2026
Merged

Fix GCONSUMP efficiency factor application#6737
hakonhagland merged 2 commits into
OPM:masterfrom
hakonhagland:gconsump_eff

Conversation

@hakonhagland
Copy link
Copy Markdown
Contributor

The GCONSUMP efficiency factor calculation was incorrectly applying group efficiency factors to the groups themselves, rather than following the the pattern used elsewhere in the code base:

  • Groups should NOT be affected by their own efficiency factors
  • Parent groups apply child efficiency factors when accumulating contributions

Changes:

  • Fix GroupState::update_gconsump() to implement correct efficiency pattern
  • Add test suite with simple and complex hierarchy scenarios

@hakonhagland hakonhagland added the manual:bugfix This PR is a bug fix and should be noted in the manual label Jan 19, 2026
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

The jenkins build failure:

...
Report step  1/12 at day 31/365, date = 01-Feb-2015
ERROR: Uncaught std::exception when running tasklet: Input IJK index (29, 29, 0) not part of grid with dimensions 30 x 30 x 9..

Starting time step 0, stepsize 18.312 days, at day 31/59, date = 01-Feb-2015
 Newton its= 7, linearizations= 8 (0.2sec), linear its= 10 (0.2sec)
Simulation aborted as program threw an unexpected exception: Failure in the TaskletRunner while writing output.
CUDA ERROR (code = 35, CUDA driver version is insufficient for CUDA runtime version) at /var/lib/jenkins/hypre/hypre/src/utilities/general.c:282

seems to be unrelated to this PR. @akva2 Any idea?

@hakonhagland hakonhagland requested a review from vkip January 20, 2026 05:49
@akva2
Copy link
Copy Markdown
Member

akva2 commented Jan 20, 2026

The real error is

ERROR: Uncaught std::exception when running tasklet: Input IJK index (29, 29, 0) not part of grid with dimensions 30 x 30 x 9.

which means k is std::size_t{-1}. I can only assume there's something funky with the input file you are using.

The GCONSUMP efficiency factor calculation was incorrectly applying group
efficiency factors to the groups themselves, rather than following the
the pattern used elsewhere in the code base:
  - Groups are NOT affected by their own efficiency factors
  - Parent groups apply child efficiency factors when accumulating contributions

Changes:
  - Fix GroupState::update_gconsump() to implement correct efficiency pattern
  - Add test suite with simple and complex hierarchy scenarios
@hakonhagland
Copy link
Copy Markdown
Contributor Author

hakonhagland commented Jan 20, 2026

I can only assume there's something funky with the input file you are using.

@akva2 I am able to reproduce an error (though not exactly the same error as in the jenkins build) for the same test case locally both for the PR branch and the master branch, so it seems it is not related to the PR.

@akva2
Copy link
Copy Markdown
Member

akva2 commented Jan 20, 2026

yeah, i ran into it in another build. there is definitely an issue.

@akva2
Copy link
Copy Markdown
Member

akva2 commented Jan 20, 2026

yeah, it contains out of bounds access errors. i've opened a PR to disable the test, #6739

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@vkip
Copy link
Copy Markdown
Member

vkip commented Jan 21, 2026

I'm probably missing something, but to me it seems this PR does the exact same thing as the originial code, only in a more inefficient (though admittedly more readable) manner. Could you provide a running example demonstrating the issue this PR intends to fix?

@hakonhagland
Copy link
Copy Markdown
Contributor Author

Could you provide a running example demonstrating the issue this PR intends to fix?

@vkip The original code has a subtle bug: the parent_gefac parameter is only applied when retrieving from cache (lines 538-542 in the original code), but since m_gconsump_rates.clear() is called at line 527, the cache is always empty during recursion, so parent_gefac is never used.

Additionally, rates is passed by reference and accumulated all the way up, resulting in all groups storing the same values.

You can verify this by checking out the original code and running the test:

git checkout HEAD~1 -- opm/simulators/wells/GroupState.cpp
cd build && ninja test_gconsump && ctest -R gconsump --output-on-failure
# Result: 8 test failures showing efficiency factors not applied
git checkout HEAD -- opm/simulators/wells/GroupState.cpp  # restore fix

Regarding efficiency: The memoization cache in the original code actually provided no benefit during recursion. Since the group hierarchy is a tree (each group has exactly one parent), and the cache is cleared at the start of update_gconsump(), each group is visited exactly once and the cache lookup never succeeds. Both versions have O(N) complexity where N is the number of groups.

@vkip
Copy link
Copy Markdown
Member

vkip commented Jan 21, 2026

Thank you, I finally see the issue(s) now, and agree that there's no real effect of the intended optimization here (beyond obfuscating the code). Thanks a lot for identifying and fixing this!

Copy link
Copy Markdown
Member

@vkip vkip left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a minor comment on the new .DATA files.

Comment thread tests/GCONSUMP.DATA
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand it is not the intension, but with a couple of very minor changes (PVTO record 2, EQUIL item 1) the data file could actually also be run with the simulator, possibly extending the usefulness in other situations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I have added a commit to address this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thanks 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank for the review!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for this file.

Update GCONSUMP.DATA and GCONSUMP_COMPLEX.DATA to be valid input for
full simulation runs while preserving their unit test functionality:

- Fix EQUIL datum depth to match gas-oil contact (7020 → 7000)
- Fix PVTO bubble point relationship (Rs/Pbub must be monotonic)
- Extend PVDG pressure range to cover reservoir pressure (→ 300 bar)
- Adjust SGOF Sg_max to avoid floating-point SOGCR precision issue
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland hakonhagland merged commit 1ae9d88 into OPM:master Jan 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:bugfix This PR is a bug fix and should be noted in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants