2017-11-29 06:41:13 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-11-29 06:41:13 -06:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-11-29 06:41:13 -06:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-11-29 06:41:13 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiuPvtPlotUpdater.h"
|
|
|
|
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
#include "RigResultAccessor.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
|
2018-01-09 03:11:28 -06:00
|
|
|
#include "Rim3dView.h"
|
2017-11-29 06:41:13 -06:00
|
|
|
#include "RimEclipseResultCase.h"
|
2021-08-26 01:13:03 -05:00
|
|
|
#include "RimEclipseResultDefinition.h"
|
2017-11-29 06:41:13 -06:00
|
|
|
|
2021-08-26 01:13:03 -05:00
|
|
|
#include "Riu3dSelectionManager.h"
|
|
|
|
#include "RiuPvtPlotPanel.h"
|
|
|
|
#include "RiuRelativePermeabilityPlotUpdater.h"
|
2017-11-29 06:41:13 -06:00
|
|
|
|
2017-11-30 01:49:21 -06:00
|
|
|
#include <cmath>
|
2017-11-29 06:41:13 -06:00
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
///
|
|
|
|
/// \class RiuPvtPlotUpdater
|
|
|
|
///
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-29 06:41:13 -06:00
|
|
|
///
|
|
|
|
//==================================================================================================
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-29 06:41:13 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RiuPvtPlotUpdater::RiuPvtPlotUpdater( RiuPvtPlotPanel* targetPlotPanel )
|
|
|
|
: m_targetPlotPanel( targetPlotPanel )
|
2019-11-27 09:03:21 -06:00
|
|
|
, m_viewToFollowAnimationFrom( nullptr )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-29 06:41:13 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuPvtPlotUpdater::updateOnSelectionChanged( const RiuSelectionItem* selectionItem )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_targetPlotPanel )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:03:21 -06:00
|
|
|
Rim3dView* newFollowAnimView = nullptr;
|
|
|
|
RiuEclipseSelectionItem* eclipseSelectionItem = nullptr;
|
2017-11-29 06:41:13 -06:00
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
eclipseSelectionItem =
|
|
|
|
RiuRelativePermeabilityPlotUpdater::extractEclipseSelectionItem( selectionItem, newFollowAnimView );
|
2018-02-06 07:39:38 -06:00
|
|
|
|
2019-11-27 09:03:21 -06:00
|
|
|
bool mustClearPlot = true;
|
|
|
|
m_viewToFollowAnimationFrom = nullptr;
|
2017-11-29 06:41:13 -06:00
|
|
|
|
2020-01-06 03:41:11 -06:00
|
|
|
if ( m_targetPlotPanel->isVisible() && eclipseSelectionItem && eclipseSelectionItem->m_resultDefinition )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2019-11-27 09:03:21 -06:00
|
|
|
if ( queryDataAndUpdatePlot( eclipseSelectionItem->m_resultDefinition,
|
|
|
|
eclipseSelectionItem->m_timestepIdx,
|
|
|
|
eclipseSelectionItem->m_gridIndex,
|
|
|
|
eclipseSelectionItem->m_gridLocalCellIndex,
|
|
|
|
m_targetPlotPanel ) )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2019-11-27 09:03:21 -06:00
|
|
|
mustClearPlot = false;
|
|
|
|
|
|
|
|
m_viewToFollowAnimationFrom = newFollowAnimView;
|
2017-11-29 06:41:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( mustClearPlot )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
|
|
|
m_targetPlotPanel->clearPlot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-29 06:41:13 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuPvtPlotUpdater::updateOnTimeStepChanged( Rim3dView* changedView )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_targetPlotPanel || !m_targetPlotPanel->isVisible() )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:03:21 -06:00
|
|
|
// Don't update the plot if the view that changed time step is different
|
|
|
|
// from the view that was the source of the current plot
|
|
|
|
|
|
|
|
if ( changedView != m_viewToFollowAnimationFrom )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the current global selection and only continue if the selection's view matches the view with time step change
|
2019-11-27 09:03:21 -06:00
|
|
|
|
|
|
|
const RiuSelectionItem* selectionItem = Riu3dSelectionManager::instance()->selectedItem();
|
|
|
|
Rim3dView* newFollowAnimView = nullptr;
|
|
|
|
RiuEclipseSelectionItem* eclipseSelectionItem = nullptr;
|
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
eclipseSelectionItem =
|
|
|
|
RiuRelativePermeabilityPlotUpdater::extractEclipseSelectionItem( selectionItem, newFollowAnimView );
|
2019-11-27 09:03:21 -06:00
|
|
|
|
|
|
|
if ( eclipseSelectionItem && newFollowAnimView == changedView )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2019-11-27 09:03:21 -06:00
|
|
|
if ( !queryDataAndUpdatePlot( eclipseSelectionItem->m_resultDefinition,
|
|
|
|
newFollowAnimView->currentTimeStep(),
|
|
|
|
eclipseSelectionItem->m_gridIndex,
|
|
|
|
eclipseSelectionItem->m_gridLocalCellIndex,
|
|
|
|
m_targetPlotPanel ) )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
|
|
|
m_targetPlotPanel->clearPlot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-29 06:41:13 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-27 09:03:21 -06:00
|
|
|
bool RiuPvtPlotUpdater::queryDataAndUpdatePlot( const RimEclipseResultDefinition* eclipseResDef,
|
|
|
|
size_t timeStepIndex,
|
|
|
|
size_t gridIndex,
|
|
|
|
size_t gridLocalCellIndex,
|
|
|
|
RiuPvtPlotPanel* plotPanel )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( plotPanel );
|
2017-11-29 06:41:13 -06:00
|
|
|
|
2020-01-06 03:41:11 -06:00
|
|
|
if ( !eclipseResDef ) return false;
|
|
|
|
|
2021-02-10 08:05:20 -06:00
|
|
|
RimEclipseResultCase* eclipseResultCase = dynamic_cast<RimEclipseResultCase*>( eclipseResDef->eclipseCase() );
|
|
|
|
RigEclipseCaseData* eclipseCaseData = eclipseResultCase ? eclipseResultCase->eclipseCaseData() : nullptr;
|
|
|
|
RiaDefines::PorosityModelType porosityModel = eclipseResDef->porosityModel();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( eclipseResultCase && eclipseCaseData && eclipseResultCase->flowDiagSolverInterface() )
|
2017-11-29 06:41:13 -06:00
|
|
|
{
|
2021-02-10 08:05:20 -06:00
|
|
|
// cvf::Trace::show("Update PVT plot for active cell index: %d", static_cast<int>(activeCellIndex));
|
|
|
|
|
|
|
|
// The following calls will read results from file in preparation for the queries below
|
|
|
|
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results( porosityModel );
|
|
|
|
|
|
|
|
cellResultsData->ensureKnownResultLoaded(
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE, "RS" ) );
|
|
|
|
cellResultsData->ensureKnownResultLoaded(
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE, "RV" ) );
|
|
|
|
cellResultsData->ensureKnownResultLoaded(
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE, "PRESSURE" ) );
|
|
|
|
cellResultsData->ensureKnownResultLoaded(
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, "PVTNUM" ) );
|
|
|
|
|
|
|
|
cvf::ref<RigResultAccessor> rsAccessor =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
timeStepIndex,
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE,
|
|
|
|
"RS" ) );
|
|
|
|
cvf::ref<RigResultAccessor> rvAccessor =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
timeStepIndex,
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE,
|
|
|
|
"RV" ) );
|
|
|
|
cvf::ref<RigResultAccessor> pressureAccessor =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
timeStepIndex,
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::DYNAMIC_NATIVE,
|
|
|
|
"PRESSURE" ) );
|
|
|
|
cvf::ref<RigResultAccessor> pvtnumAccessor =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
timeStepIndex,
|
|
|
|
RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE,
|
|
|
|
"PVTNUM" ) );
|
|
|
|
|
|
|
|
RiuPvtPlotPanel::CellValues cellValues;
|
|
|
|
cellValues.rs = rsAccessor.notNull() ? rsAccessor->cellScalar( gridLocalCellIndex ) : HUGE_VAL;
|
|
|
|
cellValues.rv = rvAccessor.notNull() ? rvAccessor->cellScalar( gridLocalCellIndex ) : HUGE_VAL;
|
|
|
|
cellValues.pressure = pressureAccessor.notNull() ? pressureAccessor->cellScalar( gridLocalCellIndex ) : HUGE_VAL;
|
|
|
|
|
|
|
|
const double cellPvtNumDouble = pvtnumAccessor.notNull() ? pvtnumAccessor->cellScalar( gridLocalCellIndex )
|
|
|
|
: HUGE_VAL;
|
|
|
|
|
|
|
|
const int cellPvtNum = ( cellPvtNumDouble != HUGE_VAL ) ? static_cast<int>( cellPvtNumDouble )
|
|
|
|
: std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
std::vector<RigFlowDiagSolverInterface::PvtCurve> fvfCurveArr =
|
|
|
|
eclipseResultCase->flowDiagSolverInterface()->calculatePvtCurves( RigFlowDiagSolverInterface::PVT_CT_FVF,
|
|
|
|
cellPvtNum );
|
|
|
|
std::vector<RigFlowDiagSolverInterface::PvtCurve> viscosityCurveArr =
|
|
|
|
eclipseResultCase->flowDiagSolverInterface()->calculatePvtCurves( RigFlowDiagSolverInterface::PVT_CT_VISCOSITY,
|
|
|
|
cellPvtNum );
|
|
|
|
|
|
|
|
RiuPvtPlotPanel::FvfDynProps fvfDynProps;
|
|
|
|
eclipseResultCase->flowDiagSolverInterface()->calculatePvtDynamicPropertiesFvf( cellPvtNum,
|
|
|
|
cellValues.pressure,
|
|
|
|
cellValues.rs,
|
|
|
|
cellValues.rv,
|
|
|
|
&fvfDynProps.bo,
|
|
|
|
&fvfDynProps.bg );
|
|
|
|
|
|
|
|
RiuPvtPlotPanel::ViscosityDynProps viscosityDynProps;
|
|
|
|
eclipseResultCase->flowDiagSolverInterface()->calculatePvtDynamicPropertiesViscosity( cellPvtNum,
|
|
|
|
cellValues.pressure,
|
|
|
|
cellValues.rs,
|
|
|
|
cellValues.rv,
|
|
|
|
&viscosityDynProps.mu_o,
|
|
|
|
&viscosityDynProps.mu_g );
|
|
|
|
|
|
|
|
QString cellRefText = RiuRelativePermeabilityPlotUpdater::constructCellReferenceText( eclipseCaseData,
|
|
|
|
gridIndex,
|
|
|
|
gridLocalCellIndex,
|
|
|
|
"PVTNUM",
|
|
|
|
cellPvtNumDouble );
|
|
|
|
|
|
|
|
plotPanel->setPlotData( eclipseCaseData->unitsType(),
|
|
|
|
fvfCurveArr,
|
|
|
|
viscosityCurveArr,
|
|
|
|
fvfDynProps,
|
|
|
|
viscosityDynProps,
|
|
|
|
cellValues,
|
|
|
|
cellRefText );
|
|
|
|
|
|
|
|
return true;
|
2017-11-29 06:41:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|