2017-10-12 00:30:37 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-12 00:30:37 -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-12 00:30:37 -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-12 00:30:37 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-23 07:27:04 -05:00
|
|
|
#include "RimSummaryCalculation.h"
|
2017-10-12 00:30:37 -05:00
|
|
|
|
2017-10-13 05:22:35 -05:00
|
|
|
#include "expressionparser/ExpressionParser.h"
|
|
|
|
|
2020-10-13 04:19:51 -05:00
|
|
|
#include "RiaCurveMerger.h"
|
|
|
|
#include "RiaLogging.h"
|
2017-10-16 15:04:00 -05:00
|
|
|
#include "RiaSummaryCurveDefinition.h"
|
2017-10-20 03:20:53 -05:00
|
|
|
#include "RiaSummaryTools.h"
|
2017-10-16 15:04:00 -05:00
|
|
|
|
2017-11-08 06:09:05 -06:00
|
|
|
#include "RimSummaryAddress.h"
|
2017-10-23 07:42:38 -05:00
|
|
|
#include "RimSummaryCalculationCollection.h"
|
|
|
|
#include "RimSummaryCalculationVariable.h"
|
2017-10-16 15:04:00 -05:00
|
|
|
#include "RimSummaryCurve.h"
|
2022-04-06 10:39:07 -05:00
|
|
|
#include "RimSummaryMultiPlot.h"
|
|
|
|
#include "RimSummaryMultiPlotCollection.h"
|
2017-10-20 03:20:53 -05:00
|
|
|
#include "RimSummaryPlot.h"
|
2017-10-12 00:30:37 -05:00
|
|
|
|
2017-11-02 09:29:39 -05:00
|
|
|
#include "RiuExpressionContextMenuManager.h"
|
|
|
|
|
2017-11-06 06:26:18 -06:00
|
|
|
#include "cafPdmUiLineEditor.h"
|
2022-04-30 08:19:24 -05:00
|
|
|
#include "cafPdmUiTableViewEditor.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cafPdmUiTextEditor.h"
|
2017-10-13 05:22:35 -05:00
|
|
|
|
2017-10-13 07:39:30 -05:00
|
|
|
#include <algorithm>
|
2017-10-13 05:22:35 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RimSummaryCalculation, "RimSummaryCalculation" );
|
2017-10-12 00:30:37 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-12 00:30:37 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:27:04 -05:00
|
|
|
RimSummaryCalculation::RimSummaryCalculation()
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_InitObject( "RimSummaryCalculation", ":/octave.png", "Calculation", "" );
|
2017-11-03 19:14:56 -05:00
|
|
|
}
|
|
|
|
|
2017-11-06 06:26:18 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-06 06:26:18 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-04-22 05:18:34 -05:00
|
|
|
RimSummaryCalculationVariable* RimSummaryCalculation::createVariable() const
|
2017-11-06 06:26:18 -06:00
|
|
|
{
|
2022-04-22 05:18:34 -05:00
|
|
|
return new RimSummaryCalculationVariable;
|
2017-10-13 05:22:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-10-13 05:22:35 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:27:04 -05:00
|
|
|
bool RimSummaryCalculation::calculate()
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString leftHandSideVariableName = RimSummaryCalculation::findLeftHandSide( m_expression );
|
2017-10-13 05:22:35 -05:00
|
|
|
|
2018-06-08 08:10:45 -05:00
|
|
|
RiaTimeHistoryCurveMerger timeHistoryCurveMerger;
|
2017-10-13 05:22:35 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < m_variables.size(); i++ )
|
2017-10-13 05:22:35 -05:00
|
|
|
{
|
2022-04-22 05:18:34 -05:00
|
|
|
RimSummaryCalculationVariable* v = dynamic_cast<RimSummaryCalculationVariable*>( m_variables[i] );
|
2022-05-09 02:32:09 -05:00
|
|
|
CAF_ASSERT( v != nullptr );
|
2017-10-16 15:04:00 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !v->summaryCase() )
|
2017-10-16 15:04:00 -05:00
|
|
|
{
|
2020-10-13 04:19:51 -05:00
|
|
|
RiaLogging::errorInMessageBox( nullptr,
|
|
|
|
"Expression Parser",
|
|
|
|
QString( "No summary case defined for variable : %1" ).arg( v->name() ) );
|
2017-10-16 15:04:00 -05:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !v->summaryAddress() )
|
2017-10-16 15:04:00 -05:00
|
|
|
{
|
2020-10-13 04:19:51 -05:00
|
|
|
RiaLogging::errorInMessageBox( nullptr,
|
|
|
|
"Expression Parser",
|
|
|
|
QString( "No summary address defined for variable : %1" ).arg( v->name() ) );
|
2017-10-16 15:04:00 -05:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-15 05:53:46 -05:00
|
|
|
RiaSummaryCurveDefinition curveDef( v->summaryCase(), v->summaryAddress()->address(), false );
|
2017-10-16 15:04:00 -05:00
|
|
|
|
2017-11-21 01:15:29 -06:00
|
|
|
std::vector<double> curveValues;
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaSummaryCurveDefinition::resultValues( curveDef, &curveValues );
|
2017-10-16 15:04:00 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<time_t> curveTimeSteps = RiaSummaryCurveDefinition::timeSteps( curveDef );
|
2017-10-16 15:04:00 -05:00
|
|
|
|
2021-01-05 07:00:32 -06:00
|
|
|
if ( !curveTimeSteps.empty() && !curveValues.empty() )
|
|
|
|
{
|
|
|
|
timeHistoryCurveMerger.addCurveData( curveTimeSteps, curveValues );
|
|
|
|
}
|
2017-10-13 05:22:35 -05:00
|
|
|
}
|
|
|
|
|
2017-11-21 01:15:29 -06:00
|
|
|
timeHistoryCurveMerger.computeInterpolatedValues();
|
|
|
|
|
|
|
|
ExpressionParser parser;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < m_variables.size(); i++ )
|
2017-10-13 05:22:35 -05:00
|
|
|
{
|
2022-04-22 05:18:34 -05:00
|
|
|
RimSummaryCalculationVariable* v = dynamic_cast<RimSummaryCalculationVariable*>( m_variables[i] );
|
2022-05-09 02:32:09 -05:00
|
|
|
CAF_ASSERT( v != nullptr );
|
2017-10-13 05:22:35 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
parser.assignVector( v->name(), timeHistoryCurveMerger.interpolatedYValuesForAllXValues( i ) );
|
2017-10-13 05:22:35 -05:00
|
|
|
}
|
|
|
|
|
2017-11-21 01:15:29 -06:00
|
|
|
std::vector<double> resultValues;
|
2019-09-06 03:40:57 -05:00
|
|
|
resultValues.resize( timeHistoryCurveMerger.allXValues().size() );
|
2017-11-21 01:15:29 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
parser.assignVector( leftHandSideVariableName, resultValues );
|
2017-10-13 05:22:35 -05:00
|
|
|
|
|
|
|
QString errorText;
|
2021-02-01 11:38:52 -06:00
|
|
|
bool evaluatedOk = parser.expandIfStatementsAndEvaluate( m_expression, &errorText );
|
2017-10-13 05:22:35 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( evaluatedOk )
|
2017-10-13 05:22:35 -05:00
|
|
|
{
|
2017-11-21 02:19:39 -06:00
|
|
|
m_timesteps.v().clear();
|
|
|
|
m_calculatedValues.v().clear();
|
2017-11-21 01:15:29 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( timeHistoryCurveMerger.validIntervalsForAllXValues().size() > 0 )
|
2017-11-21 01:15:29 -06:00
|
|
|
{
|
2019-07-25 00:38:46 -05:00
|
|
|
size_t firstValidTimeStep = timeHistoryCurveMerger.validIntervalsForAllXValues().front().first;
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t lastValidTimeStep = timeHistoryCurveMerger.validIntervalsForAllXValues().back().second + 1;
|
2017-11-21 02:19:39 -06:00
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
if ( lastValidTimeStep > firstValidTimeStep && lastValidTimeStep <= timeHistoryCurveMerger.allXValues().size() )
|
2017-11-21 02:19:39 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<time_t> validTimeSteps( timeHistoryCurveMerger.allXValues().begin() + firstValidTimeStep,
|
|
|
|
timeHistoryCurveMerger.allXValues().begin() + lastValidTimeStep );
|
2017-11-21 01:15:29 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<double> validValues( resultValues.begin() + firstValidTimeStep,
|
|
|
|
resultValues.begin() + lastValidTimeStep );
|
2017-11-21 01:15:29 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
m_timesteps = validTimeSteps;
|
2017-11-21 02:19:39 -06:00
|
|
|
m_calculatedValues = validValues;
|
|
|
|
}
|
2017-11-21 01:15:29 -06:00
|
|
|
}
|
2017-11-14 01:41:44 -06:00
|
|
|
|
|
|
|
m_isDirty = false;
|
2017-10-13 05:22:35 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-23 06:45:29 -05:00
|
|
|
QString s = "The following error message was received from the parser library : \n\n";
|
|
|
|
s += errorText;
|
|
|
|
|
2020-10-13 04:19:51 -05:00
|
|
|
RiaLogging::errorInMessageBox( nullptr, "Expression Parser", s );
|
2017-10-13 05:22:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return evaluatedOk;
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:41:44 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-11-14 01:41:44 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-04-22 05:18:34 -05:00
|
|
|
void RimSummaryCalculation::updateDependentObjects()
|
2017-10-13 07:33:26 -05:00
|
|
|
{
|
2017-10-23 07:42:38 -05:00
|
|
|
RimSummaryCalculationCollection* calcColl = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
this->firstAncestorOrThisOfTypeAsserted( calcColl );
|
2017-10-20 03:20:53 -05:00
|
|
|
calcColl->rebuildCaseMetaData();
|
|
|
|
|
2022-04-06 10:39:07 -05:00
|
|
|
RimSummaryMultiPlotCollection* summaryPlotCollection = RiaSummaryTools::summaryMultiPlotCollection();
|
|
|
|
for ( auto multiPlot : summaryPlotCollection->multiPlots() )
|
2017-10-20 03:20:53 -05:00
|
|
|
{
|
2022-04-06 10:39:07 -05:00
|
|
|
for ( RimSummaryPlot* sumPlot : multiPlot->summaryPlots() )
|
2017-10-20 03:20:53 -05:00
|
|
|
{
|
2022-04-06 10:39:07 -05:00
|
|
|
bool plotContainsCalculatedCurves = false;
|
|
|
|
|
|
|
|
for ( RimSummaryCurve* sumCurve : sumPlot->summaryCurves() )
|
2017-10-20 03:20:53 -05:00
|
|
|
{
|
2022-04-06 10:39:07 -05:00
|
|
|
if ( sumCurve->summaryAddressY().category() == RifEclipseSummaryAddress::SUMMARY_CALCULATED )
|
|
|
|
{
|
|
|
|
sumCurve->updateConnectedEditors();
|
2017-10-20 03:20:53 -05:00
|
|
|
|
2022-04-06 10:39:07 -05:00
|
|
|
plotContainsCalculatedCurves = true;
|
|
|
|
}
|
2017-10-20 03:20:53 -05:00
|
|
|
}
|
|
|
|
|
2022-04-06 10:39:07 -05:00
|
|
|
if ( plotContainsCalculatedCurves )
|
|
|
|
{
|
|
|
|
sumPlot->loadDataAndUpdate();
|
|
|
|
}
|
2017-10-20 03:20:53 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-13 07:33:26 -05:00
|
|
|
}
|
2022-05-02 07:25:45 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimSummaryCalculation::removeDependentObjects()
|
|
|
|
{
|
|
|
|
}
|