2017-03-09 11:16:27 +01: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 13:13:26 +01:00
#include "RiaApplication.h"
2017-08-17 13:49:51 +02:00
#include "RicSelectOrCreateViewFeatureImpl.h"
2017-03-10 13:13:26 +01:00
2017-03-09 11:16:27 +01:00
#include "RigFlowDiagResultAddress.h"
2017-10-13 13:44:53 +02:00
#include "RigSimWellData.h"
2017-03-09 11:16:27 +01:00
#include "RimEclipseCellColors.h"
#include "RimEclipsePropertyFilter.h"
#include "RimEclipsePropertyFilterCollection.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
2017-10-13 14:20:47 +02:00
#include "RimSimWellInViewCollection.h"
2017-10-15 21:20:03 +02:00
#include "RimFaultInViewCollection.h"
2017-03-10 13:13:26 +01:00
#include "RimFlowDiagSolution.h"
#include "RimProject.h"
2017-10-13 09:29:42 +02:00
#include "RimSimWellInView.h"
2017-03-10 13:13:26 +01:00
#include "RimViewManipulator.h"
2017-03-09 11:16:27 +01:00
2018-02-27 16:00:55 +01:00
#include "Riu3DMainWindowTools.h"
2017-03-09 11:16:27 +01:00
#include "cafCmdFeature.h"
#include "cafCmdFeatureManager.h"
2017-03-10 13:13:26 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-16 08:22:09 +01:00
RimEclipseView * RicShowContributingWellsFeatureImpl :: maniuplateSelectedView ( RimEclipseResultCase * eclipseResultCase , QString wellName , int timeStep )
2017-03-10 13:13:26 +01:00
{
2017-08-17 13:49:51 +02:00
RimEclipseView * viewToManipulate = RicSelectOrCreateViewFeatureImpl :: showViewSelection ( eclipseResultCase , "lastUsedWellAllocationView" , "Show Contributing Wells in View" );
2017-03-10 13:13:26 +01:00
2017-12-07 16:17:25 +01:00
if ( ! viewToManipulate ) return nullptr ;
2017-03-10 13:13:26 +01:00
RicShowContributingWellsFeatureImpl :: modifyViewToShowContributingWells ( viewToManipulate , wellName , timeStep );
auto * feature = caf :: CmdFeatureManager :: instance () -> getCommandFeature ( "RicShowMainWindowFeature" );
feature -> actionTriggered ( false );
2017-08-17 13:49:51 +02:00
RicSelectOrCreateViewFeatureImpl :: focusView ( viewToManipulate );
2017-03-10 13:13:26 +01:00
return viewToManipulate ;
}
2017-03-09 11:16:27 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-09 23:01:45 +01:00
void RicShowContributingWellsFeatureImpl :: modifyViewToShowContributingWells ( RimEclipseView * viewToModify , const QString & wellName , int timeStep )
2017-03-09 11:16:27 +01:00
{
2017-03-10 14:45:07 +01:00
CVF_ASSERT ( viewToModify );
2017-03-09 11:16:27 +01:00
2017-10-13 09:29:42 +02:00
RimSimWellInView * selectedWell = nullptr ;
2017-03-09 11:16:27 +01:00
2017-10-13 09:29:42 +02:00
for ( RimSimWellInView * w : viewToModify -> wellCollection () -> wells ())
2017-03-09 11:16:27 +01:00
{
if ( w -> name () == wellName )
{
selectedWell = w ;
}
}
2017-03-10 14:45:07 +01:00
CVF_ASSERT ( selectedWell );
2017-03-09 11:16:27 +01:00
RimEclipseResultCase * eclipseResultCase = nullptr ;
selectedWell -> firstAncestorOrThisOfTypeAsserted ( eclipseResultCase );
// Use the active flow diag solutions, or the first one as default
2017-03-09 23:01:45 +01:00
RimFlowDiagSolution * flowDiagSolution = viewToModify -> cellResult () -> flowDiagSolution ();
2017-03-09 11:16:27 +01:00
if ( ! flowDiagSolution )
{
2017-03-09 23:01:45 +01:00
flowDiagSolution = eclipseResultCase -> defaultFlowDiagSolution ();
2017-03-09 11:16:27 +01:00
}
2017-03-10 14:45:07 +01:00
//assert(flowDiagSolution);
CVF_ASSERT ( flowDiagSolution );
2017-03-09 11:16:27 +01:00
RimFlowDiagSolution :: TracerStatusType tracerStatus = flowDiagSolution -> tracerStatusInTimeStep ( selectedWell -> name (), timeStep );
if ( ! ( tracerStatus == RimFlowDiagSolution :: INJECTOR || tracerStatus == RimFlowDiagSolution :: PRODUCER ))
{
return ;
}
2017-03-09 23:01:45 +01:00
viewToModify -> setCurrentTimeStep ( timeStep );
2017-06-13 15:41:52 +02:00
viewToModify -> cellResult () -> setResultType ( RiaDefines :: FLOW_DIAGNOSTICS );
2017-03-09 23:01:45 +01:00
viewToModify -> cellResult () -> setResultVariable ( "MaxFractionTracer" );
viewToModify -> cellResult () -> setFlowSolution ( flowDiagSolution );
2017-03-09 11:16:27 +01:00
switch ( tracerStatus )
{
case RimFlowDiagSolution :: PRODUCER :
2017-03-09 23:01:45 +01:00
viewToModify -> cellResult () -> setFlowDiagTracerSelectionType ( RimEclipseResultDefinition :: FLOW_TR_INJECTORS );
2017-03-09 11:16:27 +01:00
break ;
case RimFlowDiagSolution :: INJECTOR :
2017-03-09 23:01:45 +01:00
viewToModify -> cellResult () -> setFlowDiagTracerSelectionType ( RimEclipseResultDefinition :: FLOW_TR_PRODUCERS );
2017-03-09 11:16:27 +01:00
break ;
default :
CVF_ASSERT ( false );
break ;
}
2017-03-09 23:01:45 +01:00
viewToModify -> cellResult () -> loadDataAndUpdate ();
viewToModify -> cellResult () -> updateConnectedEditors ();
2017-03-09 11:16:27 +01:00
2017-10-13 13:44:53 +02:00
std :: vector < QString > tracerNames = findContributingTracerNames ( flowDiagSolution , selectedWell -> simWellData (), timeStep );
2017-03-09 11:16:27 +01:00
2017-10-13 09:29:42 +02:00
for ( RimSimWellInView * w : viewToModify -> wellCollection () -> wells ())
2017-03-09 11:16:27 +01: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 23:01:45 +01:00
RimEclipsePropertyFilterCollection * propertyFilterCollection = viewToModify -> eclipsePropertyFilterCollection ();
2017-03-09 11:16:27 +01:00
for ( RimEclipsePropertyFilter * f : propertyFilterCollection -> propertyFilters ())
{
f -> isActive = false ;
}
RimEclipsePropertyFilter * propertyFilter = new RimEclipsePropertyFilter ();
propertyFilterCollection -> propertyFilters (). push_back ( propertyFilter );
2017-03-09 23:01:45 +01:00
propertyFilter -> resultDefinition () -> setEclipseCase ( viewToModify -> eclipseCase ());
2017-03-09 11:16:27 +01:00
propertyFilter -> resultDefinition () -> setTofAndSelectTracer ( selectedWell -> name ());
propertyFilter -> resultDefinition () -> loadDataAndUpdate ();
propertyFilterCollection -> updateConnectedEditors ();
2018-02-27 16:00:55 +01:00
Riu3DMainWindowTools :: setExpanded ( propertyFilterCollection );
2017-03-09 11:16:27 +01:00
2017-03-09 23:01:45 +01:00
viewToModify -> faultCollection () -> showFaultCollection = false ;
viewToModify -> faultCollection () -> updateConnectedEditors ();
2017-03-09 11:16:27 +01:00
2017-03-09 23:01:45 +01:00
viewToModify -> updateCurrentTimeStepAndRedraw ();
viewToModify -> scheduleCreateDisplayModelAndRedraw ();
2017-03-09 11:16:27 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std :: vector < QString > RicShowContributingWellsFeatureImpl :: findContributingTracerNames (
const RimFlowDiagSolution * flowDiagSolution ,
2017-10-13 13:44:53 +02:00
const RigSimWellData * simWellData ,
2017-03-09 11:16:27 +01:00
int timeStep )
{
std :: vector < QString > tracerCellFractionValues ;
2017-10-13 13:44:53 +02:00
if ( flowDiagSolution && simWellData -> hasWellResult ( timeStep ))
2017-03-09 11:16:27 +01:00
{
RimFlowDiagSolution :: TracerStatusType requestedTracerType = RimFlowDiagSolution :: UNDEFINED ;
2017-10-13 13:44:53 +02:00
const RigWellResultFrame :: WellProductionType prodType = simWellData -> wellProductionType ( timeStep );
2017-03-09 11:16:27 +01:00
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 ;
}