diff --git a/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.cpp b/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.cpp index baeb7caf44..c05ff2c9bf 100644 --- a/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.cpp +++ b/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.cpp @@ -696,13 +696,7 @@ void RigWellTargetCandidatesGenerator::generateEnsembleCandidates( RimEclipseCas generateCandidates( eclipseCase, timeStepIdx, volumeType, volumesType, volumeResultType, limits ); } - const RigCaseCellResultsData* targetResultsData = targetCase.results( RiaDefines::PorosityModelType::MATRIX_MODEL ); - const RigActiveCellInfo* targetActiveCellInfo = targetResultsData->activeCellInfo(); - - const size_t targetNumReservoirCells = targetActiveCellInfo->reservoirCellCount(); - const size_t targetNumActiveCells = targetActiveCellInfo->reservoirActiveCellCount(); - - std::vector occupancy( targetNumActiveCells, 0 ); + std::vector occupancy; std::map>> resultNamesAndSamples; resultNamesAndSamples["TOTAL_PORV_SOIL"] = {}; @@ -715,63 +709,14 @@ void RigWellTargetCandidatesGenerator::generateEnsembleCandidates( RimEclipseCas { auto task = progInfo.task( "Accumulating results.", 1 ); - RigCaseCellResultsData* resultsData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); - const RigMainGrid* mainGrid = eclipseCase->mainGrid(); - const RigActiveCellInfo* activeCellInfo = resultsData->activeCellInfo(); - - RigEclipseResultAddress clustersNumAddress( RiaDefines::ResultCatType::GENERATED, "CLUSTERS_NUM" ); - resultsData->ensureKnownResultLoaded( clustersNumAddress ); - const std::vector& clusterNum = resultsData->cellScalarResults( clustersNumAddress, 0 ); - - std::map*> namedInputVector; - - for ( auto [resultName, vec] : resultNamesAndSamples ) - { - RigEclipseResultAddress resultAddress( RiaDefines::ResultCatType::GENERATED, resultName ); - resultsData->ensureKnownResultLoaded( resultAddress ); - const std::vector& resultVector = resultsData->cellScalarResults( resultAddress, 0 ); - namedInputVector[resultName] = &resultVector; - } - - std::map> namedOutputVector; - for ( auto [resultName, vec] : resultNamesAndSamples ) - { - namedOutputVector[resultName] = std::vector( targetNumActiveCells, std::numeric_limits::infinity() ); - } - - for ( size_t targetCellIdx = 0; targetCellIdx < targetNumReservoirCells; targetCellIdx++ ) - { - const RigCell& nativeCell = targetCase.mainGrid()->cell( targetCellIdx ); - cvf::Vec3d cellCenter = nativeCell.center(); - - size_t targetResultIndex = targetActiveCellInfo->cellResultIndex( targetCellIdx ); - - size_t cellIdx = mainGrid->findReservoirCellIndexFromPoint( cellCenter ); - if ( cellIdx != cvf::UNDEFINED_SIZE_T && activeCellInfo->isActive( cellIdx ) && targetResultIndex != cvf::UNDEFINED_SIZE_T ) - { - size_t resultIndex = resultsData->activeCellInfo()->cellResultIndex( cellIdx ); - if ( !std::isinf( clusterNum[resultIndex] ) && clusterNum[resultIndex] > 0 ) - { - occupancy[targetResultIndex]++; - for ( auto [resultName, vec] : resultNamesAndSamples ) - { - namedOutputVector[resultName][targetResultIndex] = namedInputVector[resultName]->at( resultIndex ); - } - } - } - } - - for ( auto [resultName, vec] : resultNamesAndSamples ) - { - resultNamesAndSamples[resultName].push_back( namedOutputVector[resultName] ); - } + accumulateResultsForSingleCase( *eclipseCase, targetCase, resultNamesAndSamples, occupancy ); } createResultVector( targetCase, "OCCUPANCY", occupancy ); for ( auto [resultName, vec] : resultNamesAndSamples ) { - computeStatisticsAndCreateVectors( targetCase, targetNumActiveCells, resultName, vec ); + computeStatisticsAndCreateVectors( targetCase, resultName, vec ); } } @@ -779,10 +724,15 @@ void RigWellTargetCandidatesGenerator::generateEnsembleCandidates( RimEclipseCas /// //-------------------------------------------------------------------------------------------------- void RigWellTargetCandidatesGenerator::computeStatisticsAndCreateVectors( RimEclipseCase& targetCase, - size_t targetNumActiveCells, const QString& resultName, const std::vector>& vec ) { + const RigCaseCellResultsData* targetResultsData = targetCase.results( RiaDefines::PorosityModelType::MATRIX_MODEL ); + + const RigActiveCellInfo* targetActiveCellInfo = targetResultsData->activeCellInfo(); + + const size_t targetNumActiveCells = targetActiveCellInfo->reservoirActiveCellCount(); + int nCells = static_cast( targetNumActiveCells ); std::vector p10Results( nCells, std::numeric_limits::infinity() ); std::vector p50Results( nCells, std::numeric_limits::infinity() ); @@ -821,3 +771,72 @@ void RigWellTargetCandidatesGenerator::computeStatisticsAndCreateVectors( RimEcl createResultVector( targetCase, "ENSEMBLE_" + resultName + "_MIN", minResults ); createResultVector( targetCase, "ENSEMBLE_" + resultName + "_MAX", maxResults ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigWellTargetCandidatesGenerator::accumulateResultsForSingleCase( RimEclipseCase& eclipseCase, + RimEclipseCase& targetCase, + std::map>>& resultNamesAndSamples, + std::vector& occupancy ) +{ + RigCaseCellResultsData* resultsData = eclipseCase.results( RiaDefines::PorosityModelType::MATRIX_MODEL ); + const RigMainGrid* mainGrid = eclipseCase.mainGrid(); + const RigActiveCellInfo* activeCellInfo = resultsData->activeCellInfo(); + + const RigCaseCellResultsData* targetResultsData = targetCase.results( RiaDefines::PorosityModelType::MATRIX_MODEL ); + + const RigActiveCellInfo* targetActiveCellInfo = targetResultsData->activeCellInfo(); + + const size_t targetNumReservoirCells = targetActiveCellInfo->reservoirCellCount(); + const size_t targetNumActiveCells = targetActiveCellInfo->reservoirActiveCellCount(); + + occupancy.resize( targetNumActiveCells, 0 ); + + RigEclipseResultAddress clustersNumAddress( RiaDefines::ResultCatType::GENERATED, "CLUSTERS_NUM" ); + resultsData->ensureKnownResultLoaded( clustersNumAddress ); + const std::vector& clusterNum = resultsData->cellScalarResults( clustersNumAddress, 0 ); + + std::map*> namedInputVector; + + for ( auto [resultName, vec] : resultNamesAndSamples ) + { + RigEclipseResultAddress resultAddress( RiaDefines::ResultCatType::GENERATED, resultName ); + resultsData->ensureKnownResultLoaded( resultAddress ); + const std::vector& resultVector = resultsData->cellScalarResults( resultAddress, 0 ); + namedInputVector[resultName] = &resultVector; + } + + std::map> namedOutputVector; + for ( auto [resultName, vec] : resultNamesAndSamples ) + { + namedOutputVector[resultName] = std::vector( targetNumActiveCells, std::numeric_limits::infinity() ); + } + + for ( size_t targetCellIdx = 0; targetCellIdx < targetNumReservoirCells; targetCellIdx++ ) + { + const RigCell& nativeCell = targetCase.mainGrid()->cell( targetCellIdx ); + cvf::Vec3d cellCenter = nativeCell.center(); + + size_t targetResultIndex = targetActiveCellInfo->cellResultIndex( targetCellIdx ); + + size_t cellIdx = mainGrid->findReservoirCellIndexFromPoint( cellCenter ); + if ( cellIdx != cvf::UNDEFINED_SIZE_T && activeCellInfo->isActive( cellIdx ) && targetResultIndex != cvf::UNDEFINED_SIZE_T ) + { + size_t resultIndex = resultsData->activeCellInfo()->cellResultIndex( cellIdx ); + if ( !std::isinf( clusterNum[resultIndex] ) && clusterNum[resultIndex] > 0 ) + { + occupancy[targetResultIndex]++; + for ( auto [resultName, vec] : resultNamesAndSamples ) + { + namedOutputVector[resultName][targetResultIndex] = namedInputVector[resultName]->at( resultIndex ); + } + } + } + } + + for ( auto [resultName, vec] : resultNamesAndSamples ) + { + resultNamesAndSamples[resultName].push_back( namedOutputVector[resultName] ); + } +} diff --git a/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.h b/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.h index 0b3d6f39e7..95b5f24269 100644 --- a/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.h +++ b/ApplicationLibCode/ReservoirDataModel/Well/RigWellTargetCandidatesGenerator.h @@ -22,6 +22,7 @@ #include "cvfStructGrid.h" +#include #include class RigActiveCellInfo; @@ -192,7 +193,11 @@ class RigWellTargetCandidatesGenerator const QString& clusterResultName ); static void computeStatisticsAndCreateVectors( RimEclipseCase& targetCase, - size_t targetNumActiveCells, const QString& resultName, const std::vector>& vec ); + + static void accumulateResultsForSingleCase( RimEclipseCase& eclipseCase, + RimEclipseCase& targetCase, + std::map>>& resultNamesAndSamples, + std::vector& occupancy ); };