BCPROP: add correct number of times to properties table.

Also improved defaults.
This commit is contained in:
Kristian Bendiksen
2025-11-12 08:39:20 +01:00
parent b7a4983009
commit ba92dfb825
6 changed files with 100 additions and 59 deletions
@@ -27,6 +27,7 @@
#include "RigEclipseCaseData.h"
#include "RigEclipseCaseDataTools.h"
#include "RigEclipseResultAddress.h"
#include "RigEclipseResultTools.h"
#include "RigMainGrid.h"
#include "ProjectDataModel/Jobs/RimKeywordBcprop.h"
@@ -147,6 +148,8 @@ RicExportEclipseSectorModelUi::RicExportEclipseSectorModelUi()
m_exportFolder = defaultFolder();
CAF_PDM_InitFieldNoDefault( &m_bcpropKeywords, "BcpropKeywords", "BCPROP Keywords" );
m_bcpropKeywords.uiCapability()->setUiEditorTypeName( caf::PdmUiTableViewEditor::uiEditorTypeName() );
m_bcpropKeywords.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
CAF_PDM_InitField( &m_exportSimulationInput, "ExportSimulationInput", false, "Export Simulation Input" );
@@ -158,12 +161,6 @@ RicExportEclipseSectorModelUi::RicExportEclipseSectorModelUi()
m_exportParametersFilename = defaultResultsFileName();
m_exportFaultsFilename = defaultFaultsFileName();
// Add 10 default BCPROP keywords
for ( int i = 0; i < 10; ++i )
{
m_bcpropKeywords.push_back( new RimKeywordBcprop() );
}
m_tabNames << "Grid Data";
m_tabNames << "Parameters";
m_tabNames << "Simulation Input";
@@ -209,6 +206,21 @@ void RicExportEclipseSectorModelUi::setCaseData( RigEclipseCaseData* caseData /*
}
}
// Initialize BCPROP keywords based on max BCCON value in the grid
int maxBccon = RigEclipseResultTools::findMaxBcconValue( eclipseView ? eclipseView->eclipseCase() : nullptr );
// Clear existing keywords
m_bcpropKeywords.deleteChildren();
// Add appropriate number of BCPROP keywords (max BCCON value or default to 6 for the 6 faces)
int numKeywords = ( maxBccon > 0 ) ? maxBccon : 6;
for ( int i = 0; i < numKeywords; ++i )
{
auto* keyword = new RimKeywordBcprop();
keyword->setIndex( i + 1 ); // BCCON values start from 1, not 0
m_bcpropKeywords.push_back( keyword );
}
if ( minI == std::numeric_limits<int>::max() ) minI = static_cast<int>( m_visibleMin.x() ) + 1;
if ( minJ == std::numeric_limits<int>::max() ) minJ = static_cast<int>( m_visibleMin.y() ) + 1;
if ( minK == std::numeric_limits<int>::max() ) minK = static_cast<int>( m_visibleMin.z() ) + 1;
@@ -40,7 +40,7 @@ void caf::AppEnum<RimKeywordBcprop::Type>::setUp()
addItem( RimKeywordBcprop::Type::RATE, "RATE", "RATE" );
addItem( RimKeywordBcprop::Type::THERMAL, "THERMAL", "THERMAL" );
addItem( RimKeywordBcprop::Type::NONE, "NONE", "NONE" );
setDefault( RimKeywordBcprop::Type::NONE );
setDefault( RimKeywordBcprop::Type::FREE );
}
template <>
@@ -49,7 +49,7 @@ void caf::AppEnum<RimKeywordBcprop::Component>::setUp()
addItem( RimKeywordBcprop::Component::GAS, "GAS", "GAS" );
addItem( RimKeywordBcprop::Component::OIL, "OIL", "OIL" );
addItem( RimKeywordBcprop::Component::WATER, "WATER", "WATER" );
addItem( RimKeywordBcprop::Component::SOLVET, "SOLVET", "SOLVET" );
addItem( RimKeywordBcprop::Component::SOLVENT, "SOLVENT", "SOLVENT" );
addItem( RimKeywordBcprop::Component::POLYMER, "POLYMER", "POLYMER" );
addItem( RimKeywordBcprop::Component::MICR, "MICR", "MICR" );
addItem( RimKeywordBcprop::Component::OXYG, "OXYG", "OXYG" );
@@ -66,7 +66,7 @@ RimKeywordBcprop::RimKeywordBcprop()
{
CAF_PDM_InitObject( "BCPROP Keyword" );
CAF_PDM_InitField( &m_index, "index", 0, "Index" );
CAF_PDM_InitField( &m_type, "type", caf::AppEnum<Type>( Type::NONE ), "Type" );
CAF_PDM_InitField( &m_type, "type", caf::AppEnum<Type>( Type::FREE ), "Type" );
CAF_PDM_InitField( &m_component, "component", caf::AppEnum<Component>( Component::NONE ), "Component" );
CAF_PDM_InitField( &m_rate, "rate", 0.0, "Rate" );
CAF_PDM_InitFieldNoDefault( &m_press, "press", "Pressure" );
@@ -80,6 +80,14 @@ RimKeywordBcprop::~RimKeywordBcprop()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimKeywordBcprop::setIndex( int index )
{
m_index = index;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -104,12 +112,15 @@ Opm::DeckKeyword RimKeywordBcprop::keyword()
items.push_back( RifOpmDeckTools::item( B::INDEX::itemName, m_index() ) );
items.push_back( RifOpmDeckTools::item( B::TYPE::itemName, m_type().text().toStdString() ) );
items.push_back( RifOpmDeckTools::item( B::COMPONENT::itemName, m_component().text().toStdString() ) );
items.push_back( RifOpmDeckTools::item( B::RATE::itemName, m_rate() ) );
items.push_back( m_press().has_value() ? RifOpmDeckTools::item( B::PRESSURE::itemName, m_press().value() )
: RifOpmDeckTools::defaultItem( B::PRESSURE::itemName ) );
items.push_back( m_temp().has_value() ? RifOpmDeckTools::item( B::TEMPERATURE::itemName, m_temp().value() )
: RifOpmDeckTools::defaultItem( B::TEMPERATURE::itemName ) );
if ( m_type() != RimKeywordBcprop::Type::FREE )
{
items.push_back( RifOpmDeckTools::item( B::COMPONENT::itemName, m_component().text().toStdString() ) );
items.push_back( RifOpmDeckTools::item( B::RATE::itemName, m_rate() ) );
items.push_back( m_press().has_value() ? RifOpmDeckTools::item( B::PRESSURE::itemName, m_press().value() )
: RifOpmDeckTools::defaultItem( B::PRESSURE::itemName ) );
items.push_back( m_temp().has_value() ? RifOpmDeckTools::item( B::TEMPERATURE::itemName, m_temp().value() )
: RifOpmDeckTools::defaultItem( B::TEMPERATURE::itemName ) );
}
Opm::DeckKeyword kw( ( Opm::ParserKeywords::BCPROP() ) );
kw.addRecord( Opm::DeckRecord{ std::move( items ) } );
@@ -57,7 +57,7 @@ public:
GAS,
OIL,
WATER,
SOLVET,
SOLVENT,
POLYMER,
MICR,
OXYG,
@@ -68,6 +68,8 @@ public:
RimKeywordBcprop();
~RimKeywordBcprop() override;
void setIndex( int index );
void uiOrdering( caf::PdmUiGroup* uiGroup );
Opm::DeckKeyword keyword();
@@ -527,12 +527,10 @@ Opm::DeckKeyword bcpropKeyword( const std::vector<RigEclipseResultTools::BorderC
// Add one entry per boundary condition
for ( const auto& bc : boundaryConditions )
{
if ( bc.boundaryCondition <= 0 ) continue; // Skip entries without a valid boundary condition
// Find the corresponding property record
// The properties vector should be indexed by boundaryCondition - 1
size_t propIndex = static_cast<size_t>( bc.boundaryCondition );
if ( propIndex < boundaryConditionProperties.size() )
int propIndex = bc.boundaryCondition - 1;
if ( propIndex >= 0 && propIndex < static_cast<int>( boundaryConditionProperties.size() ) )
{
const auto& propRecord = boundaryConditionProperties[propIndex];
@@ -36,6 +36,50 @@
namespace RigEclipseResultTools
{
namespace
{
//--------------------------------------------------------------------------------------------------
/// Helper function to find maximum value in a result
//--------------------------------------------------------------------------------------------------
int findMaxResultValue( RimEclipseCase* eclipseCase, const QString& resultName, const std::vector<RiaDefines::ResultCatType>& categories )
{
if ( eclipseCase == nullptr ) return 0;
auto resultsData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
if ( !resultsData ) return 0;
// Try to find result in the provided categories
RigEclipseResultAddress resultAddr;
bool hasResult = false;
for ( const auto& category : categories )
{
RigEclipseResultAddress addr( category, RiaDefines::ResultDataType::INTEGER, resultName );
if ( resultsData->hasResultEntry( addr ) )
{
resultAddr = addr;
hasResult = true;
break;
}
}
if ( !hasResult ) return 0;
resultsData->ensureKnownResultLoaded( resultAddr );
auto resultValues = resultsData->cellScalarResults( resultAddr, 0 );
if ( resultValues.empty() ) return 0;
// Find maximum value
int maxValue = 0;
for ( double value : resultValues )
{
maxValue = std::max( maxValue, static_cast<int>( value ) );
}
return maxValue;
}
} // namespace
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -194,47 +238,19 @@ int generateOperNumResult( RimEclipseCase* eclipseCase, int borderCellValue )
//--------------------------------------------------------------------------------------------------
int findMaxOperNumValue( RimEclipseCase* eclipseCase )
{
if ( eclipseCase == nullptr ) return 0;
auto resultsData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
if ( !resultsData ) return 0;
// Try to find OPERNUM in both STATIC_NATIVE (from file) and GENERATED (created by us) categories
RigEclipseResultAddress operNumAddrNative( RiaDefines::ResultCatType::STATIC_NATIVE,
RiaDefines::ResultDataType::INTEGER,
RiaResultNames::opernum() );
RigEclipseResultAddress operNumAddrGenerated( RiaDefines::ResultCatType::GENERATED,
RiaDefines::ResultDataType::INTEGER,
RiaResultNames::opernum() );
return findMaxResultValue( eclipseCase,
RiaResultNames::opernum(),
{ RiaDefines::ResultCatType::STATIC_NATIVE, RiaDefines::ResultCatType::GENERATED } );
}
RigEclipseResultAddress operNumAddr;
bool hasOperNum = false;
if ( resultsData->hasResultEntry( operNumAddrNative ) )
{
operNumAddr = operNumAddrNative;
hasOperNum = true;
}
else if ( resultsData->hasResultEntry( operNumAddrGenerated ) )
{
operNumAddr = operNumAddrGenerated;
hasOperNum = true;
}
if ( !hasOperNum ) return 0;
resultsData->ensureKnownResultLoaded( operNumAddr );
auto operNumValues = resultsData->cellScalarResults( operNumAddr, 0 );
if ( operNumValues.empty() ) return 0;
// Find maximum value
int maxValue = 0;
for ( double value : operNumValues )
{
maxValue = std::max( maxValue, static_cast<int>( value ) );
}
return maxValue;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int findMaxBcconValue( RimEclipseCase* eclipseCase )
{
// Look for BCCON in GENERATED category
return findMaxResultValue( eclipseCase, "BCCON", { RiaDefines::ResultCatType::GENERATED } );
}
//--------------------------------------------------------------------------------------------------
@@ -51,6 +51,8 @@ int generateOperNumResult( RimEclipseCase* eclipseCase, int borderCellValue = -1
int findMaxOperNumValue( RimEclipseCase* eclipseCase );
int findMaxBcconValue( RimEclipseCase* eclipseCase );
void generateBcconResult( RimEclipseCase* eclipseCase, const cvf::Vec3st& min, const cvf::Vec3st& max );
std::vector<BorderCellFace> generateBorderCellFaces( RimEclipseCase* eclipseCase );