2017-03-09 04:16:27 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicShowContributingWellsFeatureImpl.h"
2017-03-10 06:13:26 -06:00
# include "RiaApplication.h"
2017-08-17 06:49:51 -05:00
# include "RicSelectOrCreateViewFeatureImpl.h"
2017-03-10 06:13:26 -06:00
2017-03-09 04:16:27 -06:00
# include "RigFlowDiagResultAddress.h"
# include "RigSingleWellResultsData.h"
# include "RimEclipseCellColors.h"
# include "RimEclipsePropertyFilter.h"
# include "RimEclipsePropertyFilterCollection.h"
# include "RimEclipseResultCase.h"
# include "RimEclipseView.h"
# include "RimEclipseWell.h"
# include "RimEclipseWellCollection.h"
# include "RimFaultCollection.h"
2017-03-10 06:13:26 -06:00
# include "RimFlowDiagSolution.h"
# include "RimProject.h"
# include "RimViewManipulator.h"
2017-03-09 04:16:27 -06:00
# include "RiuMainWindow.h"
# include "cafCmdFeature.h"
# include "cafCmdFeatureManager.h"
2017-03-10 06:13:26 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-16 02:22:09 -05:00
RimEclipseView * RicShowContributingWellsFeatureImpl : : maniuplateSelectedView ( RimEclipseResultCase * eclipseResultCase , QString wellName , int timeStep )
2017-03-10 06:13:26 -06:00
{
2017-08-17 06:49:51 -05:00
RimEclipseView * viewToManipulate = RicSelectOrCreateViewFeatureImpl : : showViewSelection ( eclipseResultCase , " lastUsedWellAllocationView " , " Show Contributing Wells in View " ) ;
2017-03-10 06:13:26 -06:00
2017-03-10 07:45:07 -06:00
CVF_ASSERT ( viewToManipulate ) ;
2017-03-10 06:13:26 -06:00
RicShowContributingWellsFeatureImpl : : modifyViewToShowContributingWells ( viewToManipulate , wellName , timeStep ) ;
auto * feature = caf : : CmdFeatureManager : : instance ( ) - > getCommandFeature ( " RicShowMainWindowFeature " ) ;
feature - > actionTriggered ( false ) ;
2017-08-17 06:49:51 -05:00
RicSelectOrCreateViewFeatureImpl : : focusView ( viewToManipulate ) ;
2017-03-10 06:13:26 -06:00
return viewToManipulate ;
}
2017-03-09 04:16:27 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-09 16:01:45 -06:00
void RicShowContributingWellsFeatureImpl : : modifyViewToShowContributingWells ( RimEclipseView * viewToModify , const QString & wellName , int timeStep )
2017-03-09 04:16:27 -06:00
{
2017-03-10 07:45:07 -06:00
CVF_ASSERT ( viewToModify ) ;
2017-03-09 04:16:27 -06:00
RimEclipseWell * selectedWell = nullptr ;
2017-03-09 16:01:45 -06:00
for ( RimEclipseWell * w : viewToModify - > wellCollection ( ) - > wells ( ) )
2017-03-09 04:16:27 -06:00
{
if ( w - > name ( ) = = wellName )
{
selectedWell = w ;
}
}
2017-03-10 07:45:07 -06:00
CVF_ASSERT ( selectedWell ) ;
2017-03-09 04:16:27 -06:00
RimEclipseResultCase * eclipseResultCase = nullptr ;
selectedWell - > firstAncestorOrThisOfTypeAsserted ( eclipseResultCase ) ;
// Use the active flow diag solutions, or the first one as default
2017-03-09 16:01:45 -06:00
RimFlowDiagSolution * flowDiagSolution = viewToModify - > cellResult ( ) - > flowDiagSolution ( ) ;
2017-03-09 04:16:27 -06:00
if ( ! flowDiagSolution )
{
2017-03-09 16:01:45 -06:00
flowDiagSolution = eclipseResultCase - > defaultFlowDiagSolution ( ) ;
2017-03-09 04:16:27 -06:00
}
2017-03-10 07:45:07 -06:00
//assert(flowDiagSolution);
CVF_ASSERT ( flowDiagSolution ) ;
2017-03-09 04:16:27 -06:00
RimFlowDiagSolution : : TracerStatusType tracerStatus = flowDiagSolution - > tracerStatusInTimeStep ( selectedWell - > name ( ) , timeStep ) ;
if ( ! ( tracerStatus = = RimFlowDiagSolution : : INJECTOR | | tracerStatus = = RimFlowDiagSolution : : PRODUCER ) )
{
return ;
}
2017-03-09 16:01:45 -06:00
viewToModify - > setCurrentTimeStep ( timeStep ) ;
2017-06-13 08:41:52 -05:00
viewToModify - > cellResult ( ) - > setResultType ( RiaDefines : : FLOW_DIAGNOSTICS ) ;
2017-03-09 16:01:45 -06:00
viewToModify - > cellResult ( ) - > setResultVariable ( " MaxFractionTracer " ) ;
viewToModify - > cellResult ( ) - > setFlowSolution ( flowDiagSolution ) ;
2017-03-09 04:16:27 -06:00
switch ( tracerStatus )
{
case RimFlowDiagSolution : : PRODUCER :
2017-03-09 16:01:45 -06:00
viewToModify - > cellResult ( ) - > setFlowDiagTracerSelectionType ( RimEclipseResultDefinition : : FLOW_TR_INJECTORS ) ;
2017-03-09 04:16:27 -06:00
break ;
case RimFlowDiagSolution : : INJECTOR :
2017-03-09 16:01:45 -06:00
viewToModify - > cellResult ( ) - > setFlowDiagTracerSelectionType ( RimEclipseResultDefinition : : FLOW_TR_PRODUCERS ) ;
2017-03-09 04:16:27 -06:00
break ;
default :
CVF_ASSERT ( false ) ;
break ;
}
2017-03-09 16:01:45 -06:00
viewToModify - > cellResult ( ) - > loadDataAndUpdate ( ) ;
viewToModify - > cellResult ( ) - > updateConnectedEditors ( ) ;
2017-03-09 04:16:27 -06:00
std : : vector < QString > tracerNames = findContributingTracerNames ( flowDiagSolution , selectedWell - > wellResults ( ) , timeStep ) ;
2017-03-09 16:01:45 -06:00
for ( RimEclipseWell * w : viewToModify - > wellCollection ( ) - > wells ( ) )
2017-03-09 04:16:27 -06:00
{
if ( std : : find ( tracerNames . begin ( ) , tracerNames . end ( ) , w - > name ( ) ) ! = tracerNames . end ( )
| | selectedWell - > name ( ) = = w - > name ( ) )
{
w - > showWell = true ;
}
else
{
w - > showWell = false ;
}
}
// Disable all existing property filters, and
// create a new property filter based on TOF for current well
2017-03-09 16:01:45 -06:00
RimEclipsePropertyFilterCollection * propertyFilterCollection = viewToModify - > eclipsePropertyFilterCollection ( ) ;
2017-03-09 04:16:27 -06:00
for ( RimEclipsePropertyFilter * f : propertyFilterCollection - > propertyFilters ( ) )
{
f - > isActive = false ;
}
RimEclipsePropertyFilter * propertyFilter = new RimEclipsePropertyFilter ( ) ;
propertyFilterCollection - > propertyFilters ( ) . push_back ( propertyFilter ) ;
2017-03-09 16:01:45 -06:00
propertyFilter - > resultDefinition ( ) - > setEclipseCase ( viewToModify - > eclipseCase ( ) ) ;
2017-03-09 04:16:27 -06:00
propertyFilter - > resultDefinition ( ) - > setTofAndSelectTracer ( selectedWell - > name ( ) ) ;
propertyFilter - > resultDefinition ( ) - > loadDataAndUpdate ( ) ;
propertyFilterCollection - > updateConnectedEditors ( ) ;
RiuMainWindow : : instance ( ) - > setExpanded ( propertyFilterCollection , true ) ;
2017-03-09 16:01:45 -06:00
viewToModify - > faultCollection ( ) - > showFaultCollection = false ;
viewToModify - > faultCollection ( ) - > updateConnectedEditors ( ) ;
2017-03-09 04:16:27 -06:00
2017-03-09 16:01:45 -06:00
viewToModify - > updateCurrentTimeStepAndRedraw ( ) ;
viewToModify - > scheduleCreateDisplayModelAndRedraw ( ) ;
2017-03-09 04:16:27 -06:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : vector < QString > RicShowContributingWellsFeatureImpl : : findContributingTracerNames (
const RimFlowDiagSolution * flowDiagSolution ,
const RigSingleWellResultsData * wellResults ,
int timeStep )
{
std : : vector < QString > tracerCellFractionValues ;
if ( flowDiagSolution & & wellResults - > hasWellResult ( timeStep ) )
{
RimFlowDiagSolution : : TracerStatusType requestedTracerType = RimFlowDiagSolution : : UNDEFINED ;
const RigWellResultFrame : : WellProductionType prodType = wellResults - > wellProductionType ( timeStep ) ;
if ( prodType = = RigWellResultFrame : : PRODUCER
| | prodType = = RigWellResultFrame : : UNDEFINED_PRODUCTION_TYPE )
{
requestedTracerType = RimFlowDiagSolution : : INJECTOR ;
}
else
{
requestedTracerType = RimFlowDiagSolution : : PRODUCER ;
}
std : : vector < QString > tracerNames = flowDiagSolution - > tracerNames ( ) ;
for ( const QString & tracerName : tracerNames )
{
if ( flowDiagSolution - > tracerStatusInTimeStep ( tracerName , timeStep ) = = requestedTracerType )
{
tracerCellFractionValues . push_back ( tracerName ) ;
}
}
}
return tracerCellFractionValues ;
}