Files
ResInsight/ApplicationLibCode/UserInterface/RiuRelativePermeabilityPlotUpdater.cpp
T

231 lines
11 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 "RiuRelativePermeabilityPlotUpdater.h"
#include "Riu3dSelectionManager.h"
#include "RiuRelativePermeabilityPlotPanel.h"
#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
2023-05-11 08:37:58 +02:00
#include "RigEclipseResultAddress.h"
#include "RigGridBase.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "Rim2dIntersectionView.h"
2018-01-09 10:11:28 +01:00
#include "Rim3dView.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimExtrudedCurveIntersection.h"
2023-04-13 07:05:53 +02:00
// #include "cvfTrace.h"
2017-11-30 08:49:21 +01:00
#include <cmath>
//==================================================================================================
///
/// \class RiuRelativePermeabilityPlotUpdater
///
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuRelativePermeabilityPlotUpdater::RiuRelativePermeabilityPlotUpdater( RiuRelativePermeabilityPlotPanel* targetPlotPanel )
: m_targetPlotPanel( targetPlotPanel )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2025-02-25 14:58:33 +01:00
void RiuRelativePermeabilityPlotUpdater::clearPlot()
{
2025-02-25 14:58:33 +01:00
if ( m_targetPlotPanel ) m_targetPlotPanel->clearPlot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2025-02-25 14:58:33 +01:00
QWidget* RiuRelativePermeabilityPlotUpdater::plotPanel()
{
2025-02-25 14:58:33 +01:00
return m_targetPlotPanel;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuRelativePermeabilityPlotUpdater::queryDataAndUpdatePlot( const RimEclipseResultDefinition* eclipseResDef,
size_t timeStepIndex,
size_t gridIndex,
2025-02-25 14:58:33 +01:00
size_t gridLocalCellIndex )
{
2025-02-25 14:58:33 +01:00
if ( m_targetPlotPanel == nullptr ) return false;
2020-01-06 10:41:11 +01:00
if ( !eclipseResDef ) return false;
if ( eclipseResDef->porosityModel() == RiaDefines::PorosityModelType::FRACTURE_MODEL )
{
// Fracture model is currently not supported. If a dual porosity model is present, the PORV values
// for the matrix model is used. It will require some changes in the flow diagnostics module to be
// able support fracture model plotting.
return false;
}
RimEclipseResultCase* eclipseResultCase = dynamic_cast<RimEclipseResultCase*>( eclipseResDef->eclipseCase() );
RigEclipseCaseData* eclipseCaseData = eclipseResultCase ? eclipseResultCase->eclipseCaseData() : nullptr;
if ( eclipseResultCase && eclipseCaseData && eclipseResultCase->flowDiagSolverInterface() )
{
size_t activeCellIndex = CellLookupHelper::mapToActiveCellIndex( eclipseCaseData, gridIndex, gridLocalCellIndex );
if ( activeCellIndex != cvf::UNDEFINED_SIZE_T )
{
// cvf::Trace::show("Updating RelPerm plot for active cell index: %d", static_cast<int>(activeCellIndex));
std::vector<RigFlowDiagSolverInterface::RelPermCurve> relPermCurveArr =
eclipseResultCase->flowDiagSolverInterface()->calculateRelPermCurves( activeCellIndex );
// Make sure we load the results that we'll query below
2023-02-26 10:48:40 +01:00
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
2020-04-23 23:25:22 +02:00
cellResultsData->ensureKnownResultLoaded(
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE, RiaResultNames::swat() ) );
2020-04-23 23:25:22 +02:00
cellResultsData->ensureKnownResultLoaded(
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE, RiaResultNames::sgas() ) );
2023-02-26 10:48:40 +01:00
cellResultsData->ensureKnownResultLoaded( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, "SATNUM" ) );
// Fetch SWAT and SGAS cell values for the selected cell
cvf::ref<RigResultAccessor> swatAccessor =
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
gridIndex,
2020-04-24 06:53:06 +02:00
RiaDefines::PorosityModelType::MATRIX_MODEL,
timeStepIndex,
2020-04-23 23:25:22 +02:00
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE,
RiaResultNames::swat() ) );
cvf::ref<RigResultAccessor> sgasAccessor =
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
gridIndex,
2020-04-24 06:53:06 +02:00
RiaDefines::PorosityModelType::MATRIX_MODEL,
timeStepIndex,
2020-04-23 23:25:22 +02:00
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE,
RiaResultNames::sgas() ) );
cvf::ref<RigResultAccessor> satnumAccessor =
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
gridIndex,
2020-04-24 06:53:06 +02:00
RiaDefines::PorosityModelType::MATRIX_MODEL,
timeStepIndex,
2020-04-23 23:25:22 +02:00
RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE,
"SATNUM" ) );
2023-02-26 10:48:40 +01:00
const double cellSWAT = swatAccessor.notNull() ? swatAccessor->cellScalar( gridLocalCellIndex ) : HUGE_VAL;
const double cellSGAS = sgasAccessor.notNull() ? sgasAccessor->cellScalar( gridLocalCellIndex ) : HUGE_VAL;
const double cellSATNUM = satnumAccessor.notNull() ? satnumAccessor->cellScalar( gridLocalCellIndex ) : HUGE_VAL;
// cvf::Trace::show("cellSWAT = %f cellSGAS = %f cellSATNUM = %f", cellSWAT, cellSGAS, cellSATNUM);
2023-02-26 10:48:40 +01:00
QString cellRefText = constructCellReferenceText( eclipseCaseData, gridIndex, gridLocalCellIndex, "SATNUM", cellSATNUM );
QString caseName = eclipseResultCase->caseUserDescription();
2025-02-25 14:58:33 +01:00
m_targetPlotPanel->setPlotData( eclipseCaseData->unitsType(), relPermCurveArr, cellSWAT, cellSGAS, caseName, cellRefText );
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuRelativePermeabilityPlotUpdater::constructCellReferenceText( const RigEclipseCaseData* eclipseCaseData,
size_t gridIndex,
size_t gridLocalCellIndex,
const QString& valueName,
double cellValue )
{
const size_t gridCount = eclipseCaseData ? eclipseCaseData->gridCount() : 0;
const RigGridBase* grid = gridIndex < gridCount ? eclipseCaseData->grid( gridIndex ) : nullptr;
if ( grid && gridLocalCellIndex < grid->cellCount() )
{
size_t i = 0;
size_t j = 0;
size_t k = 0;
if ( grid->ijkFromCellIndex( gridLocalCellIndex, &i, &j, &k ) )
{
// Adjust to 1-based Eclipse indexing
i++;
j++;
k++;
QString retText;
if ( gridIndex == 0 )
{
retText = QString( "Cell: [%1, %2, %3]" ).arg( i ).arg( j ).arg( k );
}
else
{
retText = QString( "LGR %1, Cell: [%2, %3, %4]" ).arg( gridIndex ).arg( i ).arg( j ).arg( k );
}
if ( cellValue != HUGE_VAL )
{
retText += QString( " (%1=%2)" ).arg( valueName ).arg( cellValue );
}
return retText;
}
}
return QString();
}
//==================================================================================================
//
//
//
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-02-26 10:48:40 +01:00
size_t CellLookupHelper::mapToActiveCellIndex( const RigEclipseCaseData* eclipseCaseData, size_t gridIndex, size_t gridLocalCellIndex )
{
const size_t gridCount = eclipseCaseData ? eclipseCaseData->gridCount() : 0;
const RigGridBase* grid = gridIndex < gridCount ? eclipseCaseData->grid( gridIndex ) : nullptr;
if ( grid && gridLocalCellIndex < grid->cellCount() )
{
// Note!!
// Which type of porosity model to choose? Currently hard-code to MATRIX_MODEL
2023-02-26 10:48:40 +01:00
const RigActiveCellInfo* activeCellInfo = eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL );
CVF_ASSERT( activeCellInfo );
const size_t reservoirCellIndex = grid->reservoirCellIndex( gridLocalCellIndex );
const size_t activeCellIndex = activeCellInfo->cellResultIndex( reservoirCellIndex );
return activeCellIndex;
}
return cvf::UNDEFINED_SIZE_T;
}