From 46515b107fa902a5485307a4843cdb1525f923a8 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 3 Jan 2025 12:21:45 +0100 Subject: [PATCH] #12021 Wrong calculation of INDEX_IJK INDEX_I INDEX_J INDEX_K are result properties computed by ResInsight. When using opm-common, only active cells are defined. In this situation, the computation fails. Change the implementation to compute these values only for active cells. This will also improve performance and use less memory. --- .../RigIndexIjkResultCalculator.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigIndexIjkResultCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigIndexIjkResultCalculator.cpp index e93c0446b5..b8557da0f2 100644 --- a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigIndexIjkResultCalculator.cpp +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigIndexIjkResultCalculator.cpp @@ -55,8 +55,8 @@ bool RigIndexIjkResultCalculator::isMatching( const RigEclipseResultAddress& res //-------------------------------------------------------------------------------------------------- void RigIndexIjkResultCalculator::calculate( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ) { - size_t reservoirCellCount = m_resultsData->activeCellInfo()->reservoirCellCount(); - if ( reservoirCellCount == 0 ) return; + size_t activeCellCount = m_resultsData->activeCellInfo()->reservoirActiveCellCount(); + if ( activeCellCount == 0 ) return; size_t iResultIndex = m_resultsData->findScalarResultIndexFromAddress( RiaResultNames::staticIntegerAddress( RiaResultNames::indexIResultName() ) ); @@ -76,40 +76,40 @@ void RigIndexIjkResultCalculator::calculate( const RigEclipseResultAddress& resV std::vector>& indexK = m_resultsData->m_cellScalarResults[kResultIndex]; if ( indexI.empty() ) indexI.resize( 1 ); - if ( indexI[0].size() < reservoirCellCount ) + if ( indexI[0].size() < activeCellCount ) { - indexI[0].resize( reservoirCellCount, std::numeric_limits::infinity() ); + indexI[0].resize( activeCellCount, std::numeric_limits::infinity() ); computeIndexI = true; } if ( indexJ.empty() ) indexJ.resize( 1 ); - if ( indexJ[0].size() < reservoirCellCount ) + if ( indexJ[0].size() < activeCellCount ) { - indexJ[0].resize( reservoirCellCount, std::numeric_limits::infinity() ); + indexJ[0].resize( activeCellCount, std::numeric_limits::infinity() ); computeIndexJ = true; } if ( indexK.empty() ) indexK.resize( 1 ); - if ( indexK[0].size() < reservoirCellCount ) + if ( indexK[0].size() < activeCellCount ) { - indexK[0].resize( reservoirCellCount, std::numeric_limits::infinity() ); + indexK[0].resize( activeCellCount, std::numeric_limits::infinity() ); computeIndexK = true; } if ( !( computeIndexI || computeIndexJ || computeIndexK ) ) return; - const auto mainGrid = m_resultsData->m_ownerMainGrid; - long long numCells = static_cast( mainGrid->totalCellCount() ); + const auto mainGrid = m_resultsData->m_ownerMainGrid; + const auto activeCells = m_resultsData->activeCellInfo()->activeReservoirCellIndices(); #pragma omp parallel for - for ( long long cellIdx = 0; cellIdx < numCells; cellIdx++ ) + for ( int activeIndex = 0; activeIndex < static_cast( activeCells.size() ); activeIndex++ ) { + auto cellIdx = activeCells[activeIndex]; + if ( cellIdx == cvf::UNDEFINED_SIZE_T ) continue; + const RigCell& cell = mainGrid->cell( cellIdx ); if ( cell.isInvalid() ) continue; - size_t resultIndex = cellIdx; - if ( resultIndex == cvf::UNDEFINED_SIZE_T ) continue; - bool isTemporaryGrid = cell.hostGrid()->isTempGrid(); size_t gridLocalNativeCellIndex = cell.gridLocalCellIndex(); @@ -121,17 +121,17 @@ void RigIndexIjkResultCalculator::calculate( const RigEclipseResultAddress& resV // I/J/K is 1-indexed when shown to user, thus "+ 1" if ( computeIndexI || isTemporaryGrid ) { - indexI[0][resultIndex] = i + 1; + indexI[0][activeIndex] = i + 1; } if ( computeIndexJ || isTemporaryGrid ) { - indexJ[0][resultIndex] = j + 1; + indexJ[0][activeIndex] = j + 1; } if ( computeIndexK || isTemporaryGrid ) { - indexK[0][resultIndex] = k + 1; + indexK[0][activeIndex] = k + 1; } } }