#14555 Allow statistical grid cases to be used as source for grid calculator expressions

Statistics cases were filtered out of the case lists used by the grid calculator, both in the variable table and in the Select Result dialog. Statistics cases belonging to a grid ensemble were also missing from RimProject::allGridCases(), as only the source cases of the ensemble were collected. Statistics cases in a grid case group were already included.

A statistics case can be used as source only. A calculated result stored in a statistics case is interpreted as computed statistics, and would block recomputation of the statistics, so a statistics case is never assigned as destination case.

A statistics case with no computed statistics is not necessarily opened. Make sure source cases are opened before grid dimensions are validated and before result data is read.
This commit is contained in:
Magne Sjaastad
2026-08-21 14:53:48 +02:00
parent e2319d0bd3
commit 6022980d54
4 changed files with 35 additions and 4 deletions
@@ -178,6 +178,13 @@ bool RimGridCalculation::calculate()
bool checkIfGridSizeIsEqual = ( !allSourceCasesAreEqualToDestinationCase() || m_cellFilterView != nullptr ) &&
m_additionalCasesType != AdditionalCasesType::ENSEMBLE;
// Grid dimensions are required to validate the calculation, and a source case is not necessarily opened. This is the case for a
// statistics case with no computed statistics.
for ( auto inputCase : inputCases() )
{
if ( inputCase && !inputCase->eclipseCaseData() ) inputCase->ensureReservoirCaseIsOpen();
}
for ( auto calculationCase : outputEclipseCases() )
{
if ( !calculationCase ) continue;
@@ -524,7 +531,11 @@ void RimGridCalculation::onVariableUpdated( const SignalEmitter* emitter )
{
if ( auto variableCase = variable->eclipseCase() )
{
if ( !m_destinationCase || !m_destinationCase->isGridSizeEqualTo( variableCase ) )
// A statistics case can be used as source, but never as destination. A calculated result stored in a statistics case is
// interpreted as computed statistics, and will block recomputation of the statistics.
const bool canBeDestinationCase = dynamic_cast<RimEclipseStatisticsCase*>( variableCase ) == nullptr;
if ( canBeDestinationCase && ( !m_destinationCase || !m_destinationCase->isGridSizeEqualTo( variableCase ) ) )
{
m_destinationCase = variableCase;
}
@@ -609,6 +620,9 @@ std::vector<double> RimGridCalculation::getActiveCellValues( const QString&
{
if ( !sourceCase || !destinationCase ) return {};
// A statistics case is not necessarily opened when used as source for a calculation
if ( !sourceCase->eclipseCaseData() && !sourceCase->ensureReservoirCaseIsOpen() ) return {};
size_t timeStepToUse = tsId;
if ( resultCategoryType == RiaDefines::ResultCatType::STATIC_NATIVE )
{
@@ -618,7 +632,9 @@ std::vector<double> RimGridCalculation::getActiveCellValues( const QString&
RigEclipseResultAddress resAddr( resultCategoryType, resultName );
auto eclipseCaseData = sourceCase->eclipseCaseData();
auto eclipseCaseData = sourceCase->eclipseCaseData();
if ( !eclipseCaseData ) return {};
auto rigCaseCellResultsData = eclipseCaseData->results( porosityModel );
if ( rigCaseCellResultsData->findOrLoadKnownScalarResultForTimeStep( resAddr, timeStepToUse ) == cvf::UNDEFINED_SIZE_T ) return {};
@@ -164,7 +164,11 @@ QList<caf::PdmOptionItemInfo> RimGridCalculationVariable::calculateValueOptions(
}
else if ( fieldNeedingOptions == &m_eclipseCase )
{
RimTools::eclipseCaseOptionItems( &options );
// Include statistics cases, as a statistics result can be used as source in a grid calculation
for ( auto* c : RimEclipseCaseTools::allEclipseGridCases() )
{
options.push_back( caf::PdmOptionItemInfo( c->caseUserDescription(), c, false, c->uiIconProvider() ) );
}
}
else if ( fieldNeedingOptions == &m_timeStep )
{
@@ -644,10 +644,20 @@ std::vector<RimCase*> RimProject::allGridCases() const
for ( RimReservoirGridEnsemble* ensemble : analysisModels->reservoirGridEnsembles.childrenByType() )
{
if ( ensemble == nullptr ) continue;
for ( RimEclipseCase* acase : ensemble->cases() )
{
cases.push_back( acase );
}
if ( ensemble->statisticsCaseCollection() )
{
for ( RimEclipseCase* eclipseCase : ensemble->statisticsCaseCollection()->reservoirs )
{
cases.push_back( eclipseCase );
}
}
}
RimGeoMechModels* geomModels = oilField->geoMechModels();
@@ -109,7 +109,8 @@ QList<caf::PdmOptionItemInfo> RimResultSelectionUi::calculateValueOptions( const
if ( fieldNeedingOptions == &m_eclipseCase )
{
for ( auto* c : RimEclipseCaseTools::nativeEclipseGridCases() )
// Include statistics cases, as a statistics result can be used as source in a grid calculation
for ( auto* c : RimEclipseCaseTools::allEclipseGridCases() )
{
options.push_back( caf::PdmOptionItemInfo( c->caseUserDescription(), c, false, c->uiIconProvider() ) );
}