diff --git a/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp b/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp index 5946b814a3c..5f867123a8c 100644 --- a/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp @@ -559,16 +559,18 @@ std::vector RimGridCalculation::getDataForResult( const QString& auto eclipseCaseData = sourceCase->eclipseCaseData(); auto rigCaseCellResultsData = eclipseCaseData->results( porosityModel ); - if ( !rigCaseCellResultsData->ensureKnownResultLoaded( resAddr ) ) return {}; + if ( !rigCaseCellResultsData->findOrLoadKnownScalarResultForTimeStep( resAddr, timeStepToUse ) ) return {}; // Active cell info must always be retrieved from the destination case, as the returned vector must be of the same size as number of - // active cells in the destination case. + // active cells in the destination case. Active cells can be different between source and destination case. auto activeCellInfoDestination = destinationCase->eclipseCaseData()->activeCellInfo( porosityModel ); auto activeReservoirCells = activeCellInfoDestination->activeReservoirCellIndices(); std::vector values( activeCellInfoDestination->activeReservoirCellIndices().size() ); - auto resultAccessor = RigResultAccessorFactory::createFromResultAddress( eclipseCaseData, 0, porosityModel, timeStepToUse, resAddr ); + size_t gridIndex = 0; + auto resultAccessor = + RigResultAccessorFactory::createFromResultAddress( eclipseCaseData, gridIndex, porosityModel, timeStepToUse, resAddr ); #pragma omp parallel for for ( int i = 0; i < static_cast( activeReservoirCells.size() ); i++ ) @@ -576,6 +578,11 @@ std::vector RimGridCalculation::getDataForResult( const QString& values[i] = resultAccessor->cellScalarGlobIdx( activeReservoirCells[i] ); } + auto categoriesToExclude = { RiaDefines::ResultCatType::GENERATED }; + + sourceCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->freeAllocatedResultsData( categoriesToExclude, timeStepToUse ); + sourceCase->results( RiaDefines::PorosityModelType::FRACTURE_MODEL )->freeAllocatedResultsData( categoriesToExclude, timeStepToUse ); + return values; } diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp index 2752a01fc91..1af8f1f6ab6 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -742,10 +742,14 @@ void RigCaseCellResultsData::freeAllocatedResultsData( std::vector empty; - dataForTimeStep.swap( empty ); + + if ( !dataForTimeStep.empty() ) + { + // Using swap with an empty vector as that is the safest way to really get rid of the allocated data in a + // vector + std::vector empty; + dataForTimeStep.swap( empty ); + } } } } diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h index 227ea91534b..24a917f6ed5 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -131,9 +131,12 @@ class RigCaseCellResultsData : public cvf::Object QString makeResultNameUnique( const QString& resultNameProposal ) const; bool ensureKnownResultLoaded( const RigEclipseResultAddress& resultAddress ); - bool findAndLoadResultByName( const QString& resultName, const std::vector& resultCategorySearchOrder ); + // Load result for a single time step. This can be used to process data for a single time step + // Other data access functions assume all time steps are loaded at the same time + size_t findOrLoadKnownScalarResultForTimeStep( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ); + bool hasResultEntry( const RigEclipseResultAddress& resultAddress ) const; bool isResultLoaded( const RigEclipseResultAddress& resultAddress ) const; void createResultEntry( const RigEclipseResultAddress& resultAddress, bool needsToBeStored ); @@ -167,7 +170,6 @@ class RigCaseCellResultsData : public cvf::Object friend class RigOilVolumeResultCalculator; friend class RigCellVolumeResultCalculator; friend class RigCellsWithNncsCalculator; - size_t findOrLoadKnownScalarResultForTimeStep( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ); size_t findOrCreateScalarResultIndex( const RigEclipseResultAddress& resVarAddr, bool needsToBeStored );