Merge pull request #5697 from OPM/diff_vector

Summary Address : Add difference if both native and history is present
This commit is contained in:
Jacob Støren 2020-03-19 16:35:21 +01:00 committed by GitHub
commit a267179a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 4 deletions

View File

@ -17,8 +17,11 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RifReaderEclipseSummary.h"
#include "RiaFilePathTools.h"
#include "RiaStdStringTools.h"
#include "RiaStringEncodingTools.h"
#include "RifEclipseSummaryTools.h"
#include "RifReaderEclipseOutput.h"
@ -425,10 +428,6 @@ bool RifReaderEclipseSummary::values( const RifEclipseSummaryAddress& resultAddr
{
assert( m_ecl_sum != nullptr );
int variableIndex = indexFromAddress( resultAddress );
if ( variableIndex < 0 ) return false;
values->clear();
values->reserve( timeStepCount() );
@ -439,6 +438,39 @@ bool RifReaderEclipseSummary::values( const RifEclipseSummaryAddress& resultAddr
}
else if ( m_ecl_SmSpec )
{
if ( m_differenceAddresses.count( resultAddress ) )
{
std::string quantityName = resultAddress.quantityName();
auto historyQuantity = quantityName.substr( 0, quantityName.size() - differenceIdentifier().size() );
RifEclipseSummaryAddress nativeAdrNoHistory = resultAddress;
nativeAdrNoHistory.setQuantityName( historyQuantity );
auto quantityNoHistory = quantityName.substr( 0, historyQuantity.size() - 1 );
RifEclipseSummaryAddress nativeAdrHistory = resultAddress;
nativeAdrHistory.setQuantityName( quantityNoHistory );
std::vector<double> nativeValues;
std::vector<double> historyValues;
if ( !this->values( nativeAdrHistory, &nativeValues ) ) return false;
if ( !this->values( nativeAdrNoHistory, &historyValues ) ) return false;
if ( nativeValues.size() != historyValues.size() ) return false;
for ( size_t i = 0; i < nativeValues.size(); i++ )
{
double diff = nativeValues[i] - historyValues[i];
values->push_back( diff );
m_valuesCache->insertValues( resultAddress, *values );
}
return true;
}
int variableIndex = indexFromAddress( resultAddress );
if ( variableIndex < 0 ) return false;
const ecl::smspec_node& ertSumVarNode = ecl_smspec_iget_node_w_node_index( m_ecl_SmSpec, variableIndex );
int paramsIndex = ertSumVarNode.get_params_index();
@ -513,6 +545,55 @@ void RifReaderEclipseSummary::buildMetaData()
m_resultAddressToErtNodeIdx[addr] = i;
}
}
bool addDifferenceVectors = true;
if ( addDifferenceVectors )
{
const std::string historyIdentifier( "H" );
for ( const auto& adr : m_allResultAddresses )
{
RifEclipseSummaryAddress adrWithHistory;
RifEclipseSummaryAddress adrWithoutHistory;
{
std::string s = adr.quantityName();
if ( RiaStdStringTools::endsWith( s, historyIdentifier ) )
{
RifEclipseSummaryAddress candidate = adr;
std::string quantityNoHistory = s.substr( 0, s.size() - 1 );
candidate.setQuantityName( quantityNoHistory );
if ( m_allResultAddresses.count( candidate ) )
{
adrWithHistory = adr;
adrWithoutHistory = candidate;
}
}
else
{
RifEclipseSummaryAddress candidate = adr;
candidate.setQuantityName( s + historyIdentifier );
if ( m_allResultAddresses.count( candidate ) )
{
adrWithHistory = candidate;
adrWithoutHistory = adr;
}
}
}
if ( adrWithoutHistory.isValid() && adrWithHistory.isValid() )
{
RifEclipseSummaryAddress candidate = adr;
std::string s = candidate.quantityName() + differenceIdentifier();
candidate.setQuantityName( s );
m_allResultAddresses.insert( candidate );
m_differenceAddresses.insert( candidate );
}
}
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -86,6 +86,8 @@ private:
void buildMetaData();
RifRestartFileInfo getRestartFile( const QString& headerFileName );
static std::string differenceIdentifier() { return "_DIFF"; }
private:
// Taken from ecl_sum.h
typedef struct ecl_sum_struct ecl_sum_type;
@ -101,6 +103,8 @@ private:
QStringList m_warnings;
std::set<RifEclipseSummaryAddress> m_differenceAddresses;
//==================================================================================================
//
//==================================================================================================