From de118ddae2abea825278b56b4aa5b024bec2c949 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 13 Feb 2023 13:54:43 +0100 Subject: [PATCH] #9833: Add extra check based on value/cells count Some models do not have the dual porosity flag set correctly. Add additional check to set the dual porosity flag if the number of active cells is the double of main grid cell count. --- .../FileInterface/RifActiveCellsReader.cpp | 21 +++++++++++++------ .../FileInterface/RifActiveCellsReader.h | 3 ++- .../FileInterface/RifReaderEclipseOutput.cpp | 12 +++++++---- .../UnitTests/RifActiveCellsReader-Test.cpp | 3 ++- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifActiveCellsReader.cpp b/ApplicationLibCode/FileInterface/RifActiveCellsReader.cpp index 7aeeb9d5cb..96a52c7690 100644 --- a/ApplicationLibCode/FileInterface/RifActiveCellsReader.cpp +++ b/ApplicationLibCode/FileInterface/RifActiveCellsReader.cpp @@ -53,7 +53,8 @@ std::vector> RifActiveCellsReader::activeCellsFromActnumKeyword /// //-------------------------------------------------------------------------------------------------- std::vector> RifActiveCellsReader::activeCellsFromPorvKeyword( const ecl_file_type* ecl_file, - bool dualPorosity ) + bool dualPorosity, + const int cellCountMainGrid ) { CAF_ASSERT( ecl_file ); @@ -64,19 +65,27 @@ std::vector> RifActiveCellsReader::activeCellsFromPorvKeyword( // // See documentation of active cells in top of ecl_grid.cpp + bool divideCellCountByTwo = dualPorosity; + int porvKeywordCount = ecl_file_get_num_named_kw( ecl_file, PORV_KW ); for ( size_t gridIdx = 0; gridIdx < static_cast( porvKeywordCount ); gridIdx++ ) { std::vector porvValues; RifEclipseOutputFileTools::keywordData( ecl_file, PORV_KW, gridIdx, &porvValues ); - std::vector activeCellsOneGrid; - size_t activeCellCount = porvValues.size(); - if ( dualPorosity ) + + // For some cases, the dual porosity flag is not interpreted correctly. Add a fallback by checking the number of + // cells in the main grid + // https://github.com/OPM/ResInsight/issues/9833 + if ( ( gridIdx == 0 ) && ( activeCellCount == cellCountMainGrid * 2 ) ) divideCellCountByTwo = true; + + if ( divideCellCountByTwo ) { activeCellCount /= 2; } + + std::vector activeCellsOneGrid; activeCellsOneGrid.resize( activeCellCount, 0 ); for ( size_t poreValueIndex = 0; poreValueIndex < porvValues.size(); poreValueIndex++ ) @@ -129,10 +138,10 @@ void RifActiveCellsReader::applyActiveCellsToAllGrids( ecl_grid_type* currentGrid = ecl_grid_iget_lgr( ecl_main_grid, gridIndex - 1 ); } - auto activeCellsForGrid = activeCellsForAllGrids[gridIndex]; + const auto& activeCellsForGrid = activeCellsForAllGrids[gridIndex]; CAF_ASSERT( ecl_grid_get_global_size( currentGrid ) == static_cast( activeCellsForGrid.size() ) ); - int* actnum_values = activeCellsForGrid.data(); + auto actnum_values = activeCellsForGrid.data(); ecl_grid_reset_actnum( currentGrid, actnum_values ); } diff --git a/ApplicationLibCode/FileInterface/RifActiveCellsReader.h b/ApplicationLibCode/FileInterface/RifActiveCellsReader.h index 0eba9452b9..4b116e47cf 100644 --- a/ApplicationLibCode/FileInterface/RifActiveCellsReader.h +++ b/ApplicationLibCode/FileInterface/RifActiveCellsReader.h @@ -32,7 +32,8 @@ class RifActiveCellsReader public: static std::vector> activeCellsFromActnumKeyword( const ecl_file_type* ecl_file ); - static std::vector> activeCellsFromPorvKeyword( const ecl_file_type* ecl_file, bool dualPorosity ); + static std::vector> + activeCellsFromPorvKeyword( const ecl_file_type* ecl_file, bool dualPorosity, const int cellCountMainGrid ); static void applyActiveCellsToAllGrids( ecl_grid_type* ecl_main_grid, const std::vector>& activeCellsForAllGrids ); diff --git a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp index edea05b7ab..9d286cc3ad 100644 --- a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp @@ -840,8 +840,10 @@ bool RifReaderEclipseOutput::readActiveCellInfo() ecl_file_open( RiaStringEncodingTools::toNativeEncoded( initFileName ).data(), ECL_FILE_CLOSE_STREAM ); if ( ecl_file ) { - bool isDualPorosity = m_eclipseCase->mainGrid()->isDualPorosity(); - actnumValuesPerGrid = RifActiveCellsReader::activeCellsFromPorvKeyword( ecl_file, isDualPorosity ); + bool isDualPorosity = m_eclipseCase->mainGrid()->isDualPorosity(); + int cellCountMainGrid = static_cast( m_eclipseCase->mainGrid()->cellCount() ); + actnumValuesPerGrid = + RifActiveCellsReader::activeCellsFromPorvKeyword( ecl_file, isDualPorosity, cellCountMainGrid ); ecl_file_close( ecl_file ); } } @@ -2330,8 +2332,10 @@ ecl_grid_type* RifReaderEclipseOutput::loadAllGrids() const // TODO : ecl_grid_alloc() will automatically read ACTNUM from EGRID file, and reading of active cell // information can be skipped if PORV is available - bool isDualPorosity = ecl_grid_dual_grid( mainEclGrid ); - auto activeCells = RifActiveCellsReader::activeCellsFromPorvKeyword( m_ecl_init_file, isDualPorosity ); + bool isDualPorosity = ecl_grid_dual_grid( mainEclGrid ); + auto cellCountMainGrid = ecl_grid_get_global_size( mainEclGrid ); + auto activeCells = + RifActiveCellsReader::activeCellsFromPorvKeyword( m_ecl_init_file, isDualPorosity, cellCountMainGrid ); if ( !activeCells.empty() ) { diff --git a/ApplicationLibCode/UnitTests/RifActiveCellsReader-Test.cpp b/ApplicationLibCode/UnitTests/RifActiveCellsReader-Test.cpp index dcfddb0dce..2052d8a29a 100644 --- a/ApplicationLibCode/UnitTests/RifActiveCellsReader-Test.cpp +++ b/ApplicationLibCode/UnitTests/RifActiveCellsReader-Test.cpp @@ -65,7 +65,8 @@ TEST( RifActiveCellsReaderTest, BasicTest10k ) ecl_file_type* initFile = ecl_file_open( RiaStringEncodingTools::toNativeEncoded( filePath ).data(), ECL_FILE_CLOSE_STREAM ); - activeCellsFromPorv = RifActiveCellsReader::activeCellsFromPorvKeyword( initFile, false ); + int cellCountMainGrid = 0; + activeCellsFromPorv = RifActiveCellsReader::activeCellsFromPorvKeyword( initFile, false, cellCountMainGrid ); EXPECT_EQ( 2, (int)activeCellsFromPorv.size() ); ecl_file_close( initFile );