2022-03-26 16:57:46 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2021- 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 "RifMultipleSummaryReaders.h"
|
2025-07-16 15:16:19 +02:00
|
|
|
|
2023-02-26 08:08:06 +01:00
|
|
|
#include "RimCalculatedSummaryCurveReader.h"
|
2022-03-26 16:57:46 +01:00
|
|
|
|
2026-08-06 21:18:33 +02:00
|
|
|
#include "cafAssert.h"
|
|
|
|
|
|
2022-03-26 16:57:46 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RifMultipleSummaryReaders::RifMultipleSummaryReaders() = default;
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-07-16 15:16:19 +02:00
|
|
|
void RifMultipleSummaryReaders::addReader( std::unique_ptr<RifSummaryReaderInterface> reader )
|
2022-03-26 16:57:46 +01:00
|
|
|
{
|
2025-07-17 16:32:25 +02:00
|
|
|
if ( findReader( reader->serialNumber() ) != nullptr ) return;
|
2022-03-26 16:57:46 +01:00
|
|
|
|
2025-07-17 16:32:25 +02:00
|
|
|
m_readers.push_back( std::move( reader ) );
|
2025-10-07 14:56:37 +02:00
|
|
|
|
|
|
|
|
// https://github.com/OPM/ResInsight/issues/12989
|
2025-11-06 10:56:33 +01:00
|
|
|
// Reorder readers so the calculated reader is at the front of the vector. This ensures that RifMultipleSummaryReaders::values()
|
|
|
|
|
// evaluates calculated reader first.
|
|
|
|
|
auto calculatedReaderFirst = []( const auto& first, const auto& second )
|
|
|
|
|
{
|
|
|
|
|
bool isFirstCalc = dynamic_cast<RifCalculatedSummaryCurveReader*>( first.get() ) != nullptr;
|
|
|
|
|
bool isSecondCalc = dynamic_cast<RifCalculatedSummaryCurveReader*>( second.get() ) != nullptr;
|
|
|
|
|
if ( isFirstCalc && !isSecondCalc ) return true;
|
|
|
|
|
if ( !isFirstCalc && isSecondCalc ) return false;
|
|
|
|
|
return first->serialNumber() < second->serialNumber();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::sort( m_readers.begin(), m_readers.end(), calculatedReaderFirst );
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-07-16 15:16:19 +02:00
|
|
|
RifSummaryReaderInterface* RifMultipleSummaryReaders::findReader( int serialNumber ) const
|
2022-03-26 16:57:46 +01:00
|
|
|
{
|
2025-07-16 15:16:19 +02:00
|
|
|
auto reader = std::find_if( m_readers.begin(),
|
|
|
|
|
m_readers.end(),
|
|
|
|
|
[serialNumber]( const std::unique_ptr<RifSummaryReaderInterface>& r )
|
|
|
|
|
{ return r->serialNumber() == serialNumber; } );
|
|
|
|
|
if ( reader != m_readers.end() )
|
|
|
|
|
{
|
|
|
|
|
return reader->get();
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RifMultipleSummaryReaders::removeReader( int serialNumber )
|
|
|
|
|
{
|
|
|
|
|
auto reader = std::find_if( m_readers.begin(),
|
|
|
|
|
m_readers.end(),
|
|
|
|
|
[serialNumber]( const std::unique_ptr<RifSummaryReaderInterface>& r )
|
|
|
|
|
{ return r->serialNumber() == serialNumber; } );
|
|
|
|
|
|
|
|
|
|
if ( reader != m_readers.end() )
|
|
|
|
|
{
|
|
|
|
|
m_readers.erase( reader );
|
|
|
|
|
}
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-13 12:40:08 +01:00
|
|
|
std::vector<time_t> RifMultipleSummaryReaders::timeSteps( const RifEclipseSummaryAddress& resultAddress ) const
|
2022-03-26 16:57:46 +01:00
|
|
|
{
|
|
|
|
|
for ( const auto& r : m_readers )
|
|
|
|
|
{
|
2025-07-30 07:16:29 +02:00
|
|
|
const auto& timeSteps = r->timeSteps( resultAddress );
|
|
|
|
|
if ( !timeSteps.empty() ) return timeSteps;
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 12:40:08 +01:00
|
|
|
return {};
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-09-29 17:52:31 +02:00
|
|
|
std::pair<bool, std::vector<double>> RifMultipleSummaryReaders::values( const RifEclipseSummaryAddress& resultAddress ) const
|
2022-03-26 16:57:46 +01:00
|
|
|
{
|
|
|
|
|
for ( const auto& r : m_readers )
|
|
|
|
|
{
|
2025-07-30 07:16:29 +02:00
|
|
|
const auto& okAndValues = r->values( resultAddress );
|
|
|
|
|
if ( okAndValues.first && !okAndValues.second.empty() ) return okAndValues;
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-29 17:52:31 +02:00
|
|
|
return { false, {} };
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::string RifMultipleSummaryReaders::unitName( const RifEclipseSummaryAddress& resultAddress ) const
|
|
|
|
|
{
|
|
|
|
|
for ( const auto& r : m_readers )
|
|
|
|
|
{
|
2025-07-30 07:16:29 +02:00
|
|
|
auto name = r->unitName( resultAddress );
|
|
|
|
|
if ( !name.empty() ) return name;
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RiaDefines::EclipseUnitSystem RifMultipleSummaryReaders::unitSystem() const
|
|
|
|
|
{
|
2026-08-06 21:18:33 +02:00
|
|
|
CAF_ASSERT( !m_readers.empty() );
|
2022-03-26 16:57:46 +01:00
|
|
|
|
|
|
|
|
return m_readers.at( 0 )->unitSystem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-07-17 16:32:25 +02:00
|
|
|
void RifMultipleSummaryReaders::createAndSetAddresses()
|
2022-03-26 16:57:46 +01:00
|
|
|
{
|
|
|
|
|
m_allErrorAddresses.clear();
|
|
|
|
|
m_allResultAddresses.clear();
|
|
|
|
|
|
2025-11-06 10:56:33 +01:00
|
|
|
// Loop over readers in inverted order to ensure calculated readers are processed after native file readers. Creation of summary
|
|
|
|
|
// addresses for calculated readers depend on native readers.
|
|
|
|
|
// https://github.com/OPM/ResInsight/issues/13137
|
|
|
|
|
|
|
|
|
|
std::vector<RifSummaryReaderInterface*> readers;
|
|
|
|
|
for ( auto& r : m_readers )
|
|
|
|
|
{
|
|
|
|
|
readers.push_back( r.get() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto nativeReaderFirst = []( const auto& first, const auto& second )
|
|
|
|
|
{
|
|
|
|
|
bool isFirstCalc = dynamic_cast<RifCalculatedSummaryCurveReader*>( first ) != nullptr;
|
|
|
|
|
bool isSecondCalc = dynamic_cast<RifCalculatedSummaryCurveReader*>( second ) != nullptr;
|
|
|
|
|
if ( isFirstCalc && !isSecondCalc ) return false;
|
|
|
|
|
if ( !isFirstCalc && isSecondCalc ) return true;
|
|
|
|
|
return first->serialNumber() < second->serialNumber();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::sort( readers.begin(), readers.end(), nativeReaderFirst );
|
|
|
|
|
|
|
|
|
|
for ( auto reader : readers )
|
2022-03-26 16:57:46 +01:00
|
|
|
{
|
2025-07-17 16:32:25 +02:00
|
|
|
reader->createAndSetAddresses();
|
|
|
|
|
|
|
|
|
|
auto resultAddresses = reader->allResultAddresses();
|
|
|
|
|
m_allResultAddresses.insert( resultAddresses.begin(), resultAddresses.end() );
|
|
|
|
|
|
|
|
|
|
auto errorResultAddresses = reader->allErrorAddresses();
|
|
|
|
|
m_allErrorAddresses.insert( errorResultAddresses.begin(), errorResultAddresses.end() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
size_t RifMultipleSummaryReaders::keywordCount() const
|
|
|
|
|
{
|
|
|
|
|
for ( const auto& r : m_readers )
|
|
|
|
|
{
|
|
|
|
|
if ( r->keywordCount() > 0 ) return r->keywordCount();
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|
2025-07-17 16:32:25 +02:00
|
|
|
|
|
|
|
|
return 0;
|
2022-03-26 16:57:46 +01:00
|
|
|
}
|