diff --git a/ApplicationLibCode/ReservoirDataModel/RigEclipseResultTools.cpp b/ApplicationLibCode/ReservoirDataModel/RigEclipseResultTools.cpp index 8927b5d764..dbef57f08a 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigEclipseResultTools.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigEclipseResultTools.cpp @@ -67,8 +67,9 @@ void generateBorderResult( RimEclipseCase* eclipseCase, cvf::refeclipseCaseData()->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL )->activeReservoirCellIndices(); int numActiveCells = static_cast( activeReservoirCellIdxs.size() ); - std::vector result; - result.resize( numActiveCells, BorderType::INVISIBLE_CELL ); + size_t reservoirCellCount = + eclipseCase->eclipseCaseData()->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL )->reservoirCellCount(); + std::vector result( reservoirCellCount, BorderType::INVISIBLE_CELL ); auto grid = eclipseCase->eclipseCaseData()->mainGrid(); @@ -89,11 +90,11 @@ void generateBorderResult( RimEclipseCase* eclipseCase, cvf::refeclipseCaseData()->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL )->activeReservoirCellIndices(); - int numActiveCells = static_cast( activeReservoirCellIdxs.size() ); - - std::vector result; - result.resize( numActiveCells, 0 ); // Check if OPERNUM already exists - if so, keep existing values. RigEclipseResultAddress operNumAddrNative( RiaDefines::ResultCatType::STATIC_NATIVE, @@ -147,16 +144,17 @@ void generateOperNumResult( RimEclipseCase* eclipseCase, int borderCellValue ) hasExistingOperNum = true; } + std::vector result; + if ( hasExistingOperNum ) { resultsData->ensureKnownResultLoaded( operNumAddr ); - auto existingValues = resultsData->cellScalarResults( operNumAddr ); - if ( !existingValues.empty() ) + auto existingValues = resultsData->cellScalarResults( operNumAddr, 0 ); + result.resize( existingValues.size() ); + + for ( size_t i = 0; i < existingValues.size(); i++ ) { - for ( int i = 0; i < numActiveCells; i++ ) - { - result[i] = static_cast( existingValues[0][i] ); - } + result[i] = static_cast( existingValues[i] ); } } @@ -165,15 +163,16 @@ void generateOperNumResult( RimEclipseCase* eclipseCase, int borderCellValue ) if ( resultsData->hasResultEntry( bordNumAddr ) ) { resultsData->ensureKnownResultLoaded( bordNumAddr ); - auto bordNumValues = resultsData->cellScalarResults( bordNumAddr ); + auto bordNumValues = resultsData->cellScalarResults( bordNumAddr, 0 ); if ( !bordNumValues.empty() ) { - for ( int i = 0; i < numActiveCells; i++ ) + if ( result.empty() ) result.resize( bordNumValues.size(), 0 ); + for ( size_t activeCellIdx : activeReservoirCellIdxs ) { // If BORDNUM = 1 (BORDER_CELL), assign the border cell value - if ( static_cast( bordNumValues[0][i] ) == BorderType::BORDER_CELL ) + if ( static_cast( bordNumValues[activeCellIdx] ) == BorderType::BORDER_CELL ) { - result[i] = borderCellValue; + result[activeCellIdx] = borderCellValue; } } } @@ -219,15 +218,14 @@ int findMaxOperNumValue( RimEclipseCase* eclipseCase ) if ( !hasOperNum ) return 0; resultsData->ensureKnownResultLoaded( operNumAddr ); - auto operNumValues = resultsData->cellScalarResults( operNumAddr ); + auto operNumValues = resultsData->cellScalarResults( operNumAddr, 0 ); if ( operNumValues.empty() ) return 0; // Find maximum value int maxValue = 0; - for ( double value : operNumValues[0] ) + for ( double value : operNumValues ) { - int intValue = static_cast( value ); - maxValue = std::max( maxValue, intValue ); + maxValue = std::max( maxValue, static_cast( value ) ); } return maxValue; diff --git a/ApplicationLibCode/UnitTests/RigEclipseCaseDataTools-Test.cpp b/ApplicationLibCode/UnitTests/RigEclipseCaseDataTools-Test.cpp index 483c867c69..ed85ffa619 100644 --- a/ApplicationLibCode/UnitTests/RigEclipseCaseDataTools-Test.cpp +++ b/ApplicationLibCode/UnitTests/RigEclipseCaseDataTools-Test.cpp @@ -18,6 +18,7 @@ #include "gtest/gtest.h" +#include "RiaPorosityModel.h" #include "RiaResultNames.h" #include "RiaTestDataDirectory.h" @@ -592,7 +593,8 @@ TEST( RigEclipseCaseDataToolsTest, GenerateOperNumResultFromBorderResult ) int numActiveCells = static_cast( activeReservoirCellIdxs.size() ); std::vector customOperValues; - customOperValues.resize( numActiveCells, 5 ); // Set all to 5 initially + customOperValues.resize( eclipseCase->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL )->reservoirCellCount(), + 5 ); // Set all to 5 initially // Add some higher values to test max detection if ( numActiveCells > 10 ) {