From b1157436febe175149db8587e8aca82dbc5e0908 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 18 Aug 2023 16:14:37 +0200 Subject: [PATCH] #10523 Export sector model: Support more result categories Allow export of GENERATED and INPUT_PROPERTY in addition to STATIC. --- .../RicExportEclipseSectorModelUi.cpp | 34 ++++++++---------- .../RifEclipseInputFileTools.cpp | 36 ++++++++++++++----- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/ApplicationLibCode/Commands/ExportCommands/RicExportEclipseSectorModelUi.cpp b/ApplicationLibCode/Commands/ExportCommands/RicExportEclipseSectorModelUi.cpp index fc2ce09844..b1c67b422e 100644 --- a/ApplicationLibCode/Commands/ExportCommands/RicExportEclipseSectorModelUi.cpp +++ b/ApplicationLibCode/Commands/ExportCommands/RicExportEclipseSectorModelUi.cpp @@ -408,37 +408,33 @@ QList RicExportEclipseSectorModelUi::calculateValueOptio QList options; if ( fieldNeedingOptions == &selectedKeywords ) { - RigCaseCellResultsData* resultData = m_caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); - QList allOptions = - RimEclipseResultDefinition::calcOptionsForVariableUiFieldStandard( RiaDefines::ResultCatType::STATIC_NATIVE, resultData ); + RigCaseCellResultsData* resultData = m_caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); + + std::vector exportTypes = { RiaDefines::ResultCatType::STATIC_NATIVE, + RiaDefines::ResultCatType::GENERATED, + RiaDefines::ResultCatType::INPUT_PROPERTY }; + + QList allOptions; + + for ( const auto resultCategory : exportTypes ) + { + auto options = RimEclipseResultDefinition::calcOptionsForVariableUiFieldStandard( resultCategory, resultData ); + allOptions.append( options ); + } std::set mainKeywords = RicExportEclipseSectorModelUi::mainKeywords(); for ( const caf::PdmOptionItemInfo& option : allOptions ) { if ( mainKeywords.count( option.optionUiText() ) ) { - if ( resultData->hasResultEntry( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, option.optionUiText() ) ) ) - { - options.push_back( option ); - } + options.push_back( option ); } } for ( const caf::PdmOptionItemInfo& option : allOptions ) { if ( !mainKeywords.count( option.optionUiText() ) && option.optionUiText() != "None" ) { - if ( resultData->hasResultEntry( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, option.optionUiText() ) ) ) - { - if ( option.optionUiText() == "ACTNUM" && exportGrid() ) - { - if ( exportParameters() != EXPORT_TO_GRID_FILE ) - options.push_back( caf::PdmOptionItemInfo( "ACTNUM (included in Grid File)", "ACTNUM" ) ); - } - else - { - options.push_back( option ); - } - } + options.push_back( option ); } } } diff --git a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp index c5809f5d67..ecde23dd34 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp +++ b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp @@ -38,6 +38,7 @@ #include "RigEclipseResultAddress.h" #include "RigFault.h" #include "RigMainGrid.h" +#include "RigResultAccessorFactory.h" #include "cafProgressInfo.h" @@ -411,19 +412,30 @@ bool RifEclipseInputFileTools::exportKeywords( const QString& resul caf::ProgressInfo progress( keywords.size(), "Saving Keywords" ); - for ( const QString& keyword : keywords ) + auto allResultAddresses = cellResultsData->existingResults(); + + auto findResultAddress = [&allResultAddresses]( const QString& keyword ) -> RigEclipseResultAddress { - std::vector resultValues; + for ( const auto& adr : allResultAddresses ) + { + if ( adr.resultName() == keyword ) + { + return adr; + } + } - RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::STATIC_NATIVE, keyword ); + return {}; + }; + + for ( const QString& keyword : keywords ) + { + RigEclipseResultAddress resAddr = findResultAddress( keyword ); if ( !cellResultsData->hasResultEntry( resAddr ) ) continue; cellResultsData->ensureKnownResultLoaded( resAddr ); - CVF_ASSERT( !cellResultsData->cellScalarResults( resAddr ).empty() ); - resultValues = cellResultsData->cellScalarResults( resAddr )[0]; - CVF_ASSERT( !resultValues.empty() ); + std::vector resultValues = cellResultsData->cellScalarResults( resAddr )[0]; if ( resultValues.empty() ) continue; double defaultExportValue = 0.0; @@ -432,6 +444,11 @@ bool RifEclipseInputFileTools::exportKeywords( const QString& resul defaultExportValue = 1.0; } + RiaDefines::PorosityModelType porosityModel = RiaDefines::PorosityModelType::MATRIX_MODEL; + + // Create result accessor object for main grid at time step zero (static result date is always at first time step + auto resultAcc = RigResultAccessorFactory::createFromResultAddress( eclipseCase, 0, porosityModel, 0, resAddr ); + std::vector filteredResults; filteredResults.reserve( resultValues.size() ); @@ -445,12 +462,13 @@ bool RifEclipseInputFileTools::exportKeywords( const QString& resul { size_t mainI = i / refinement.x(); - size_t mainIndex = mainGrid->cellIndexFromIJK( mainI, mainJ, mainK ); + size_t reservoirCellIndex = mainGrid->cellIndexFromIJK( mainI, mainJ, mainK ); - size_t resIndex = activeCells->cellResultIndex( mainIndex ); + size_t resIndex = activeCells->cellResultIndex( reservoirCellIndex ); if ( resIndex != cvf::UNDEFINED_SIZE_T ) { - filteredResults.push_back( resultValues[resIndex] ); + auto value = resultAcc->cellScalarGlobIdx( reservoirCellIndex ); + filteredResults.push_back( value ); } else {