ResInsight/ApplicationLibCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.cpp
jonjenssen a7775214c8
Rewrite of cell filters. Added new polyline filter and user defined filter types. (#7191)
Make 3d view picker more generic to enable picking cell filter polygon

Give cell filters a new, generic interface for updating included/excluded cells from collection

Remove old range filter collection and replace with new filter collection that supports both range filters, polyline filters and user defined filters.

Update existing range filter code for the new collection and interface

Add user defined cell filter type

Add polyline cell filter type

Implement both Z and K index depth for polyline filters
Allow interactive editing of polyline filter node positions.
Support both geomech and eclipse views
Support view linking with both eclipse and geomech views and the new filter types

Support loading old project files with range filter collections into the new collection type

Adjust to new world order.
2021-01-11 18:47:09 +01:00

211 lines
8.2 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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"
#include "RicSelectOrCreateViewFeatureImpl.h"
#include "RigFlowDiagResultAddress.h"
#include "RigSimWellData.h"
#include "RimEclipseCellColors.h"
#include "RimEclipsePropertyFilter.h"
#include "RimEclipsePropertyFilterCollection.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimFaultInViewCollection.h"
#include "RimFlowDiagSolution.h"
#include "RimProject.h"
#include "RimSimWellInView.h"
#include "RimSimWellInViewCollection.h"
#include "RimViewManipulator.h"
#include "Riu3DMainWindowTools.h"
#include "cafCmdFeature.h"
#include "cafCmdFeatureManager.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseView* RicShowContributingWellsFeatureImpl::manipulateSelectedView( RimEclipseResultCase* eclipseResultCase,
QString wellName,
int timeStep )
{
RimEclipseView* viewToManipulate =
RicSelectOrCreateViewFeatureImpl::showViewSelection( eclipseResultCase,
"lastUsedWellAllocationView",
"ContributingWells_" + wellName,
"Show Contributing Wells in View" );
if ( !viewToManipulate ) return nullptr;
RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells( viewToManipulate, wellName, timeStep );
auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature( "RicShowMainWindowFeature" );
feature->actionTriggered( false );
RicSelectOrCreateViewFeatureImpl::focusView( viewToManipulate );
return viewToManipulate;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells( RimEclipseView* viewToModify,
const QString& wellName,
int timeStep )
{
CVF_ASSERT( viewToModify );
RimSimWellInView* selectedWell = nullptr;
for ( RimSimWellInView* w : viewToModify->wellCollection()->wells() )
{
if ( w->name() == wellName )
{
selectedWell = w;
}
}
CVF_ASSERT( selectedWell );
RimEclipseResultCase* eclipseResultCase = nullptr;
selectedWell->firstAncestorOrThisOfTypeAsserted( eclipseResultCase );
// Use the active flow diag solutions, or the first one as default
RimFlowDiagSolution* flowDiagSolution = viewToModify->cellResult()->flowDiagSolution();
if ( !flowDiagSolution )
{
flowDiagSolution = eclipseResultCase->defaultFlowDiagSolution();
}
// assert(flowDiagSolution);
CVF_ASSERT( flowDiagSolution );
RimFlowDiagSolution::TracerStatusType tracerStatus =
flowDiagSolution->tracerStatusInTimeStep( selectedWell->name(), timeStep );
if ( !( tracerStatus == RimFlowDiagSolution::INJECTOR || tracerStatus == RimFlowDiagSolution::PRODUCER ) )
{
return;
}
viewToModify->setCurrentTimeStep( timeStep );
viewToModify->cellResult()->setResultType( RiaDefines::ResultCatType::FLOW_DIAGNOSTICS );
viewToModify->cellResult()->setResultVariable( "MaxFractionTracer" );
viewToModify->cellResult()->setFlowSolution( flowDiagSolution );
switch ( tracerStatus )
{
case RimFlowDiagSolution::PRODUCER:
viewToModify->cellResult()->setFlowDiagTracerSelectionType( RimEclipseResultDefinition::FLOW_TR_INJECTORS );
break;
case RimFlowDiagSolution::INJECTOR:
viewToModify->cellResult()->setFlowDiagTracerSelectionType( RimEclipseResultDefinition::FLOW_TR_PRODUCERS );
break;
default:
CVF_ASSERT( false );
break;
}
viewToModify->cellResult()->loadDataAndUpdate();
viewToModify->cellResult()->updateConnectedEditors();
std::vector<QString> tracerNames =
findContributingTracerNames( flowDiagSolution, selectedWell->simWellData(), timeStep );
for ( RimSimWellInView* w : viewToModify->wellCollection()->wells() )
{
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
RimEclipsePropertyFilterCollection* propertyFilterCollection = viewToModify->eclipsePropertyFilterCollection();
for ( RimEclipsePropertyFilter* f : propertyFilterCollection->propertyFilters() )
{
f->setActive( false );
}
RimEclipsePropertyFilter* propertyFilter = new RimEclipsePropertyFilter();
propertyFilterCollection->propertyFilters().push_back( propertyFilter );
propertyFilter->resultDefinition()->setEclipseCase( viewToModify->eclipseCase() );
propertyFilter->resultDefinition()->setTofAndSelectTracer( selectedWell->name() );
propertyFilter->resultDefinition()->loadDataAndUpdate();
propertyFilterCollection->updateConnectedEditors();
Riu3DMainWindowTools::setExpanded( propertyFilterCollection );
viewToModify->faultCollection()->showFaultCollection = false;
viewToModify->faultCollection()->updateConnectedEditors();
viewToModify->updateDisplayModelForCurrentTimeStepAndRedraw();
viewToModify->scheduleCreateDisplayModelAndRedraw();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString>
RicShowContributingWellsFeatureImpl::findContributingTracerNames( const RimFlowDiagSolution* flowDiagSolution,
const RigSimWellData* simWellData,
int timeStep )
{
std::vector<QString> tracerCellFractionValues;
if ( flowDiagSolution && simWellData->hasWellResult( timeStep ) )
{
RimFlowDiagSolution::TracerStatusType requestedTracerType = RimFlowDiagSolution::UNDEFINED;
const RigWellResultFrame::WellProductionType prodType = simWellData->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;
}