2019-08-09 02:54:55 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor 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 "RicSummaryPlotFeatureImpl.h"
# include "RimSummaryCurve.h"
# include "RimSummaryPlot.h"
# include "RimSummaryPlotCollection.h"
# include "RimProject.h"
# include "RimMainPlotCollection.h"
2019-08-13 04:48:57 -05:00
# include "RimSummaryCase.h"
2019-08-20 08:40:40 -05:00
# include "RimEnsembleCurveSet.h"
# include "RimEnsembleCurveSetCollection.h"
2019-08-09 02:54:55 -05:00
# include "RiuPlotMainWindowTools.h"
2019-08-20 08:40:40 -05:00
# include "RiuMainWindow.h"
2019-08-09 02:54:55 -05:00
# include "RiaApplication.h"
# include "RiaColorTables.h"
2019-08-28 04:36:29 -05:00
# include "RiaLogging.h"
2019-08-09 06:15:32 -05:00
# include "RiaPreferences.h"
2019-08-13 04:48:57 -05:00
# include "RiaEclipseFileNameTools.h"
2019-08-20 08:40:40 -05:00
# include "RiaDefines.h"
2019-08-13 04:48:57 -05:00
2019-08-09 06:15:32 -05:00
# include "RifSummaryReaderInterface.h"
2019-08-13 04:48:57 -05:00
# include "RicImportGeneralDataFeature.h"
2019-08-20 08:40:40 -05:00
# include "RicCreateSummaryCaseCollectionFeature.h"
# include "RicImportSummaryCasesFeature.h"
2019-08-13 04:48:57 -05:00
# include <QStringList>
2019-08-20 05:16:28 -05:00
# include <QFileInfo>
2019-08-21 09:36:17 -05:00
# include <QRegularExpression>
# include "RiaImportEclipseCaseTools.h"
# include "RimEclipseCase.h"
# include "RimGridTimeHistoryCurve.h"
# include "WellLogCommands/RicWellLogPlotCurveFeatureImpl.h"
# include "RimEclipseResultCase.h"
# include "RimOilField.h"
# include "RimEclipseCaseCollection.h"
# include "RigEclipseResultAddress.h"
2019-08-22 01:34:49 -05:00
# include "RigEclipseCaseData.h"
# include "RigCaseCellResultsData.h"
2019-08-09 02:54:55 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryCurve * RicSummaryPlotFeatureImpl : : addDefaultCurveToPlot ( RimSummaryPlot * plot , RimSummaryCase * summaryCase )
{
if ( plot )
{
2019-08-09 06:15:32 -05:00
RifEclipseSummaryAddress defaultAddressToUse ;
QString curvesTextFilter = RiaApplication : : instance ( ) - > preferences ( ) - > defaultSummaryCurvesTextFilter ;
QStringList curveFilters = curvesTextFilter . split ( " ; " , QString : : SkipEmptyParts ) ;
if ( curveFilters . size ( ) )
{
const std : : set < RifEclipseSummaryAddress > & addrs = summaryCase - > summaryReader ( ) - > allResultAddresses ( ) ;
for ( const auto & addr : addrs )
{
const QString & filter = curveFilters [ 0 ] ;
{
if ( addr . isUiTextMatchingFilterText ( filter ) )
{
defaultAddressToUse = addr ;
}
}
}
}
2019-08-09 02:54:55 -05:00
RimSummaryCurve * newCurve = new RimSummaryCurve ( ) ;
// Use same counting as RicNewSummaryEnsembleCurveSetFeature::onActionTriggered
cvf : : Color3f curveColor = RiaColorTables : : summaryCurveDefaultPaletteColors ( ) . cycledColor3f ( plot - > singleColorCurveCount ( ) ) ;
newCurve - > setColor ( curveColor ) ;
plot - > addCurveNoUpdate ( newCurve ) ;
if ( summaryCase )
{
newCurve - > setSummaryCaseY ( summaryCase ) ;
}
2019-08-09 06:15:32 -05:00
newCurve - > setSummaryAddressYAndApplyInterpolation ( defaultAddressToUse ) ;
2019-08-09 02:54:55 -05:00
return newCurve ;
}
return nullptr ;
}
2019-08-09 06:15:32 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : vector < RimSummaryCurve * > RicSummaryPlotFeatureImpl : : addDefaultCurvesToPlot ( RimSummaryPlot * plot , RimSummaryCase * summaryCase )
{
std : : vector < RimSummaryCurve * > defaultCurves ;
QString curvesTextFilter = RiaApplication : : instance ( ) - > preferences ( ) - > defaultSummaryCurvesTextFilter ;
QStringList curveFilters = curvesTextFilter . split ( " ; " , QString : : SkipEmptyParts ) ;
2019-08-13 07:16:51 -05:00
return addCurvesFromAddressFiltersToPlot ( curveFilters , plot , summaryCase , false ) ;
2019-08-09 06:15:32 -05:00
}
2019-08-09 02:54:55 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotFeatureImpl : : ensureAtLeastOnePlot ( RimSummaryPlotCollection * summaryPlotCollection , RimSummaryCase * summaryCase )
{
if ( summaryPlotCollection & & summaryCase )
{
if ( summaryPlotCollection - > summaryPlots . empty ( ) )
{
createDefaultSummaryPlot ( summaryCase ) ;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotFeatureImpl : : createDefaultSummaryPlot ( RimSummaryCase * summaryCase )
{
RimSummaryPlotCollection * summaryPlotCollection = RiaApplication : : instance ( ) - > project ( ) - > mainPlotCollection - > summaryPlotCollection ( ) ;
2019-08-13 04:48:57 -05:00
if ( summaryPlotCollection & & summaryCase & & ! RiaApplication : : instance ( ) - > preferences ( ) - > defaultSummaryCurvesTextFilter ( ) . isEmpty ( ) )
2019-08-09 02:54:55 -05:00
{
auto plot = summaryPlotCollection - > createSummaryPlotWithAutoTitle ( ) ;
2019-08-09 06:15:32 -05:00
std : : vector < RimSummaryCurve * > curves = RicSummaryPlotFeatureImpl : : addDefaultCurvesToPlot ( plot , summaryCase ) ;
plot - > applyDefaultCurveAppearances ( ) ;
2019-08-09 02:54:55 -05:00
plot - > loadDataAndUpdate ( ) ;
summaryPlotCollection - > updateConnectedEditors ( ) ;
2019-08-09 06:15:32 -05:00
caf : : PdmObject * itemToSelect = plot ;
if ( curves . size ( ) ) itemToSelect = curves [ 0 ] ;
RiuPlotMainWindowTools : : setExpanded ( itemToSelect ) ;
RiuPlotMainWindowTools : : selectAsCurrentItem ( itemToSelect ) ;
2019-08-09 02:54:55 -05:00
}
}
2019-08-20 08:40:40 -05:00
RimSummaryCurve * createHistoryCurve ( const RifEclipseSummaryAddress & addr , RimSummaryCase * summaryCasesToUse )
2019-08-13 04:48:57 -05:00
{
2019-08-20 08:40:40 -05:00
RifEclipseSummaryAddress historyAddr = addr ;
historyAddr . setQuantityName ( historyAddr . quantityName ( ) + " H " ) ;
if ( summaryCasesToUse - > summaryReader ( ) - > allResultAddresses ( ) . count ( historyAddr ) )
{
RimSummaryCurve * historyCurve = new RimSummaryCurve ( ) ;
historyCurve - > setSummaryCaseY ( summaryCasesToUse ) ;
historyCurve - > setSummaryAddressYAndApplyInterpolation ( historyAddr ) ;
return historyCurve ;
}
return nullptr ;
2019-08-13 04:48:57 -05:00
}
2019-08-21 09:36:17 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RigGridCellResultAddress
{
public :
RigGridCellResultAddress ( )
: gridIndex ( - 1 )
, i ( - 1 )
, j ( - 1 )
, k ( - 1 )
{ }
RigGridCellResultAddress ( size_t gridIndex ,
size_t i ,
size_t j ,
size_t k ,
const RigEclipseResultAddress & eclipseResultAddress )
: gridIndex ( gridIndex )
, i ( i )
, j ( j )
, k ( k )
, eclipseResultAddress ( eclipseResultAddress )
{ }
// Using zero based ijk
size_t gridIndex ;
size_t i ;
size_t j ;
size_t k ;
RigEclipseResultAddress eclipseResultAddress ;
} ;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : vector < RigGridCellResultAddress > createGridCellAddressesFromFilter ( const QString & text )
{
std : : vector < RigGridCellResultAddress > addresses ;
QStringList addressParts = text . split ( " : " ) ;
if ( addressParts . size ( ) > 1 )
{
QString resultVarName = addressParts [ 0 ] ;
size_t gridIdx = 0 ;
if ( addressParts . size ( ) > 2 )
{
gridIdx = addressParts [ 1 ] . toULong ( ) ;
}
QString ijkText = addressParts . back ( ) ;
QStringList ijkTextParts = ijkText . split ( " , " ) ;
if ( ijkTextParts . size ( ) = = 3 )
{
bool isOk = true ;
bool allOk = true ;
size_t i = ijkTextParts [ 0 ] . toULong ( & isOk ) ;
allOk & = isOk ;
size_t j = ijkTextParts [ 1 ] . toULong ( & isOk ) ;
allOk & = isOk ;
size_t k = ijkTextParts [ 2 ] . toULong ( & isOk ) ;
allOk & = isOk ;
if ( allOk )
{
addresses . emplace_back ( RigGridCellResultAddress ( gridIdx , i - 1 , j - 1 , k - 1 , RigEclipseResultAddress ( resultVarName ) ) ) ;
}
}
}
return addresses ;
}
std : : vector < RimEclipseCase * > openEclipseCasesForCellPlotting ( QStringList gridFileNames )
{
std : : vector < RimEclipseCase * > openedCases ;
RiaApplication * app = RiaApplication : : instance ( ) ;
RimProject * project = app - > project ( ) ;
RimEclipseCaseCollection * analysisModels = project - > activeOilField ( ) - > analysisModels ( ) ;
for ( const QString & fileName : gridFileNames )
{
QFileInfo gridFileInfo ( fileName ) ;
if ( ! gridFileInfo . exists ( ) ) continue ;
QString caseName = gridFileInfo . completeBaseName ( ) ;
RimEclipseResultCase * rimResultReservoir = new RimEclipseResultCase ( ) ;
rimResultReservoir - > setCaseInfo ( caseName , fileName ) ;
analysisModels - > cases . push_back ( rimResultReservoir ) ;
if ( ! rimResultReservoir - > openReserviorCase ( ) )
{
analysisModels - > removeCaseFromAllGroups ( rimResultReservoir ) ;
delete rimResultReservoir ;
continue ;
}
else
{
openedCases . push_back ( rimResultReservoir ) ;
}
}
analysisModels - > updateConnectedEditors ( ) ;
return openedCases ;
}
2019-08-13 04:48:57 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2019-08-20 08:40:40 -05:00
void RicSummaryPlotFeatureImpl : : createSummaryPlotsFromArgumentLine ( const QStringList & arguments )
2019-08-13 04:48:57 -05:00
{
// Split arguments in options, vectors and filenames
QStringList options ;
2019-08-21 09:36:17 -05:00
QStringList allCurveAddressFilters ;
QStringList summaryFileNames ;
QStringList gridFileNames ;
2019-08-20 08:40:40 -05:00
QString ensembleColoringParameter ;
2019-08-13 04:48:57 -05:00
2019-08-20 08:40:40 -05:00
std : : set < QString > validOptions = { " -help " , " -h " , " -nl " , " -s " , " -n " , " -e " , " -c " , " -cl " } ;
2019-08-13 04:48:57 -05:00
for ( int optionIdx = 0 ; optionIdx < arguments . size ( ) ; + + optionIdx )
{
if ( arguments [ optionIdx ] . startsWith ( " - " ) )
{
if ( arguments [ optionIdx ] = = " -help " )
{
RiaApplication : : instance ( ) - > showFormattedTextInMessageBoxOrConsole (
" The --summaryplot option has the following syntax: \n "
" \n "
2019-08-14 04:12:39 -05:00
" [<plotOptions>] <eclipsesummaryvectorfilters> [<eclipsedatafiles>] \n "
2019-08-13 04:48:57 -05:00
" \n "
2019-08-20 08:40:40 -05:00
" It Creates one summary plot for each of the the summary vectors matched by the <eclipsesummaryvectorfilters> using all the <eclipsedatafiles> in each plot. \n "
2019-08-14 04:12:39 -05:00
" The <eclipsesummaryvectorfilters> has the syntax <vectorname>[:<item>[:<subitem>[:i,j,k]]] and can be repeated. \n "
2019-08-13 04:48:57 -05:00
" Wildcards can also be used, eg. \" WOPT:* \" to select the total oil production from all the wells. \n "
" The <eclipsedatafiles> can be written with or without extension. Only the corresponding SMSPEC file will be opened for each case. \n "
" \n "
" The summary plot options are: \n "
" -help \t Show this help text and ignore the rest of the options. \n "
2019-08-14 01:53:08 -05:00
" -h \t Include history vectors. Will be read from the summary file if the vectors exist. \n "
" \t Only history vectors from the first summary case in the project will be included. \n "
2019-08-14 04:12:39 -05:00
" -nl \t Omit legend in plot. \n "
2019-08-20 08:40:40 -05:00
" -s \t Create only one plot including all the defined vectors and cases. \n "
" -n \t Scale all curves into the range 0.0-1.0. Useful when using -s. \n "
" -e \t Import all the cases as an ensemble, and create ensemble curves sets instead of single curves. \n "
" -c <parametername> \t Same as -e, but colors the curves by the ensemble parameter <parametername> . \n "
" -cl <parametername> \t Same as -c, but uses logarithmic legend. \n "
2019-08-13 04:48:57 -05:00
) ;
2019-08-20 08:40:40 -05:00
return ;
}
if ( validOptions . count ( arguments [ optionIdx ] ) )
{
options . push_back ( arguments [ optionIdx ] ) ;
if ( arguments [ optionIdx ] = = " -c " | | arguments [ optionIdx ] = = " -cl " )
{
optionIdx + + ;
if ( optionIdx < arguments . size ( ) ) ensembleColoringParameter = arguments [ optionIdx ] ;
}
}
else
{
RiaLogging : : error ( " The summaryplot option: \" " + arguments [ optionIdx ] + " \" is unknown. " ) ;
2019-08-13 04:48:57 -05:00
}
}
else
{
RiaEclipseFileNameTools nameTool ( arguments [ optionIdx ] ) ;
QString smSpecFileName = nameTool . findRelatedSummarySpecFile ( ) ;
2019-08-21 09:36:17 -05:00
QString gridFileName = nameTool . findRelatedGridFile ( ) ;
if ( smSpecFileName ! = " " | | gridFileName ! = " " )
2019-08-13 04:48:57 -05:00
{
2019-08-21 09:36:17 -05:00
if ( smSpecFileName ! = " " ) summaryFileNames . push_back ( smSpecFileName ) ;
if ( gridFileName ! = " " ) gridFileNames . push_back ( gridFileName ) ;
2019-08-13 04:48:57 -05:00
}
else
{
2019-08-21 09:36:17 -05:00
allCurveAddressFilters . push_back ( arguments [ optionIdx ] ) ;
2019-08-13 04:48:57 -05:00
}
}
}
2019-08-09 02:54:55 -05:00
2019-08-21 09:36:17 -05:00
if ( allCurveAddressFilters . empty ( ) )
2019-08-13 04:48:57 -05:00
{
2019-08-21 09:36:17 -05:00
RiaLogging : : error ( " Needs at least one vector to create a plot. " ) ;
2019-08-13 04:48:57 -05:00
}
2019-08-14 04:12:39 -05:00
2019-08-13 07:16:51 -05:00
bool hideLegend = options . contains ( " -nl " ) ;
bool addHistoryCurves = options . contains ( " -h " ) ;
2019-08-14 01:53:08 -05:00
bool isNormalizedY = options . contains ( " -n " ) ;
2019-08-14 04:12:39 -05:00
bool isSinglePlot = options . contains ( " -s " ) ;
2019-08-13 04:48:57 -05:00
2019-08-20 08:40:40 -05:00
enum EnsembleColoringType { SINGLE_COLOR , PARAMETER , LOG_PARAMETER , NONE } ;
EnsembleColoringType ensembleColoringStyle = NONE ;
{
int e_pos = options . lastIndexOf ( " -e " ) ;
int c_pos = options . lastIndexOf ( " -c " ) ;
int cl_pos = options . lastIndexOf ( " -cl " ) ;
2019-08-20 05:16:28 -05:00
2019-08-20 08:40:40 -05:00
int lastEnsembleOptionPos = - 1 ;
if ( e_pos > lastEnsembleOptionPos ) { lastEnsembleOptionPos = e_pos ; ensembleColoringStyle = SINGLE_COLOR ; }
if ( c_pos > lastEnsembleOptionPos ) { lastEnsembleOptionPos = c_pos ; ensembleColoringStyle = PARAMETER ; }
if ( cl_pos > lastEnsembleOptionPos ) { lastEnsembleOptionPos = cl_pos ; ensembleColoringStyle = LOG_PARAMETER ; }
}
bool isEnsembleMode = ensembleColoringStyle ! = NONE ;
std : : vector < RimSummaryCase * > summaryCasesToUse ;
2019-08-21 09:36:17 -05:00
if ( summaryFileNames . size ( ) )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
RicImportSummaryCasesFeature : : createSummaryCasesFromFiles ( summaryFileNames , & summaryCasesToUse , isEnsembleMode ) ;
2019-08-20 08:40:40 -05:00
RicImportSummaryCasesFeature : : addSummaryCases ( summaryCasesToUse ) ;
RiaApplication : : instance ( ) - > setLastUsedDialogDirectory ( RiaDefines : : defaultDirectoryLabel ( RiaDefines : : ECLIPSE_SUMMARY_FILE ) ,
2019-08-21 09:36:17 -05:00
QFileInfo ( summaryFileNames [ 0 ] ) . absolutePath ( ) ) ;
2019-08-20 08:40:40 -05:00
}
2019-08-21 09:36:17 -05:00
// Sort in summary and grid curve addresses
2019-08-13 04:48:57 -05:00
2019-08-21 09:36:17 -05:00
QStringList gridResultAddressFilters ;
QStringList summaryAddressFilters ;
2019-08-13 04:48:57 -05:00
if ( summaryCasesToUse . size ( ) )
{
2019-08-21 09:36:17 -05:00
const std : : set < RifEclipseSummaryAddress > & addrs = summaryCasesToUse [ 0 ] - > summaryReader ( ) - > allResultAddresses ( ) ;
std : : vector < bool > usedFilters ;
std : : set < RifEclipseSummaryAddress > setToInsertFilteredAddressesIn ;
filteredSummaryAdressesFromCase ( allCurveAddressFilters , addrs , & setToInsertFilteredAddressesIn , & usedFilters ) ;
2019-08-20 08:40:40 -05:00
2019-08-21 09:36:17 -05:00
QRegularExpression gridAddressPattern ( " ^[A-Z]+:[0-9]+,[0-9]+,[0-9]+$ " ) ;
2019-08-14 04:12:39 -05:00
2019-08-21 09:36:17 -05:00
for ( int filterIdx = 0 ; filterIdx < allCurveAddressFilters . size ( ) ; + + filterIdx )
{
const QString & address = allCurveAddressFilters [ filterIdx ] ;
if ( usedFilters [ filterIdx ] )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
summaryAddressFilters . push_back ( address ) ;
2019-08-20 08:40:40 -05:00
}
else
2019-08-14 04:12:39 -05:00
{
2019-08-21 09:36:17 -05:00
if ( gridAddressPattern . match ( address ) . hasMatch ( ) )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
gridResultAddressFilters . push_back ( address ) ;
}
else
{
RiaLogging : : warning ( " No summary or restart vectors matched \" " + address + " \" " ) ;
2019-08-20 08:40:40 -05:00
}
2019-08-14 04:12:39 -05:00
}
2019-08-13 04:48:57 -05:00
}
2019-08-21 09:36:17 -05:00
}
2019-08-14 04:12:39 -05:00
2019-08-21 09:36:17 -05:00
if ( summaryCasesToUse . size ( ) )
{
if ( summaryAddressFilters . size ( ) )
{
RimSummaryPlotCollection * sumPlotColl = RiaApplication : : instance ( ) - > project ( ) - > mainPlotCollection ( ) - > summaryPlotCollection ( ) ;
RimSummaryPlot * lastPlotCreated = nullptr ;
RimSummaryCaseCollection * ensemble = nullptr ;
if ( isEnsembleMode ) ensemble = RicCreateSummaryCaseCollectionFeature : : groupSummaryCases ( summaryCasesToUse , " Ensemble " , true ) ;
2019-08-13 04:48:57 -05:00
2019-08-21 09:36:17 -05:00
if ( isSinglePlot )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
RimSummaryPlot * newPlot = sumPlotColl - > createSummaryPlotWithAutoTitle ( ) ;
2019-08-20 08:40:40 -05:00
if ( isEnsembleMode )
2019-08-14 04:12:39 -05:00
{
2019-08-21 09:36:17 -05:00
std : : set < RifEclipseSummaryAddress > filteredAdressesFromCases = applySummaryAddressFiltersToCases ( summaryCasesToUse ,
summaryAddressFilters ) ;
for ( const auto & addr : filteredAdressesFromCases )
2019-08-14 04:12:39 -05:00
{
2019-08-21 09:36:17 -05:00
RimEnsembleCurveSet * curveSet = new RimEnsembleCurveSet ( ) ;
curveSet - > setSummaryCaseCollection ( ensemble ) ;
curveSet - > setSummaryAddress ( addr ) ;
if ( ensembleColoringStyle = = PARAMETER | | ensembleColoringStyle = = LOG_PARAMETER )
{
curveSet - > setColorMode ( RimEnsembleCurveSet : : BY_ENSEMBLE_PARAM ) ;
curveSet - > setEnsembleParameter ( ensembleColoringParameter ) ;
if ( ensembleColoringStyle = = LOG_PARAMETER )
{
curveSet - > legendConfig ( ) - > setMappingMode ( RimRegularLegendConfig : : LOG10_CONTINUOUS ) ;
}
}
newPlot - > ensembleCurveSetCollection ( ) - > addCurveSet ( curveSet ) ;
if ( addHistoryCurves )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
RimSummaryCurve * historyCurve = createHistoryCurve ( addr , summaryCasesToUse [ 0 ] ) ;
if ( historyCurve ) newPlot - > addCurveNoUpdate ( historyCurve ) ;
2019-08-20 08:40:40 -05:00
}
2019-08-14 04:12:39 -05:00
}
}
2019-08-20 08:40:40 -05:00
else
2019-08-14 04:12:39 -05:00
{
2019-08-20 08:40:40 -05:00
for ( RimSummaryCase * sumCase : summaryCasesToUse )
2019-08-14 04:12:39 -05:00
{
2019-08-21 09:36:17 -05:00
RicSummaryPlotFeatureImpl : : addCurvesFromAddressFiltersToPlot ( summaryAddressFilters , newPlot , sumCase , addHistoryCurves ) ;
addHistoryCurves = false ;
2019-08-14 04:12:39 -05:00
}
2019-08-20 08:40:40 -05:00
}
2019-08-14 04:12:39 -05:00
2019-08-21 09:36:17 -05:00
lastPlotCreated = newPlot ;
newPlot - > showLegend ( ! hideLegend ) ;
newPlot - > setNormalizationEnabled ( isNormalizedY ) ;
newPlot - > applyDefaultCurveAppearances ( ) ;
newPlot - > loadDataAndUpdate ( ) ;
sumPlotColl - > updateConnectedEditors ( ) ;
2019-08-14 04:12:39 -05:00
2019-08-21 09:36:17 -05:00
RiuPlotMainWindowTools : : setExpanded ( newPlot ) ;
RiuPlotMainWindowTools : : selectAsCurrentItem ( newPlot ) ;
}
else // Multiplot, one for each separate summary address
{
std : : set < RifEclipseSummaryAddress > filteredAdressesFromCases = applySummaryAddressFiltersToCases ( summaryCasesToUse ,
summaryAddressFilters ) ;
for ( const auto & addr : filteredAdressesFromCases )
2019-08-14 04:12:39 -05:00
{
2019-08-21 09:36:17 -05:00
std : : vector < RimSummaryCurve * > createdCurves ;
std : : vector < RimEnsembleCurveSet * > createdEnsembleCurveSets ;
if ( isEnsembleMode )
{
RimEnsembleCurveSet * curveSet = new RimEnsembleCurveSet ( ) ;
2019-08-20 08:40:40 -05:00
2019-08-21 09:36:17 -05:00
curveSet - > setSummaryCaseCollection ( ensemble ) ;
curveSet - > setSummaryAddress ( addr ) ;
if ( ensembleColoringStyle = = PARAMETER | | ensembleColoringStyle = = LOG_PARAMETER )
{
curveSet - > setColorMode ( RimEnsembleCurveSet : : BY_ENSEMBLE_PARAM ) ;
curveSet - > setEnsembleParameter ( ensembleColoringParameter ) ;
if ( ensembleColoringStyle = = LOG_PARAMETER )
{
curveSet - > legendConfig ( ) - > setMappingMode ( RimRegularLegendConfig : : LOG10_CONTINUOUS ) ;
}
}
createdEnsembleCurveSets . push_back ( curveSet ) ;
}
else
2019-08-14 04:12:39 -05:00
{
2019-08-21 09:36:17 -05:00
for ( RimSummaryCase * sumCase : summaryCasesToUse )
{
const std : : set < RifEclipseSummaryAddress > & allAddrsInCase = sumCase - > summaryReader ( ) - > allResultAddresses ( ) ;
if ( allAddrsInCase . count ( addr ) )
{
RimSummaryCurve * newCurve = new RimSummaryCurve ( ) ;
newCurve - > setSummaryCaseY ( sumCase ) ;
newCurve - > setSummaryAddressYAndApplyInterpolation ( addr ) ;
createdCurves . push_back ( newCurve ) ;
}
}
2019-08-14 04:12:39 -05:00
}
2019-08-13 04:48:57 -05:00
2019-08-21 09:36:17 -05:00
if ( addHistoryCurves )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
RimSummaryCurve * historyCurve = createHistoryCurve ( addr , summaryCasesToUse [ 0 ] ) ;
if ( historyCurve ) createdCurves . push_back ( historyCurve ) ;
2019-08-20 08:40:40 -05:00
}
2019-08-21 09:36:17 -05:00
if ( createdCurves . size ( ) | | createdEnsembleCurveSets . size ( ) )
{
RimSummaryPlot * newPlot = sumPlotColl - > createSummaryPlotWithAutoTitle ( ) ;
2019-08-13 04:48:57 -05:00
2019-08-21 09:36:17 -05:00
for ( auto curve : createdCurves )
{
newPlot - > addCurveNoUpdate ( curve ) ;
}
for ( auto curveSet : createdEnsembleCurveSets )
{
newPlot - > ensembleCurveSetCollection ( ) - > addCurveSet ( curveSet ) ;
}
newPlot - > showLegend ( ! hideLegend ) ;
newPlot - > setNormalizationEnabled ( isNormalizedY ) ;
newPlot - > applyDefaultCurveAppearances ( ) ;
newPlot - > loadDataAndUpdate ( ) ;
lastPlotCreated = newPlot ;
}
2019-08-14 04:12:39 -05:00
}
}
2019-08-21 09:36:17 -05:00
sumPlotColl - > updateConnectedEditors ( ) ;
if ( lastPlotCreated )
{
RiuPlotMainWindowTools : : setExpanded ( lastPlotCreated ) ;
RiuPlotMainWindowTools : : selectAsCurrentItem ( lastPlotCreated ) ;
RiuPlotMainWindowTools : : showPlotMainWindow ( ) ;
RiuMainWindow : : instance ( ) - > close ( ) ;
}
2019-08-20 08:40:40 -05:00
}
2019-08-13 04:48:57 -05:00
2019-08-21 09:36:17 -05:00
// Grid Cell Result vectors
if ( gridResultAddressFilters . size ( ) )
2019-08-20 08:40:40 -05:00
{
2019-08-21 09:36:17 -05:00
// Todo: Use identical grid case import if -e -c or -cl
std : : vector < RimEclipseCase * > gridCasesToPlotFrom = openEclipseCasesForCellPlotting ( gridFileNames ) ;
RimSummaryPlotCollection * sumPlotColl = RiaApplication : : instance ( ) - > project ( ) - > mainPlotCollection ( ) - > summaryPlotCollection ( ) ;
2019-08-22 01:34:49 -05:00
if ( isSinglePlot )
2019-08-21 09:36:17 -05:00
{
2019-08-22 01:34:49 -05:00
std : : vector < RimGridTimeHistoryCurve * > createdCurves ;
int curveColorIndex = 0 ;
for ( const QString & gridAddressFilter : gridResultAddressFilters )
{
std : : vector < RigGridCellResultAddress > cellResAddrs = createGridCellAddressesFromFilter ( gridAddressFilter ) ;
for ( RigGridCellResultAddress cellResAddr : cellResAddrs )
{
for ( RimEclipseCase * eclCase : gridCasesToPlotFrom )
{
if ( ! ( eclCase - > eclipseCaseData ( ) - > results ( RiaDefines : : MATRIX_MODEL ) & &
eclCase - > eclipseCaseData ( ) - > results ( RiaDefines : : MATRIX_MODEL ) - > resultInfo ( cellResAddr . eclipseResultAddress ) ) )
{
RiaLogging : : warning ( " Could not find a restart result property with name: \" " + cellResAddr . eclipseResultAddress . m_resultName + " \" " ) ;
continue ;
}
RimGridTimeHistoryCurve * newCurve = new RimGridTimeHistoryCurve ( ) ;
newCurve - > setFromEclipseCellAndResult ( eclCase ,
cellResAddr . gridIndex ,
cellResAddr . i ,
cellResAddr . j ,
cellResAddr . k ,
cellResAddr . eclipseResultAddress ) ;
newCurve - > setLineThickness ( 2 ) ;
cvf : : Color3f curveColor = RicWellLogPlotCurveFeatureImpl : : curveColorFromTable ( curveColorIndex ) ;
newCurve - > setColor ( curveColor ) ;
if ( ! isEnsembleMode ) + + curveColorIndex ;
createdCurves . push_back ( newCurve ) ;
}
if ( isEnsembleMode ) + + curveColorIndex ;
}
}
if ( createdCurves . size ( ) )
2019-08-21 09:36:17 -05:00
{
RimSummaryPlot * newPlot = sumPlotColl - > createSummaryPlotWithAutoTitle ( ) ;
2019-08-22 01:34:49 -05:00
for ( auto curve : createdCurves )
2019-08-21 09:36:17 -05:00
{
2019-08-22 01:34:49 -05:00
newPlot - > addGridTimeHistoryCurve ( curve ) ;
}
2019-08-21 09:36:17 -05:00
2019-08-22 01:34:49 -05:00
newPlot - > showLegend ( ! hideLegend ) ;
newPlot - > setNormalizationEnabled ( isNormalizedY ) ;
newPlot - > loadDataAndUpdate ( ) ;
}
}
else // Multiplot
{
int curveColorIndex = 0 ;
2019-08-21 09:36:17 -05:00
2019-08-22 01:34:49 -05:00
for ( const QString & gridAddressFilter : gridResultAddressFilters )
{
std : : vector < RigGridCellResultAddress > cellResAddrs = createGridCellAddressesFromFilter ( gridAddressFilter ) ;
for ( RigGridCellResultAddress cellResAddr : cellResAddrs )
{
std : : vector < RimGridTimeHistoryCurve * > createdCurves ;
for ( RimEclipseCase * eclCase : gridCasesToPlotFrom )
{
if ( ! ( eclCase - > eclipseCaseData ( ) - > results ( RiaDefines : : MATRIX_MODEL ) & &
eclCase - > eclipseCaseData ( ) - > results ( RiaDefines : : MATRIX_MODEL ) - > resultInfo ( cellResAddr . eclipseResultAddress ) ) )
{
RiaLogging : : warning ( " Could not find a restart result property with name: \" " + cellResAddr . eclipseResultAddress . m_resultName + " \" " ) ;
continue ;
}
RimGridTimeHistoryCurve * newCurve = new RimGridTimeHistoryCurve ( ) ;
newCurve - > setFromEclipseCellAndResult ( eclCase ,
cellResAddr . gridIndex ,
cellResAddr . i ,
cellResAddr . j ,
cellResAddr . k ,
cellResAddr . eclipseResultAddress ) ;
newCurve - > setLineThickness ( 2 ) ;
cvf : : Color3f curveColor = RicWellLogPlotCurveFeatureImpl : : curveColorFromTable ( curveColorIndex ) ;
newCurve - > setColor ( curveColor ) ;
if ( ! isEnsembleMode ) + + curveColorIndex ;
createdCurves . push_back ( newCurve ) ;
}
if ( isEnsembleMode ) + + curveColorIndex ;
if ( createdCurves . size ( ) )
{
RimSummaryPlot * newPlot = sumPlotColl - > createSummaryPlotWithAutoTitle ( ) ;
for ( auto newCurve : createdCurves )
{
newPlot - > addGridTimeHistoryCurve ( newCurve ) ;
}
newPlot - > showLegend ( ! hideLegend ) ;
newPlot - > setNormalizationEnabled ( isNormalizedY ) ;
newPlot - > loadDataAndUpdate ( ) ;
}
2019-08-21 09:36:17 -05:00
}
}
}
sumPlotColl - > updateConnectedEditors ( ) ;
2019-08-20 08:40:40 -05:00
RiuPlotMainWindowTools : : showPlotMainWindow ( ) ;
RiuMainWindow : : instance ( ) - > close ( ) ;
2019-08-14 04:12:39 -05:00
}
2019-08-13 04:48:57 -05:00
}
else
{
RiaLogging : : error ( " Needs at least one summary case to create a plot. " ) ;
}
2019-08-20 08:40:40 -05:00
}
2019-08-13 04:48:57 -05:00
2019-08-20 08:40:40 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : set < RifEclipseSummaryAddress > RicSummaryPlotFeatureImpl : : applySummaryAddressFiltersToCases ( const std : : vector < RimSummaryCase * > & summaryCasesToUse ,
const QStringList & summaryAddressFilters )
{
std : : set < RifEclipseSummaryAddress > filteredAdressesFromCases ;
for ( RimSummaryCase * sumCase : summaryCasesToUse )
{
const std : : set < RifEclipseSummaryAddress > & addrs = sumCase - > summaryReader ( ) - > allResultAddresses ( ) ;
std : : vector < bool > usedFilters ;
2019-08-13 04:48:57 -05:00
2019-08-20 08:40:40 -05:00
filteredSummaryAdressesFromCase ( summaryAddressFilters , addrs , & filteredAdressesFromCases , & usedFilters ) ;
for ( int cfIdx = 0 ; cfIdx < usedFilters . size ( ) ; + + cfIdx )
{
if ( ! usedFilters [ cfIdx ] )
{
RiaLogging : : warning ( " Vector filter \" " + summaryAddressFilters [ cfIdx ] + " \" did not match anything in case: \" " + sumCase - > caseName ( ) + " \" " ) ;
}
}
}
return filteredAdressesFromCases ;
2019-08-13 04:48:57 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : vector < RimSummaryCurve * > RicSummaryPlotFeatureImpl : : addCurvesFromAddressFiltersToPlot ( const QStringList & curveFilters ,
RimSummaryPlot * plot ,
2019-08-13 07:16:51 -05:00
RimSummaryCase * summaryCase ,
bool addHistoryCurves )
2019-08-13 04:48:57 -05:00
{
std : : vector < RimSummaryCurve * > createdCurves ;
2019-08-14 04:12:39 -05:00
std : : set < RifEclipseSummaryAddress > curveAddressesToUse ;
2019-08-13 08:35:14 -05:00
2019-08-14 04:12:39 -05:00
const std : : set < RifEclipseSummaryAddress > & addrs = summaryCase - > summaryReader ( ) - > allResultAddresses ( ) ;
std : : vector < bool > usedFilters ;
2019-08-13 04:48:57 -05:00
2019-08-14 04:12:39 -05:00
filteredSummaryAdressesFromCase ( curveFilters , addrs , & curveAddressesToUse , & usedFilters ) ;
2019-08-13 04:48:57 -05:00
2019-08-14 04:12:39 -05:00
for ( int cfIdx = 0 ; cfIdx < usedFilters . size ( ) ; + + cfIdx )
2019-08-13 08:35:14 -05:00
{
if ( ! usedFilters [ cfIdx ] )
{
RiaLogging : : warning ( " Vector filter \" " + curveFilters [ cfIdx ] + " \" did not match anything in case: \" " + summaryCase - > caseName ( ) + " \" " ) ;
}
}
2019-08-13 07:16:51 -05:00
if ( addHistoryCurves )
{
std : : vector < RifEclipseSummaryAddress > historyAddressesToUse ;
for ( RifEclipseSummaryAddress historyAddr : curveAddressesToUse )
{
historyAddr . setQuantityName ( historyAddr . quantityName ( ) + " H " ) ;
if ( addrs . count ( historyAddr ) )
{
historyAddressesToUse . push_back ( historyAddr ) ;
}
}
2019-08-14 04:12:39 -05:00
curveAddressesToUse . insert ( historyAddressesToUse . begin ( ) , historyAddressesToUse . end ( ) ) ;
2019-08-13 07:16:51 -05:00
}
2019-08-13 04:48:57 -05:00
for ( const auto & addr : curveAddressesToUse )
{
RimSummaryCurve * newCurve = new RimSummaryCurve ( ) ;
plot - > addCurveNoUpdate ( newCurve ) ;
if ( summaryCase )
{
newCurve - > setSummaryCaseY ( summaryCase ) ;
}
newCurve - > setSummaryAddressYAndApplyInterpolation ( addr ) ;
createdCurves . push_back ( newCurve ) ;
}
return createdCurves ;
}
2019-08-14 04:12:39 -05:00
2019-08-21 09:36:17 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2019-08-14 04:12:39 -05:00
void RicSummaryPlotFeatureImpl : : filteredSummaryAdressesFromCase ( const QStringList & curveFilters ,
const std : : set < RifEclipseSummaryAddress > & allAddressesInCase ,
std : : set < RifEclipseSummaryAddress > * setToInsertFilteredAddressesIn ,
std : : vector < bool > * usedFilters )
{
int curveFilterCount = curveFilters . size ( ) ;
usedFilters - > clear ( ) ;
usedFilters - > resize ( curveFilterCount , false ) ;
for ( const auto & addr : allAddressesInCase )
{
for ( int cfIdx = 0 ; cfIdx < curveFilterCount ; + + cfIdx )
{
if ( addr . isUiTextMatchingFilterText ( curveFilters [ cfIdx ] ) )
{
setToInsertFilteredAddressesIn - > insert ( addr ) ;
( * usedFilters ) [ cfIdx ] = true ;
}
}
}
}