Skip to content

Fix ensemble contour map GENERATED result statistics and caching bugs - #14813

Merged
magnesj merged 2 commits into
OPM:devfrom
magnesj:ensemble-contour-map-generated-result-caching
Oct 2, 2026
Merged

magnesj merged 2 commits into
OPM:devfrom
magnesj:ensemble-contour-map-generated-result-caching

Conversation

@magnesj

@magnesj magnesj commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #14812 - a set of related bugs affecting ensemble contour maps that use a GENERATED (grid calculation) result, plus a related bug where switching a view's case lost generated results.

  1. Per-realization recompute: RimStatisticsContourMap::computeStatisticsForMaps() opens and closes each ensemble realization in turn to bound memory use. RimEclipseCase::closeReservoirCase() discards the whole RigEclipseCaseData, so a GENERATED result computed for one realization is lost again before the next realization is processed. Added ensureGeneratedResultIsComputed(), called for the current case inside the per-case loop, which looks up the matching RimGridCalculation (by result variable name) and re-runs it for that single realization.

  2. Disk cache always rejected for GENERATED results: RimStatisticsContourMap::selectedTimeSteps() collapses to a single time step unless the mapped result reports as dynamic (RimEclipseResultDefinition::hasDynamicResult()). For a GENERATED result, that check depends on whether the primary case currently has the result computed in memory - true right after computing statistics (cache write time), false on a fresh session before the calculation has run again (cache check time). This made the cache validity key unstable between sessions, so the on-disk .gri cache was always rejected and the whole ensemble recomputed on every load. Fixed by proactively computing the GENERATED result on the primary case in ensureResultsComputed(), before the cache is checked.

  3. "Calculate" button always recomputed the whole ensemble: clicking "Calculate" for a calculation with a Destination Ensemble iterated every realization, even for a plain per-cell expression whose result can be recomputed lazily, one realization at a time (see point 1). Restricted RimGridCalculation::calculate() to the ensemble's main case for plain expressions via a new casesToCalculate() helper; only aggregation expressions (sum/avg/min/max/count, whose result is the per-realization summary itself and cannot be produced lazily) still compute for every realization.

  4. Generated results lost when a view is stepped to another case: grid calculation results are not stored with the case, so switching a view's case (RimEclipseView::fieldChangedByUi()) left no generated results available and the view was cleared. Added RimGridCalculationCollection::ensureCalculationsAreComputed(), called before the result definitions are updated, which computes any calculation missing for the new case. Introduced RimGridCalculation::calculateForCase() to compute a single case using the calculation's own filter and time step settings, and reused it in ensureGeneratedResultIsComputed() for the ensemble contour map per-realization path (point 1), so that path now also respects the calculation's filter/time step settings instead of always using none.

Testing

  • Added RimStatisticsContourMapTest.GeneratedDynamicResultIsNotReportedAsDynamicBeforeItIsComputed and RimStatisticsContourMapTest.EnsureResultsComputedMakesGeneratedResultDynamicBeforeCacheCheck reproducing and verifying the caching fix.
  • Added RimGridCalculationTest.EnsembleDestinationWithPlainExpressionOnlyCalculatesMainCase and RimGridCalculationTest.EnsembleDestinationWithAggregationExpressionCalculatesAllCases verifying the "Calculate" button restriction.
  • Added RimGridCalculationTest.EnsureCalculationsAreComputedForCaseNotInOutputCases verifying generated results are computed for a case stepped to that is not an output case of the calculation.

…ching bugs

Compute grid calculations when a view is stepped to another case.
@magnesj
magnesj force-pushed the ensemble-contour-map-generated-result-caching branch from 1cb5c95 to 15a649b Compare October 1, 2026 08:54
@magnesj
magnesj marked this pull request as ready for review October 1, 2026 08:54
@magnesj
magnesj requested a review from kriben October 1, 2026 08:59
@magnesj magnesj self-assigned this Oct 1, 2026

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

Reviewed the last commit using open-code-review-delegate.

Comment thread ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp
Comment thread ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp
…ble results in calculateForCase()

calculateForCase() now opens required source cases before validation, like
calculate() already did, fixing a null-deref crash when a source case is
closed. Recalculating an ensemble's main case for a plain per-cell
expression now also invalidates any stale result already computed for
another, currently open realization, so it is lazily recomputed instead of
being mistaken for up to date.
@magnesj

magnesj commented Oct 2, 2026 •

Copy link
Copy Markdown
Member Author

Addressed both review comments in 21d609e:

  • High (open source cases before validation): calculateForCase() now opens any closed source cases before validation/evaluation, mirroring what calculate() already did. Added RimGridCalculationTest.CalculateForCaseOpensClosedSourceCase reproducing the crash (closed source case -> null results() deref) and verifying it's fixed.
  • Medium (invalidate stale lazily-computed results): when calculate() restricts a plain per-cell ensemble expression to the main case, it now clears the output result on any other already-open realization via RigCaseCellResultsData::clearScalarResult(), and RimGridCalculationCollection::ensureCalculationsAreComputed() now checks isResultLoaded() in addition to hasResultEntry() so a cleared-but-registered result is recomputed on next use instead of being treated as up to date. Added RimGridCalculationTest.RecalculatingEnsembleMainCaseInvalidatesStaleResultOnOtherOpenRealization covering this.

All 44 tests in the targeted suite pass, and the full ResInsight app target builds cleanly.

@magnesj
magnesj merged commit c5c0e05 into OPM:dev Oct 2, 2026
10 checks passed
@magnesj
magnesj deleted the ensemble-contour-map-generated-result-caching branch October 2, 2026 13:08
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.

Ensemble contour map: GENERATED result statistics and caching bugs

2 participants