Refactor: extract cell volume computation.

This commit is contained in:
Kristian Bendiksen 2023-04-19 09:31:10 +02:00
parent 6a37c5a5d0
commit 9b78826f03
5 changed files with 132 additions and 30 deletions

View File

@ -5,6 +5,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RigMobilePoreVolumeResultCalculator.h
${CMAKE_CURRENT_LIST_DIR}/RigIndexIjkResultCalculator.h
${CMAKE_CURRENT_LIST_DIR}/RigOilVolumeResultCalculator.h
${CMAKE_CURRENT_LIST_DIR}/RigCellVolumeResultCalculator.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -14,6 +15,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RigMobilePoreVolumeResultCalculator.cpp
${CMAKE_CURRENT_LIST_DIR}/RigIndexIjkResultCalculator.cpp
${CMAKE_CURRENT_LIST_DIR}/RigOilVolumeResultCalculator.cpp
${CMAKE_CURRENT_LIST_DIR}/RigCellVolumeResultCalculator.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RigCellVolumeResultCalculator.h"
#include "RiaDefines.h"
#include "RiaResultNames.h"
#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
#include "RigCell.h"
#include "RigEclipseResultInfo.h"
#include "RigMainGrid.h"
//==================================================================================================
///
//==================================================================================================
RigCellVolumeResultCalculator::RigCellVolumeResultCalculator( RigCaseCellResultsData& resultsData )
: RigEclipseResultCalculator( resultsData )
{
}
//==================================================================================================
///
//==================================================================================================
RigCellVolumeResultCalculator::~RigCellVolumeResultCalculator()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigCellVolumeResultCalculator::isMatching( const RigEclipseResultAddress& resVarAddr ) const
{
return resVarAddr.resultName() == RiaResultNames::riCellVolumeResultName() &&
resVarAddr.resultCatType() == RiaDefines::ResultCatType::STATIC_NATIVE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCellVolumeResultCalculator::calculate( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex )
{
size_t cellVolIdx = m_resultsData->findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE,
RiaResultNames::riCellVolumeResultName() ),
false );
if ( m_resultsData->m_cellScalarResults[cellVolIdx].empty() )
{
m_resultsData->m_cellScalarResults[cellVolIdx].resize( 1 );
}
std::vector<double>& cellVolumeResults = m_resultsData->m_cellScalarResults[cellVolIdx][0];
size_t cellResultCount = m_resultsData->m_activeCellInfo->reservoirActiveCellCount();
cellVolumeResults.resize( cellResultCount, std::numeric_limits<double>::infinity() );
#pragma omp parallel for
for ( int nativeResvCellIndex = 0; nativeResvCellIndex < static_cast<int>( m_resultsData->m_ownerMainGrid->globalCellArray().size() );
nativeResvCellIndex++ )
{
size_t resultIndex = m_resultsData->activeCellInfo()->cellResultIndex( nativeResvCellIndex );
if ( resultIndex != cvf::UNDEFINED_SIZE_T )
{
const RigCell& cell = m_resultsData->m_ownerMainGrid->globalCellArray()[nativeResvCellIndex];
if ( !cell.subGrid() )
{
cellVolumeResults[resultIndex] = cell.volume();
}
}
}
// Clear oil volume so it will have to be recalculated.
m_resultsData->clearScalarResult( RiaDefines::ResultCatType::DYNAMIC_NATIVE, RiaResultNames::riOilVolumeResultName() );
}

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cstddef>
#include "RigEclipseResultCalculator.h"
class RigCaseCellResultsData;
class RigEclipseResultAddress;
//==================================================================================================
///
//==================================================================================================
class RigCellVolumeResultCalculator : public RigEclipseResultCalculator
{
public:
RigCellVolumeResultCalculator( RigCaseCellResultsData& resultsData );
~RigCellVolumeResultCalculator() override;
bool isMatching( const RigEclipseResultAddress& resVarAddr ) const override;
void calculate( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ) override;
};

View File

@ -28,6 +28,7 @@
#include "RiaResultNames.h"
#include "RigAllanDiagramData.h"
#include "RigCaseCellResultCalculator.h"
#include "RigCellVolumeResultCalculator.h"
#include "RigEclipseAllanFaultsStatCalc.h"
#include "RigEclipseCaseData.h"
#include "RigEclipseMultiPropertyStatCalc.h"
@ -2612,36 +2613,9 @@ double RigCaseCellResultsData::darchysValue()
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::computeCellVolumes()
{
size_t cellVolIdx = this->findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE,
RiaResultNames::riCellVolumeResultName() ),
false );
if ( m_cellScalarResults[cellVolIdx].empty() )
{
m_cellScalarResults[cellVolIdx].resize( 1 );
}
std::vector<double>& cellVolumeResults = m_cellScalarResults[cellVolIdx][0];
size_t cellResultCount = m_activeCellInfo->reservoirActiveCellCount();
cellVolumeResults.resize( cellResultCount, std::numeric_limits<double>::infinity() );
#pragma omp parallel for
for ( int nativeResvCellIndex = 0; nativeResvCellIndex < static_cast<int>( m_ownerMainGrid->globalCellArray().size() );
nativeResvCellIndex++ )
{
size_t resultIndex = activeCellInfo()->cellResultIndex( nativeResvCellIndex );
if ( resultIndex != cvf::UNDEFINED_SIZE_T )
{
const RigCell& cell = m_ownerMainGrid->globalCellArray()[nativeResvCellIndex];
if ( !cell.subGrid() )
{
cellVolumeResults[resultIndex] = cell.volume();
}
}
}
// Clear oil volume so it will have to be recalculated.
clearScalarResult( RiaDefines::ResultCatType::DYNAMIC_NATIVE, RiaResultNames::riOilVolumeResultName() );
RigEclipseResultAddress addr( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::riCellVolumeResultName() );
RigCellVolumeResultCalculator calculator( *this );
calculator.calculate( addr, 0 );
}
//--------------------------------------------------------------------------------------------------

View File

@ -158,6 +158,7 @@ private:
friend class RigMobilePoreVolumeResultCalculator;
friend class RigIndexIjkResultCalculator;
friend class RigOilVolumeResultCalculator;
friend class RigCellVolumeResultCalculator;
size_t findOrLoadKnownScalarResultForTimeStep( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex );
size_t findOrCreateScalarResultIndex( const RigEclipseResultAddress& resVarAddr, bool needsToBeStored );