From 30d0b8e1153d85ee3c012bb8922e43d2bc03cb91 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Mon, 16 Dec 2024 12:44:29 +0100 Subject: [PATCH] Grid calculator: add support for grid ensembles. --- .../ProjectDataModel/RimGridCalculation.cpp | 46 ++++++++++++++++--- .../ProjectDataModel/RimGridCalculation.h | 3 ++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp b/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp index 6211ad6b9f..ea91d24e0c 100644 --- a/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp @@ -37,6 +37,7 @@ #include "RimCaseCollection.h" #include "RimEclipseCase.h" #include "RimEclipseCaseCollection.h" +#include "RimEclipseCaseEnsemble.h" #include "RimEclipseCaseTools.h" #include "RimEclipseCellColors.h" #include "RimEclipseResultAddress.h" @@ -77,6 +78,7 @@ void caf::AppEnum::setUp() { addItem( RimGridCalculation::AdditionalCasesType::NONE, "NONE", "None" ); addItem( RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP, "GRID_CASE_GROUP", "Case Group" ); + addItem( RimGridCalculation::AdditionalCasesType::ENSEMBLE, "ENSEMBLE", "Ensemble" ); addItem( RimGridCalculation::AdditionalCasesType::ALL_CASES, "NONE", "All Cases" ); setDefault( RimGridCalculation::AdditionalCasesType::NONE ); } @@ -98,6 +100,7 @@ RimGridCalculation::RimGridCalculation() CAF_PDM_InitFieldNoDefault( &m_additionalCasesType, "AdditionalCasesType", "Apply To Additional Cases" ); CAF_PDM_InitFieldNoDefault( &m_additionalCaseGroup, "AdditionalCaseGroup", "Case Group" ); + CAF_PDM_InitFieldNoDefault( &m_additionalEnsemble, "AdditionalEnsemble", "Ensemble" ); CAF_PDM_InitFieldNoDefault( &m_nonVisibleResultAddress, "NonVisibleResultAddress", "" ); m_nonVisibleResultAddress = new RimEclipseResultAddress; @@ -175,7 +178,8 @@ bool RimGridCalculation::calculate() { // Equal grid size is required if there is more than one grid case in the expression. If a cell filter view is active, the visibility is // based on one view and reused for all other grid models, and requires equal grid size. - bool checkIfGridSizeIsEqual = !allSourceCasesAreEqualToDestinationCase() || m_cellFilterView != nullptr; + bool checkIfGridSizeIsEqual = ( !allSourceCasesAreEqualToDestinationCase() || m_cellFilterView != nullptr ) && + m_additionalCasesType != AdditionalCasesType::ENSEMBLE; for ( auto calculationCase : outputEclipseCases() ) { @@ -183,9 +187,16 @@ bool RimGridCalculation::calculate() if ( !calculationCase->eclipseCaseData() ) { - QString msg = QString( "No data available for case %1, aborting calculation" ).arg( calculationCase->caseUserDescription() ); - RiaLogging::errorInMessageBox( nullptr, "Grid Property Calculator", msg ); - return false; + if ( m_additionalCasesType == AdditionalCasesType::ENSEMBLE ) + { + calculationCase->ensureReservoirCaseIsOpen(); + } + else + { + QString msg = QString( "No data available for case %1, aborting calculation" ).arg( calculationCase->caseUserDescription() ); + RiaLogging::errorInMessageBox( nullptr, "Grid Property Calculator", msg ); + return false; + } } if ( !calculationCase->eclipseCaseData()->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL ) ) @@ -275,6 +286,11 @@ std::vector RimGridCalculation::outputEclipseCases() const return m_additionalCaseGroup()->caseCollection()->reservoirs.childrenByType(); } + if ( m_additionalCasesType() == RimGridCalculation::AdditionalCasesType::ENSEMBLE ) + { + if ( m_additionalEnsemble() ) return m_additionalEnsemble()->cases(); + } + return { m_destinationCase }; } @@ -333,6 +349,9 @@ void RimGridCalculation::defineUiOrdering( QString uiConfigName, caf::PdmUiOrder uiOrdering.add( &m_additionalCaseGroup ); m_additionalCaseGroup.uiCapability()->setUiHidden( m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP ); + uiOrdering.add( &m_additionalEnsemble ); + m_additionalEnsemble.uiCapability()->setUiHidden( m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::ENSEMBLE ); + caf::PdmUiGroup* filterGroup = uiOrdering.addNewGroup( "Cell Filter" ); filterGroup->setCollapsedByDefault(); filterGroup->add( &m_cellFilterView ); @@ -442,6 +461,20 @@ QList RimGridCalculation::calculateValueOptions( const c } } } + else if ( &m_additionalEnsemble == fieldNeedingOptions ) + { + options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) ); + + RimProject* proj = RimProject::current(); + if ( proj->activeOilField() && proj->activeOilField()->analysisModels() ) + { + auto analysisModels = proj->activeOilField()->analysisModels(); + for ( RimEclipseCaseEnsemble* e : analysisModels->caseEnsembles() ) + { + options.push_back( caf::PdmOptionItemInfo( e->name(), e, false, e->uiIconProvider() ) ); + } + } + } return options; } @@ -903,8 +936,9 @@ bool RimGridCalculation::calculateForCases( const std::vector& RimGridCalculationVariable* v = dynamic_cast( m_variables[i] ); CAF_ASSERT( v != nullptr ); - bool useDataFromSourceCase = ( v->eclipseCase() == m_destinationCase ); - auto sourceCase = useDataFromSourceCase ? calculationCase : v->eclipseCase(); + bool useDataFromSourceCase = ( v->eclipseCase() == m_destinationCase ) || + m_additionalCasesType == AdditionalCasesType::ENSEMBLE; + auto sourceCase = useDataFromSourceCase ? calculationCase : v->eclipseCase(); auto dataForVariable = getActiveCellValuesForVariable( v, tsId, porosityModel, sourceCase, calculationCase ); if ( dataForVariable.empty() ) diff --git a/ApplicationLibCode/ProjectDataModel/RimGridCalculation.h b/ApplicationLibCode/ProjectDataModel/RimGridCalculation.h index a4454f5a5b..eb50781b28 100644 --- a/ApplicationLibCode/ProjectDataModel/RimGridCalculation.h +++ b/ApplicationLibCode/ProjectDataModel/RimGridCalculation.h @@ -19,6 +19,7 @@ #pragma once #include "RiaPorosityModel.h" +#include "RimEclipseCaseEnsemble.h" #include "RimGridCalculationVariable.h" #include "RimUserDefinedCalculation.h" @@ -56,6 +57,7 @@ class RimGridCalculation : public RimUserDefinedCalculation { NONE, GRID_CASE_GROUP, + ENSEMBLE, ALL_CASES }; @@ -146,6 +148,7 @@ class RimGridCalculation : public RimUserDefinedCalculation caf::PdmField> m_additionalCasesType; caf::PdmPtrField m_additionalCaseGroup; + caf::PdmPtrField m_additionalEnsemble; caf::PdmField> m_selectedTimeSteps;