Skip to content

Commit

Permalink
Refactor: split out per case accumulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Dec 9, 2024
1 parent 31d5a34 commit bd4faee
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> occupancy( targetNumActiveCells, 0 );
std::vector<int> occupancy;

std::map<QString, std::vector<std::vector<double>>> resultNamesAndSamples;
resultNamesAndSamples["TOTAL_PORV_SOIL"] = {};
Expand All @@ -715,74 +709,30 @@ 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<double>& clusterNum = resultsData->cellScalarResults( clustersNumAddress, 0 );

std::map<QString, const std::vector<double>*> namedInputVector;

for ( auto [resultName, vec] : resultNamesAndSamples )
{
RigEclipseResultAddress resultAddress( RiaDefines::ResultCatType::GENERATED, resultName );
resultsData->ensureKnownResultLoaded( resultAddress );
const std::vector<double>& resultVector = resultsData->cellScalarResults( resultAddress, 0 );
namedInputVector[resultName] = &resultVector;
}

std::map<QString, std::vector<double>> namedOutputVector;
for ( auto [resultName, vec] : resultNamesAndSamples )
{
namedOutputVector[resultName] = std::vector( targetNumActiveCells, std::numeric_limits<double>::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 );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigWellTargetCandidatesGenerator::computeStatisticsAndCreateVectors( RimEclipseCase& targetCase,
size_t targetNumActiveCells,
const QString& resultName,
const std::vector<std::vector<double>>& 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<int>( targetNumActiveCells );
std::vector<double> p10Results( nCells, std::numeric_limits<double>::infinity() );
std::vector<double> p50Results( nCells, std::numeric_limits<double>::infinity() );
Expand Down Expand Up @@ -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<QString, std::vector<std::vector<double>>>& resultNamesAndSamples,
std::vector<int>& 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<double>& clusterNum = resultsData->cellScalarResults( clustersNumAddress, 0 );

std::map<QString, const std::vector<double>*> namedInputVector;

for ( auto [resultName, vec] : resultNamesAndSamples )
{
RigEclipseResultAddress resultAddress( RiaDefines::ResultCatType::GENERATED, resultName );
resultsData->ensureKnownResultLoaded( resultAddress );
const std::vector<double>& resultVector = resultsData->cellScalarResults( resultAddress, 0 );
namedInputVector[resultName] = &resultVector;
}

std::map<QString, std::vector<double>> namedOutputVector;
for ( auto [resultName, vec] : resultNamesAndSamples )
{
namedOutputVector[resultName] = std::vector( targetNumActiveCells, std::numeric_limits<double>::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] );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "cvfStructGrid.h"

#include <map>
#include <optional>

class RigActiveCellInfo;
Expand Down Expand Up @@ -192,7 +193,11 @@ class RigWellTargetCandidatesGenerator
const QString& clusterResultName );

static void computeStatisticsAndCreateVectors( RimEclipseCase& targetCase,
size_t targetNumActiveCells,
const QString& resultName,
const std::vector<std::vector<double>>& vec );

static void accumulateResultsForSingleCase( RimEclipseCase& eclipseCase,
RimEclipseCase& targetCase,
std::map<QString, std::vector<std::vector<double>>>& resultNamesAndSamples,
std::vector<int>& occupancy );
};

0 comments on commit bd4faee

Please sign in to comment.