From 89dca9eec974b542e0e76fa0a2aadd14b999400a Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Mon, 17 Apr 2023 16:03:52 +0200 Subject: [PATCH] Refactor: extract mobile pore volume computation. --- .../ResultCalculators/CMakeLists_files.cmake | 2 + .../RigMobilePoreVolumeResultCalculator.cpp | 114 ++++++++++++++++++ .../RigMobilePoreVolumeResultCalculator.h | 38 ++++++ .../RigCaseCellResultsData.cpp | 56 +-------- .../RigCaseCellResultsData.h | 1 + 5 files changed, 159 insertions(+), 52 deletions(-) create mode 100644 ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.cpp create mode 100644 ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.h diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake index 1328990777..7a5e058597 100644 --- a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake @@ -2,12 +2,14 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultCalculator.h ${CMAKE_CURRENT_LIST_DIR}/RigSoilResultCalculator.h ${CMAKE_CURRENT_LIST_DIR}/RigFaultDistanceResultCalculator.h + ${CMAKE_CURRENT_LIST_DIR}/RigMobilePoreVolumeResultCalculator.h ) set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigSoilResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigFaultDistanceResultCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/RigMobilePoreVolumeResultCalculator.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.cpp new file mode 100644 index 0000000000..461b91f294 --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.cpp @@ -0,0 +1,114 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RigMobilePoreVolumeResultCalculator.h" +#include "RiaDefines.h" +#include "RiaResultNames.h" +#include "RigActiveCellInfo.h" +#include "RigCaseCellResultsData.h" +#include "RigCell.h" +#include "RigEclipseResultInfo.h" +#include "RigMainGrid.h" + +#include "RiaLogging.h" + +//================================================================================================== +/// +//================================================================================================== +RigMobilePoreVolumeResultCalculator::RigMobilePoreVolumeResultCalculator( RigCaseCellResultsData& resultsData ) + : RigEclipseResultCalculator( resultsData ) +{ +} + +//================================================================================================== +/// +//================================================================================================== +RigMobilePoreVolumeResultCalculator::~RigMobilePoreVolumeResultCalculator() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigMobilePoreVolumeResultCalculator::isMatching( const RigEclipseResultAddress& resVarAddr ) const +{ + return resVarAddr.resultName() == RiaResultNames::mobilePoreVolumeName() && + resVarAddr.resultCatType() == RiaDefines::ResultCatType::STATIC_NATIVE; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigMobilePoreVolumeResultCalculator::calculate( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ) +{ + std::vector porvDataTemp; + std::vector swcrDataTemp; + std::vector multpvDataTemp; + + const std::vector* porvResults = nullptr; + const std::vector* swcrResults = nullptr; + const std::vector* multpvResults = nullptr; + + porvResults = + RigCaseCellResultsData::getResultIndexableStaticResult( m_resultsData->activeCellInfo(), m_resultsData, "PORV", porvDataTemp ); + if ( !porvResults || porvResults->empty() ) + { + RiaLogging::error( "Assumed PORV, but not data was found." ); + return; + } + + swcrResults = + RigCaseCellResultsData::getResultIndexableStaticResult( m_resultsData->activeCellInfo(), m_resultsData, "SWCR", swcrDataTemp ); + multpvResults = + RigCaseCellResultsData::getResultIndexableStaticResult( m_resultsData->activeCellInfo(), m_resultsData, "MULTPV", multpvDataTemp ); + + size_t mobPVIdx = m_resultsData->findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, + RiaResultNames::mobilePoreVolumeName() ), + false ); + + std::vector& mobPVResults = m_resultsData->m_cellScalarResults[mobPVIdx][0]; + + // Set up output container to correct number of results + mobPVResults.resize( porvResults->size() ); + + if ( multpvResults && swcrResults ) + { + for ( size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx ) + { + mobPVResults[vIdx] = ( *multpvResults )[vIdx] * ( *porvResults )[vIdx] * ( 1.0 - ( *swcrResults )[vIdx] ); + } + } + else if ( !multpvResults && swcrResults ) + { + for ( size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx ) + { + mobPVResults[vIdx] = ( *porvResults )[vIdx] * ( 1.0 - ( *swcrResults )[vIdx] ); + } + } + else if ( !swcrResults && multpvResults ) + { + for ( size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx ) + { + mobPVResults[vIdx] = ( *multpvResults )[vIdx] * ( *porvResults )[vIdx]; + } + } + else + { + mobPVResults.assign( porvResults->begin(), porvResults->end() ); + } +} diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.h b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.h new file mode 100644 index 0000000000..25ac5a87dc --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigMobilePoreVolumeResultCalculator.h @@ -0,0 +1,38 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +#include "RigEclipseResultCalculator.h" + +class RigCaseCellResultsData; +class RigEclipseResultAddress; + +//================================================================================================== +/// +//================================================================================================== +class RigMobilePoreVolumeResultCalculator : public RigEclipseResultCalculator +{ +public: + RigMobilePoreVolumeResultCalculator( RigCaseCellResultsData& resultsData ); + ~RigMobilePoreVolumeResultCalculator() override; + bool isMatching( const RigEclipseResultAddress& resVarAddr ) const override; + void calculate( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ) override; +}; diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp index eb7a864d94..cbcae55d5d 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -36,6 +36,7 @@ #include "RigFaultDistanceResultCalculator.h" #include "RigFormationNames.h" #include "RigMainGrid.h" +#include "RigMobilePoreVolumeResultCalculator.h" #include "RigSoilResultCalculator.h" #include "RigStatisticsDataCache.h" #include "RigStatisticsMath.h" @@ -2762,58 +2763,9 @@ void RigCaseCellResultsData::computeOilVolumes() //-------------------------------------------------------------------------------------------------- void RigCaseCellResultsData::computeMobilePV() { - std::vector porvDataTemp; - std::vector swcrDataTemp; - std::vector multpvDataTemp; - - const std::vector* porvResults = nullptr; - const std::vector* swcrResults = nullptr; - const std::vector* multpvResults = nullptr; - - porvResults = RigCaseCellResultsData::getResultIndexableStaticResult( this->activeCellInfo(), this, "PORV", porvDataTemp ); - if ( !porvResults || porvResults->empty() ) - { - RiaLogging::error( "Assumed PORV, but not data was found." ); - return; - } - - swcrResults = RigCaseCellResultsData::getResultIndexableStaticResult( this->activeCellInfo(), this, "SWCR", swcrDataTemp ); - multpvResults = RigCaseCellResultsData::getResultIndexableStaticResult( this->activeCellInfo(), this, "MULTPV", multpvDataTemp ); - - size_t mobPVIdx = this->findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, - RiaResultNames::mobilePoreVolumeName() ), - false ); - - std::vector& mobPVResults = m_cellScalarResults[mobPVIdx][0]; - - // Set up output container to correct number of results - mobPVResults.resize( porvResults->size() ); - - if ( multpvResults && swcrResults ) - { - for ( size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx ) - { - mobPVResults[vIdx] = ( *multpvResults )[vIdx] * ( *porvResults )[vIdx] * ( 1.0 - ( *swcrResults )[vIdx] ); - } - } - else if ( !multpvResults && swcrResults ) - { - for ( size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx ) - { - mobPVResults[vIdx] = ( *porvResults )[vIdx] * ( 1.0 - ( *swcrResults )[vIdx] ); - } - } - else if ( !swcrResults && multpvResults ) - { - for ( size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx ) - { - mobPVResults[vIdx] = ( *multpvResults )[vIdx] * ( *porvResults )[vIdx]; - } - } - else - { - mobPVResults.assign( porvResults->begin(), porvResults->end() ); - } + RigEclipseResultAddress addr( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::mobilePoreVolumeName() ); + RigMobilePoreVolumeResultCalculator calculator( *this ); + calculator.calculate( addr, 0 ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h index 5d18a17041..2c989c4caa 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -155,6 +155,7 @@ private: friend class RimEclipseStatisticsCaseEvaluator; friend class RigSoilResultCalculator; friend class RigFaultDistanceResultCalculator; + friend class RigMobilePoreVolumeResultCalculator; size_t findOrLoadKnownScalarResultForTimeStep( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ); size_t findOrCreateScalarResultIndex( const RigEclipseResultAddress& resVarAddr, bool needsToBeStored );