Skip to content

Commit

Permalink
#10523 Export sector model: Support more result categories
Browse files Browse the repository at this point in the history
Allow export of GENERATED and INPUT_PROPERTY in addition to STATIC.
  • Loading branch information
magnesj committed Aug 21, 2023
1 parent 96b3bef commit b115743
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,37 +408,33 @@ QList<caf::PdmOptionItemInfo> RicExportEclipseSectorModelUi::calculateValueOptio
QList<caf::PdmOptionItemInfo> options;
if ( fieldNeedingOptions == &selectedKeywords )
{
RigCaseCellResultsData* resultData = m_caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
QList<caf::PdmOptionItemInfo> allOptions =
RimEclipseResultDefinition::calcOptionsForVariableUiFieldStandard( RiaDefines::ResultCatType::STATIC_NATIVE, resultData );
RigCaseCellResultsData* resultData = m_caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );

std::vector<RiaDefines::ResultCatType> exportTypes = { RiaDefines::ResultCatType::STATIC_NATIVE,
RiaDefines::ResultCatType::GENERATED,
RiaDefines::ResultCatType::INPUT_PROPERTY };

QList<caf::PdmOptionItemInfo> allOptions;

for ( const auto resultCategory : exportTypes )
{
auto options = RimEclipseResultDefinition::calcOptionsForVariableUiFieldStandard( resultCategory, resultData );
allOptions.append( options );
}

std::set<QString> 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 );
}
}
}
Expand Down
36 changes: 27 additions & 9 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "RigEclipseResultAddress.h"
#include "RigFault.h"
#include "RigMainGrid.h"
#include "RigResultAccessorFactory.h"

#include "cafProgressInfo.h"

Expand Down Expand Up @@ -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<double> 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<double> resultValues = cellResultsData->cellScalarResults( resAddr )[0];
if ( resultValues.empty() ) continue;

double defaultExportValue = 0.0;
Expand All @@ -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<double> filteredResults;
filteredResults.reserve( resultValues.size() );

Expand All @@ -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
{
Expand Down

0 comments on commit b115743

Please sign in to comment.