2018-06-25 08:14:47 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016- Statoil ASA
|
2019-06-07 07:41:55 -05:00
|
|
|
//
|
2018-06-25 08:14:47 -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-06-07 07:41:55 -05:00
|
|
|
//
|
2018-06-25 08:14:47 -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-06-07 07:41:55 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-06-25 08:14:47 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-02-10 00:13:04 -06:00
|
|
|
#include "RimDerivedSummaryCase.h"
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2020-02-10 00:13:04 -06:00
|
|
|
#include "RiaApplication.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RiaCurveMerger.h"
|
2019-03-22 02:21:43 -05:00
|
|
|
#include "RiaLogging.h"
|
2018-06-25 08:14:47 -05:00
|
|
|
|
|
|
|
#include "RifDerivedEnsembleReader.h"
|
|
|
|
|
|
|
|
#include "RimProject.h"
|
2020-02-10 00:13:04 -06:00
|
|
|
#include "RimSummaryPlot.h"
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2020-02-10 00:13:04 -06:00
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
void caf::AppEnum<DerivedSummaryOperator>::setUp()
|
|
|
|
{
|
|
|
|
addItem( DerivedSummaryOperator::DERIVED_OPERATOR_SUB, "Sub", "-" );
|
|
|
|
addItem( DerivedSummaryOperator::DERIVED_OPERATOR_ADD, "Add", "+" );
|
|
|
|
setDefault( DerivedSummaryOperator::DERIVED_OPERATOR_SUB );
|
|
|
|
}
|
|
|
|
} // namespace caf
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2020-02-10 00:13:04 -06:00
|
|
|
CAF_PDM_SOURCE_INIT( RimDerivedSummaryCase, "RimDerivedEnsembleCase" );
|
2018-06-25 08:14:47 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
RimDerivedSummaryCase::RimDerivedSummaryCase()
|
2019-09-06 03:40:57 -05:00
|
|
|
: m_summaryCase1( nullptr )
|
|
|
|
, m_summaryCase2( nullptr )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_InitObject( "Summary Case", ":/SummaryCase16x16.png", "", "" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_summaryCase1, "SummaryCase1", "SummaryCase1", "", "", "" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_summaryCase2, "SummaryCase2", "SummaryCase2", "", "", "" );
|
2020-02-10 00:13:04 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_operator, "Operator", "Operator", "", "", "" );
|
2018-08-02 12:22:03 -05:00
|
|
|
|
|
|
|
m_inUse = false;
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
2018-06-25 08:58:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:58:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
RimDerivedSummaryCase::~RimDerivedSummaryCase()
|
|
|
|
{
|
|
|
|
}
|
2018-06-25 08:58:28 -05:00
|
|
|
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::setInUse( bool inUse )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
|
|
|
m_inUse = inUse;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_inUse )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
|
|
|
m_summaryCase1 = nullptr;
|
|
|
|
m_summaryCase2 = nullptr;
|
2020-02-10 00:13:04 -06:00
|
|
|
m_dataCache.clear();
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
bool RimDerivedSummaryCase::isInUse() const
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
|
|
|
return m_inUse;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::setSummaryCases( RimSummaryCase* sumCase1, RimSummaryCase* sumCase2 )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !sumCase1 || !sumCase2 ) return;
|
2018-06-25 08:14:47 -05:00
|
|
|
m_summaryCase1 = sumCase1;
|
|
|
|
m_summaryCase2 = sumCase2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
bool RimDerivedSummaryCase::needsCalculation( const RifEclipseSummaryAddress& address ) const
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
return m_dataCache.count( address ) == 0;
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
const std::vector<time_t>& RimDerivedSummaryCase::timeSteps( const RifEclipseSummaryAddress& address ) const
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
if ( m_dataCache.count( address ) == 0 )
|
|
|
|
{
|
|
|
|
static std::vector<time_t> empty;
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_dataCache.at( address ).first;
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
const std::vector<double>& RimDerivedSummaryCase::values( const RifEclipseSummaryAddress& address ) const
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
if ( m_dataCache.count( address ) == 0 )
|
|
|
|
{
|
|
|
|
static std::vector<double> empty;
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_dataCache.at( address ).second;
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::calculate( const RifEclipseSummaryAddress& address )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
clearData( address );
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2019-06-07 07:41:55 -05:00
|
|
|
RifSummaryReaderInterface* reader1 = m_summaryCase1 ? m_summaryCase1->summaryReader() : nullptr;
|
|
|
|
RifSummaryReaderInterface* reader2 = m_summaryCase2 ? m_summaryCase2->summaryReader() : nullptr;
|
2020-02-10 00:13:04 -06:00
|
|
|
if ( !reader1 || !reader2 ) return;
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !reader1->hasAddress( address ) || !reader2->hasAddress( address ) )
|
2019-03-22 02:21:43 -05:00
|
|
|
{
|
|
|
|
std::string text = address.uiText();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaLogging::warning(
|
|
|
|
"Derived Ensemble : At least one of the ensembles does not contain the summary address : " +
|
|
|
|
QString::fromStdString( text ) );
|
2019-03-22 02:21:43 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-07 07:41:55 -05:00
|
|
|
RiaTimeHistoryCurveMerger merger;
|
|
|
|
std::vector<double> values1;
|
|
|
|
std::vector<double> values2;
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
reader1->values( address, &values1 );
|
|
|
|
reader2->values( address, &values2 );
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
merger.addCurveData( reader1->timeSteps( address ), values1 );
|
|
|
|
merger.addCurveData( reader2->timeSteps( address ), values2 );
|
2018-06-25 08:14:47 -05:00
|
|
|
merger.computeInterpolatedValues();
|
|
|
|
|
2019-11-03 01:37:03 -06:00
|
|
|
const std::vector<double>& allValues1 = merger.interpolatedYValuesForAllXValues( 0 );
|
|
|
|
const std::vector<double>& allValues2 = merger.interpolatedYValuesForAllXValues( 1 );
|
2018-06-27 08:17:08 -05:00
|
|
|
|
2019-07-25 00:38:46 -05:00
|
|
|
size_t sampleCount = merger.allXValues().size();
|
2018-06-25 08:14:47 -05:00
|
|
|
std::vector<double> calculatedValues;
|
2019-09-06 03:40:57 -05:00
|
|
|
calculatedValues.reserve( sampleCount );
|
|
|
|
for ( size_t i = 0; i < sampleCount; i++ )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
if ( m_operator() == DerivedSummaryOperator::DERIVED_OPERATOR_SUB )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
calculatedValues.push_back( allValues1[i] - allValues2[i] );
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
2020-02-10 00:13:04 -06:00
|
|
|
else if ( m_operator() == DerivedSummaryOperator::DERIVED_OPERATOR_ADD )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
calculatedValues.push_back( allValues1[i] + allValues2[i] );
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 00:13:04 -06:00
|
|
|
auto& dataItem = m_dataCache[address];
|
2019-07-25 00:38:46 -05:00
|
|
|
dataItem.first = merger.allXValues();
|
2018-06-25 08:14:47 -05:00
|
|
|
dataItem.second = calculatedValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
QString RimDerivedSummaryCase::caseName() const
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
if ( m_summaryCase1 && m_summaryCase2 )
|
|
|
|
{
|
|
|
|
auto case1Name = m_summaryCase1->displayCaseName();
|
|
|
|
auto case2Name = m_summaryCase2->displayCaseName();
|
2018-06-25 08:14:47 -05:00
|
|
|
|
2020-02-10 00:13:04 -06:00
|
|
|
if ( case1Name == case2Name )
|
|
|
|
return case1Name;
|
|
|
|
else
|
|
|
|
return QString( "%1/%2" ).arg( case1Name ).arg( case2Name );
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_shortName;
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::createSummaryReaderInterface()
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2019-06-07 07:41:55 -05:00
|
|
|
RifSummaryReaderInterface* summaryCase1Reader = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_summaryCase1 )
|
2019-06-07 07:41:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_summaryCase1->summaryReader() )
|
2019-06-07 07:41:55 -05:00
|
|
|
{
|
|
|
|
m_summaryCase1->createSummaryReaderInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
summaryCase1Reader = m_summaryCase1->summaryReader();
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
m_reader.reset( new RifDerivedEnsembleReader( this, summaryCase1Reader ) );
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
RifSummaryReaderInterface* RimDerivedSummaryCase::summaryReader()
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
|
|
|
return m_reader.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::updateFilePathsFromProjectPath( const QString& newProjectPath, const QString& oldProjectPath )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
|
|
|
// NOP
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::setOperator( DerivedSummaryOperator oper )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
m_operator = oper;
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-07 07:41:55 -05:00
|
|
|
///
|
2018-06-25 08:14:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-10 00:13:04 -06:00
|
|
|
void RimDerivedSummaryCase::clearData( const RifEclipseSummaryAddress& address )
|
2018-06-25 08:14:47 -05:00
|
|
|
{
|
2020-02-10 00:13:04 -06:00
|
|
|
m_dataCache.erase( address );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimDerivedSummaryCase::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
{
|
|
|
|
// Base class
|
|
|
|
uiOrdering.add( &m_shortName );
|
|
|
|
|
|
|
|
// This class
|
|
|
|
uiOrdering.add( &m_summaryCase1 );
|
|
|
|
uiOrdering.add( &m_operator );
|
|
|
|
uiOrdering.add( &m_summaryCase2 );
|
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QList<caf::PdmOptionItemInfo>
|
|
|
|
RimDerivedSummaryCase::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly )
|
|
|
|
{
|
|
|
|
QList<caf::PdmOptionItemInfo> options;
|
|
|
|
|
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
auto summaryCases = proj->allSummaryCases();
|
|
|
|
|
|
|
|
if ( fieldNeedingOptions == &m_summaryCase1 || fieldNeedingOptions == &m_summaryCase2 )
|
|
|
|
{
|
|
|
|
for ( auto c : summaryCases )
|
|
|
|
{
|
|
|
|
if ( c != this ) options.push_back( caf::PdmOptionItemInfo( c->displayCaseName(), c ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimDerivedSummaryCase::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
|
|
|
const QVariant& oldValue,
|
|
|
|
const QVariant& newValue )
|
|
|
|
{
|
|
|
|
bool reloadData = false;
|
|
|
|
if ( changedField == &m_summaryCase2 || changedField == &m_summaryCase1 )
|
|
|
|
{
|
|
|
|
if ( !m_reader )
|
|
|
|
{
|
|
|
|
createSummaryReaderInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_reader )
|
|
|
|
{
|
|
|
|
m_reader->updateData( m_summaryCase1(), m_summaryCase2() );
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadData = true;
|
|
|
|
}
|
|
|
|
else if ( changedField == &m_operator )
|
|
|
|
{
|
|
|
|
reloadData = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RimSummaryCase::fieldChangedByUi( changedField, oldValue, newValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( reloadData )
|
|
|
|
{
|
|
|
|
m_dataCache.clear();
|
|
|
|
|
|
|
|
std::vector<caf::PdmObjectHandle*> referringObjects;
|
|
|
|
this->objectsWithReferringPtrFields( referringObjects );
|
|
|
|
|
|
|
|
std::set<RimSummaryPlot*> plotsToUpdate;
|
|
|
|
for ( auto o : referringObjects )
|
|
|
|
{
|
|
|
|
RimSummaryPlot* sumPlot = nullptr;
|
|
|
|
o->firstAncestorOrThisOfType( sumPlot );
|
|
|
|
|
|
|
|
if ( sumPlot )
|
|
|
|
{
|
|
|
|
plotsToUpdate.insert( sumPlot );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( auto p : plotsToUpdate )
|
|
|
|
{
|
|
|
|
p->loadDataAndUpdate();
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 08:14:47 -05:00
|
|
|
}
|