2016-12-14 02:50:30 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- 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 "RimFlowDiagSolution.h"
2017-01-09 12:04:45 -06:00
2017-02-10 01:39:25 -06:00
# include "RiaColorTables.h"
2016-12-14 02:50:30 -06:00
2017-01-09 12:14:07 -06:00
# include "RigActiveCellInfo.h"
2016-12-20 04:41:05 -06:00
# include "RigCaseCellResultsData.h"
2017-01-10 02:51:39 -06:00
# include "RigEclipseCaseData.h"
2017-01-09 12:04:45 -06:00
# include "RigFlowDiagResults.h"
# include "RigMainGrid.h"
2017-01-09 12:51:15 -06:00
# include "RigSingleWellResultsData.h"
2017-02-10 01:39:25 -06:00
# include "RimEclipseResultCase.h"
2017-02-02 02:56:39 -06:00
# include "RimEclipseWellCollection.h"
2016-12-16 07:17:56 -06:00
2016-12-14 02:50:30 -06:00
CAF_PDM_SOURCE_INIT ( RimFlowDiagSolution , " FlowDiagSolution " ) ;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFlowDiagSolution : : RimFlowDiagSolution ( void )
{
CAF_PDM_InitObject ( " Flow Diagnostics Solution " , " " , " " , " " ) ;
//CAF_PDM_InitFieldNoDefault(&m_selectedWells, "SelectedWells", "Selected Wells","","");
CAF_PDM_InitField ( & m_userDescription , " UserDescription " , QString ( " All Wells " ) , " Description " , " " , " " , " " ) ;
2016-12-16 07:17:56 -06:00
2016-12-17 03:46:57 -06:00
2016-12-16 07:17:56 -06:00
2016-12-14 02:50:30 -06:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFlowDiagSolution : : ~ RimFlowDiagSolution ( void )
{
}
2016-12-16 07:17:56 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagResults * RimFlowDiagSolution : : flowDiagResults ( )
{
2016-12-17 03:46:57 -06:00
if ( m_flowDiagResults . isNull ( ) )
{
size_t timeStepCount ;
{
RimEclipseResultCase * eclCase ;
this - > firstAncestorOrThisOfType ( eclCase ) ;
CVF_ASSERT ( eclCase & & eclCase - > reservoirData ( ) & & eclCase - > reservoirData ( ) ) ;
timeStepCount = eclCase - > reservoirData ( ) - > results ( RifReaderInterface : : MATRIX_RESULTS ) - > maxTimeStepCount ( ) ;
}
m_flowDiagResults = new RigFlowDiagResults ( this , timeStepCount ) ;
}
2016-12-16 07:17:56 -06:00
return m_flowDiagResults . p ( ) ;
}
2016-12-14 02:50:30 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-01-03 02:27:25 -06:00
std : : vector < QString > RimFlowDiagSolution : : tracerNames ( )
2016-12-14 02:50:30 -06:00
{
RimEclipseResultCase * eclCase ;
this - > firstAncestorOrThisOfType ( eclCase ) ;
2017-01-03 02:27:25 -06:00
std : : vector < QString > tracerNameSet ;
2016-12-14 02:50:30 -06:00
if ( eclCase )
{
const cvf : : Collection < RigSingleWellResultsData > & wellResults = eclCase - > reservoirData ( ) - > wellResults ( ) ;
for ( size_t wIdx = 0 ; wIdx < wellResults . size ( ) ; + + wIdx )
{
2017-01-03 02:27:25 -06:00
tracerNameSet . push_back ( wellResults [ wIdx ] - > m_wellName ) ;
2016-12-14 02:50:30 -06:00
}
}
return tracerNameSet ;
}
2016-12-20 04:41:05 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : map < std : : string , std : : vector < int > > RimFlowDiagSolution : : allInjectorTracerActiveCellIndices ( size_t timeStepIndex )
{
return allTracerActiveCellIndices ( timeStepIndex , true ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : map < std : : string , std : : vector < int > > RimFlowDiagSolution : : allProducerTracerActiveCellIndices ( size_t timeStepIndex )
{
return allTracerActiveCellIndices ( timeStepIndex , false ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : map < std : : string , std : : vector < int > > RimFlowDiagSolution : : allTracerActiveCellIndices ( size_t timeStepIndex , bool useInjectors )
{
RimEclipseResultCase * eclCase ;
this - > firstAncestorOrThisOfType ( eclCase ) ;
std : : map < std : : string , std : : vector < int > > tracersWithCells ;
if ( eclCase )
{
const cvf : : Collection < RigSingleWellResultsData > & wellResults = eclCase - > reservoirData ( ) - > wellResults ( ) ;
RigMainGrid * mainGrid = eclCase - > reservoirData ( ) - > mainGrid ( ) ;
RigActiveCellInfo * activeCellInfo = eclCase - > reservoirData ( ) - > activeCellInfo ( RifReaderInterface : : MATRIX_RESULTS ) ; //Todo: Must come from the results definition
for ( size_t wIdx = 0 ; wIdx < wellResults . size ( ) ; + + wIdx )
{
if ( ! wellResults [ wIdx ] - > hasWellResult ( timeStepIndex ) ) continue ;
size_t wellTimeStep = wellResults [ wIdx ] - > m_resultTimeStepIndexToWellTimeStepIndex [ timeStepIndex ] ;
2017-01-11 05:34:48 -06:00
if ( wellTimeStep = = cvf : : UNDEFINED_SIZE_T ) continue ;
2016-12-20 04:41:05 -06:00
const RigWellResultFrame & wellResFrame = wellResults [ wIdx ] - > m_wellCellsTimeSteps [ wellTimeStep ] ;
if ( ! wellResFrame . m_isOpen ) continue ;
bool useWell = ( useInjectors & & ( wellResFrame . m_productionType = = RigWellResultFrame : : GAS_INJECTOR
| | wellResFrame . m_productionType = = RigWellResultFrame : : OIL_INJECTOR
| | wellResFrame . m_productionType = = RigWellResultFrame : : WATER_INJECTOR ) )
| | ( ! useInjectors & & wellResFrame . m_productionType = = RigWellResultFrame : : PRODUCER ) ;
if ( useWell )
{
std : : string wellname = wellResults [ wIdx ] - > m_wellName . toStdString ( ) ;
std : : vector < int > & tracerCells = tracersWithCells [ wellname ] ;
for ( const RigWellResultBranch & wBr : wellResFrame . m_wellResultBranches )
{
for ( const RigWellResultPoint & wrp : wBr . m_branchResultPoints )
{
if ( wrp . isValid ( ) & & wrp . m_isOpen )
{
RigGridBase * grid = mainGrid - > gridByIndex ( wrp . m_gridIndex ) ;
size_t reservoirCellIndex = grid - > reservoirCellIndex ( wrp . m_gridCellIndex ) ;
int cellActiveIndex = static_cast < int > ( activeCellInfo - > cellResultIndex ( reservoirCellIndex ) ) ;
tracerCells . push_back ( cellActiveIndex ) ;
}
}
}
}
}
}
return tracersWithCells ;
}
2016-12-14 02:50:30 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-12-21 10:14:13 -06:00
RimFlowDiagSolution : : TracerStatusType RimFlowDiagSolution : : tracerStatusOverall ( QString tracerName )
2016-12-14 02:50:30 -06:00
{
RimEclipseResultCase * eclCase ;
this - > firstAncestorOrThisOfType ( eclCase ) ;
TracerStatusType tracerStatus = UNDEFINED ;
if ( eclCase )
{
const cvf : : Collection < RigSingleWellResultsData > & wellResults = eclCase - > reservoirData ( ) - > wellResults ( ) ;
for ( size_t wIdx = 0 ; wIdx < wellResults . size ( ) ; + + wIdx )
{
2017-01-11 05:34:48 -06:00
if ( wellResults [ wIdx ] - > m_wellName = = tracerName )
2016-12-14 02:50:30 -06:00
{
2017-01-11 05:34:48 -06:00
tracerStatus = CLOSED ;
for ( const RigWellResultFrame & wellResFrame : wellResults [ wIdx ] - > m_wellCellsTimeSteps )
{
if ( wellResFrame . m_isOpen )
2016-12-14 02:50:30 -06:00
{
2017-01-11 05:34:48 -06:00
if ( wellResFrame . m_productionType = = RigWellResultFrame : : GAS_INJECTOR
| | wellResFrame . m_productionType = = RigWellResultFrame : : OIL_INJECTOR
| | wellResFrame . m_productionType = = RigWellResultFrame : : WATER_INJECTOR )
{
if ( tracerStatus = = PRODUCER ) tracerStatus = VARYING ;
else tracerStatus = INJECTOR ;
}
else if ( wellResFrame . m_productionType = = RigWellResultFrame : : PRODUCER )
{
if ( tracerStatus = = INJECTOR ) tracerStatus = VARYING ;
else tracerStatus = PRODUCER ;
}
2016-12-14 02:50:30 -06:00
}
2017-01-11 05:34:48 -06:00
if ( tracerStatus = = VARYING ) break ;
}
2016-12-14 02:50:30 -06:00
2017-01-11 05:34:48 -06:00
break ;
2016-12-14 02:50:30 -06:00
}
}
}
return tracerStatus ;
}
2016-12-21 10:14:13 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFlowDiagSolution : : TracerStatusType RimFlowDiagSolution : : tracerStatusInTimeStep ( QString tracerName , size_t timeStepIndex )
{
RimEclipseResultCase * eclCase ;
this - > firstAncestorOrThisOfType ( eclCase ) ;
if ( eclCase )
{
const cvf : : Collection < RigSingleWellResultsData > & wellResults = eclCase - > reservoirData ( ) - > wellResults ( ) ;
for ( size_t wIdx = 0 ; wIdx < wellResults . size ( ) ; + + wIdx )
{
if ( wellResults [ wIdx ] - > m_wellName = = tracerName )
{
size_t wellTimeStep = wellResults [ wIdx ] - > m_resultTimeStepIndexToWellTimeStepIndex [ timeStepIndex ] ;
2017-01-11 05:34:48 -06:00
if ( wellTimeStep = = cvf : : UNDEFINED_SIZE_T ) return CLOSED ;
2016-12-21 10:14:13 -06:00
const RigWellResultFrame & wellResFrame = wellResults [ wIdx ] - > m_wellCellsTimeSteps [ wellTimeStep ] ;
{
2017-01-11 05:34:48 -06:00
if ( ! wellResFrame . m_isOpen ) return CLOSED ;
2016-12-21 10:14:13 -06:00
if ( wellResFrame . m_productionType = = RigWellResultFrame : : GAS_INJECTOR
| | wellResFrame . m_productionType = = RigWellResultFrame : : OIL_INJECTOR
| | wellResFrame . m_productionType = = RigWellResultFrame : : WATER_INJECTOR )
{
return INJECTOR ;
}
else if ( wellResFrame . m_productionType = = RigWellResultFrame : : PRODUCER )
{
return PRODUCER ;
}
else
{
return UNDEFINED ;
}
}
}
}
}
CVF_ASSERT ( false ) ;
return UNDEFINED ;
}
2017-02-02 02:56:39 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf : : Color3f RimFlowDiagSolution : : tracerColor ( QString tracerName )
{
RimEclipseResultCase * eclCase ;
this - > firstAncestorOrThisOfType ( eclCase ) ;
if ( eclCase )
{
const cvf : : Collection < RigSingleWellResultsData > & wellResults = eclCase - > reservoirData ( ) - > wellResults ( ) ;
2017-02-10 01:39:25 -06:00
const caf : : ColorTable & colorTable = RiaColorTables : : wellsPaletteColors ( ) ;
2017-02-02 02:56:39 -06:00
for ( size_t wIdx = 0 ; wIdx < wellResults . size ( ) ; + + wIdx )
{
if ( wellResults [ wIdx ] - > m_wellName = = tracerName )
{
2017-02-10 01:39:25 -06:00
return colorTable . cycledColor3f ( wIdx ) ;
2017-02-02 02:56:39 -06:00
}
}
}
return cvf : : Color3f : : DARK_GRAY ;
}
2016-12-14 02:50:30 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf : : PdmFieldHandle * RimFlowDiagSolution : : userDescriptionField ( )
{
return & m_userDescription ;
}