2017-10-20 03:00:16 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-20 03:00:16 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-20 03:00:16 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-10-20 03:00:16 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiaSummaryTools.h"
|
|
|
|
|
2020-09-04 03:01:12 -05:00
|
|
|
#include "RiaFilePathTools.h"
|
2021-02-12 03:50:58 -06:00
|
|
|
#include "RiaTimeHistoryCurveResampler.h"
|
|
|
|
|
2017-10-20 03:00:16 -05:00
|
|
|
#include "RifEclipseSummaryAddress.h"
|
|
|
|
|
|
|
|
#include "RimMainPlotCollection.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimOilField.h"
|
2017-10-20 03:00:16 -05:00
|
|
|
#include "RimProject.h"
|
2019-12-11 07:51:18 -06:00
|
|
|
#include "RimSummaryAddress.h"
|
|
|
|
#include "RimSummaryCalculation.h"
|
|
|
|
#include "RimSummaryCalculationCollection.h"
|
|
|
|
#include "RimSummaryCalculationVariable.h"
|
2022-01-21 07:32:51 -06:00
|
|
|
#include "RimSummaryCase.h"
|
2018-05-23 06:33:10 -05:00
|
|
|
#include "RimSummaryCaseMainCollection.h"
|
2017-11-15 00:07:26 -06:00
|
|
|
#include "RimSummaryCrossPlot.h"
|
2019-12-11 07:51:18 -06:00
|
|
|
#include "RimSummaryCrossPlotCollection.h"
|
2017-10-20 03:00:16 -05:00
|
|
|
#include "RimSummaryCurve.h"
|
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
#include "RimSummaryPlotCollection.h"
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cafPdmObject.h"
|
2017-11-15 00:07:26 -06:00
|
|
|
|
2020-09-04 03:01:12 -05:00
|
|
|
#include <QRegularExpression>
|
|
|
|
|
2017-10-20 03:00:16 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-20 03:00:16 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryPlotCollection* RiaSummaryTools::summaryPlotCollection()
|
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* project = RimProject::current();
|
2017-10-20 03:00:16 -05:00
|
|
|
|
|
|
|
return project->mainPlotCollection()->summaryPlotCollection();
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:18:15 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryCrossPlotCollection* RiaSummaryTools::summaryCrossPlotCollection()
|
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* project = RimProject::current();
|
2019-12-09 16:18:15 -06:00
|
|
|
|
|
|
|
return project->mainPlotCollection()->summaryCrossPlotCollection();
|
|
|
|
}
|
|
|
|
|
2018-05-23 06:33:10 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryCaseMainCollection* RiaSummaryTools::summaryCaseMainCollection()
|
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* project = RimProject::current();
|
2018-05-23 06:33:10 -05:00
|
|
|
RimSummaryCaseMainCollection* summaryCaseMainCollection = project->activeOilField()->summaryCaseMainCollection();
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( summaryCaseMainCollection );
|
2018-05-23 06:33:10 -05:00
|
|
|
return summaryCaseMainCollection;
|
|
|
|
}
|
|
|
|
|
2017-10-20 03:00:16 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Update the summary curves referencing this curve, as the curve is identified by the name
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-12-09 02:21:06 -06:00
|
|
|
void RiaSummaryTools::notifyCalculatedCurveNameHasChanged( int calculationId, const QString& currentCurveName )
|
2017-10-20 03:00:16 -05:00
|
|
|
{
|
|
|
|
RimSummaryPlotCollection* summaryPlotColl = RiaSummaryTools::summaryPlotCollection();
|
|
|
|
|
2020-09-16 12:33:44 -05:00
|
|
|
for ( RimSummaryPlot* plot : summaryPlotColl->plots() )
|
2017-10-20 03:00:16 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( RimSummaryCurve* curve : plot->summaryCurves() )
|
2017-10-20 03:00:16 -05:00
|
|
|
{
|
2017-11-15 04:36:33 -06:00
|
|
|
RifEclipseSummaryAddress adr = curve->summaryAddressY();
|
2019-12-09 02:21:06 -06:00
|
|
|
if ( adr.category() == RifEclipseSummaryAddress::SUMMARY_CALCULATED && adr.id() == calculationId )
|
2017-10-20 03:00:16 -05:00
|
|
|
{
|
2019-12-09 02:21:06 -06:00
|
|
|
RifEclipseSummaryAddress updatedAdr =
|
|
|
|
RifEclipseSummaryAddress::calculatedAddress( currentCurveName.toStdString(), calculationId );
|
|
|
|
curve->setSummaryAddressYAndApplyInterpolation( updatedAdr );
|
2017-10-20 03:00:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-15 00:07:26 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-15 00:07:26 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RimSummaryPlot* RiaSummaryTools::parentSummaryPlot( caf::PdmObject* object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( parentCrossPlot( object ) )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RimSummaryPlot* summaryPlot = nullptr;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
object->firstAncestorOrThisOfType( summaryPlot );
|
2017-11-15 00:07:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return summaryPlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-15 00:07:26 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RimSummaryPlotCollection* RiaSummaryTools::parentSummaryPlotCollection( caf::PdmObject* object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
|
|
|
RimSummaryPlotCollection* summaryPlotColl = nullptr;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
object->firstAncestorOrThisOfType( summaryPlotColl );
|
2017-11-15 00:07:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return summaryPlotColl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-15 00:07:26 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RimSummaryCrossPlot* RiaSummaryTools::parentCrossPlot( caf::PdmObject* object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
|
|
|
RimSummaryCrossPlot* crossPlot = nullptr;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
object->firstAncestorOrThisOfType( crossPlot );
|
2017-11-15 00:07:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return crossPlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-15 00:07:26 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RimSummaryCrossPlotCollection* RiaSummaryTools::parentCrossPlotCollection( caf::PdmObject* object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
|
|
|
RimSummaryCrossPlotCollection* crossPlotColl = nullptr;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( object )
|
2017-11-15 00:07:26 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
object->firstAncestorOrThisOfType( crossPlotColl );
|
2017-11-15 00:07:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return crossPlotColl;
|
|
|
|
}
|
2017-12-12 06:22:16 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-12-12 06:22:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RiaSummaryTools::isSummaryCrossPlot( const RimSummaryPlot* plot )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
return dynamic_cast<const RimSummaryCrossPlot*>( plot );
|
2017-12-12 06:22:16 -06:00
|
|
|
}
|
2019-12-11 07:51:18 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RiaSummaryTools::hasAccumulatedData( const RifEclipseSummaryAddress& address )
|
|
|
|
{
|
|
|
|
if ( address.category() == RifEclipseSummaryAddress::SUMMARY_CALCULATED )
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryCase*> cases;
|
|
|
|
std::vector<RifEclipseSummaryAddress> addresses;
|
|
|
|
|
|
|
|
getSummaryCasesAndAddressesForCalculation( address.id(), cases, addresses );
|
|
|
|
for ( const RifEclipseSummaryAddress& variableAddress : addresses )
|
|
|
|
{
|
|
|
|
if ( !variableAddress.hasAccumulatedData() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-12-13 01:50:01 -06:00
|
|
|
|
2019-12-11 07:51:18 -06:00
|
|
|
// All the variables are accumulated
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return address.hasAccumulatedData();
|
|
|
|
}
|
|
|
|
|
2019-12-13 01:50:01 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-12-11 07:51:18 -06:00
|
|
|
void RiaSummaryTools::getSummaryCasesAndAddressesForCalculation( int id,
|
|
|
|
std::vector<RimSummaryCase*>& cases,
|
|
|
|
std::vector<RifEclipseSummaryAddress>& addresses )
|
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* proj = RimProject::current();
|
2019-12-11 07:51:18 -06:00
|
|
|
|
|
|
|
RimSummaryCalculationCollection* calculationColl = proj->calculationCollection();
|
|
|
|
if ( !calculationColl ) return;
|
|
|
|
|
|
|
|
RimSummaryCalculation* calculation = calculationColl->findCalculationById( id );
|
|
|
|
if ( !calculation ) return;
|
|
|
|
|
|
|
|
for ( RimSummaryCalculationVariable* v : calculation->allVariables() )
|
|
|
|
{
|
|
|
|
cases.push_back( v->summaryCase() );
|
|
|
|
addresses.push_back( v->summaryAddress()->address() );
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 03:01:12 -05:00
|
|
|
|
2021-02-12 03:50:58 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::pair<std::vector<time_t>, std::vector<double>>
|
|
|
|
RiaSummaryTools::resampledValuesForPeriod( const RifEclipseSummaryAddress& address,
|
|
|
|
const std::vector<time_t>& timeSteps,
|
|
|
|
std::vector<double>& values,
|
|
|
|
RiaQDateTimeTools::DateTimePeriod period )
|
|
|
|
{
|
|
|
|
RiaTimeHistoryCurveResampler resampler;
|
|
|
|
resampler.setCurveData( values, timeSteps );
|
|
|
|
|
|
|
|
if ( RiaSummaryTools::hasAccumulatedData( address ) )
|
|
|
|
{
|
|
|
|
resampler.resampleAndComputePeriodEndValues( period );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resampler.resampleAndComputeWeightedMeanValues( period );
|
|
|
|
}
|
|
|
|
|
|
|
|
return { resampler.resampledTimeSteps(), resampler.resampledValues() };
|
|
|
|
}
|
2022-01-21 07:32:51 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryCase* RiaSummaryTools::summaryCaseById( int caseId )
|
|
|
|
{
|
|
|
|
auto summaryCases = RimProject::current()->allSummaryCases();
|
|
|
|
|
|
|
|
for ( auto summaryCase : summaryCases )
|
|
|
|
{
|
|
|
|
if ( summaryCase->caseId() == caseId )
|
|
|
|
{
|
|
|
|
return summaryCase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|