mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
Refactors building of addresses and introduce keyword count
This commit is contained in:
@@ -75,8 +75,6 @@ bool RifEclEclipseSummary::open( const QString& headerFileName, RiaThreadSafeLog
|
||||
m_unitSystem = RifEclipseSummaryTools::readUnitSystem( m_ecl_sum );
|
||||
}
|
||||
|
||||
buildMetaData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -314,7 +312,7 @@ int RifEclEclipseSummary::indexFromAddress( const RifEclipseSummaryAddress& resu
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclEclipseSummary::buildMetaData()
|
||||
void RifEclEclipseSummary::createAndSetAddresses()
|
||||
{
|
||||
m_allResultAddresses.clear();
|
||||
m_resultAddressToErtNodeIdx.clear();
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
private:
|
||||
int indexFromAddress( const RifEclipseSummaryAddress& resultAddress ) const;
|
||||
void buildMetaData() override;
|
||||
void createAndSetAddresses() override;
|
||||
|
||||
private:
|
||||
ecl_sum_type* m_ecl_sum;
|
||||
|
||||
@@ -30,14 +30,9 @@ RifMultipleSummaryReaders::RifMultipleSummaryReaders() = default;
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifMultipleSummaryReaders::addReader( std::unique_ptr<RifSummaryReaderInterface> reader )
|
||||
{
|
||||
if ( findReader( reader->serialNumber() ) != nullptr )
|
||||
{
|
||||
// Do not add duplicate readers
|
||||
return;
|
||||
}
|
||||
m_readers.push_back( std::move( reader ) );
|
||||
if ( findReader( reader->serialNumber() ) != nullptr ) return;
|
||||
|
||||
buildMetaData();
|
||||
m_readers.push_back( std::move( reader ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -69,7 +64,6 @@ void RifMultipleSummaryReaders::removeReader( int serialNumber )
|
||||
if ( reader != m_readers.end() )
|
||||
{
|
||||
m_readers.erase( reader );
|
||||
buildMetaData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,25 +119,32 @@ RiaDefines::EclipseUnitSystem RifMultipleSummaryReaders::unitSystem() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifMultipleSummaryReaders::buildMetaData()
|
||||
void RifMultipleSummaryReaders::createAndSetAddresses()
|
||||
{
|
||||
m_allErrorAddresses.clear();
|
||||
m_allResultAddresses.clear();
|
||||
|
||||
for ( auto& reader : m_readers )
|
||||
{
|
||||
// TODO: hack. Find a better way to rebuild calculated summary meta data.
|
||||
auto calcReader = dynamic_cast<RifCalculatedSummaryCurveReader*>( reader.get() );
|
||||
if ( calcReader ) calcReader->buildMetaData();
|
||||
reader->createAndSetAddresses();
|
||||
|
||||
{
|
||||
auto resultAddresses = reader->allResultAddresses();
|
||||
m_allResultAddresses.insert( resultAddresses.begin(), resultAddresses.end() );
|
||||
}
|
||||
auto resultAddresses = reader->allResultAddresses();
|
||||
m_allResultAddresses.insert( resultAddresses.begin(), resultAddresses.end() );
|
||||
|
||||
{
|
||||
auto errorResultAddresses = reader->allErrorAddresses();
|
||||
m_allErrorAddresses.insert( errorResultAddresses.begin(), errorResultAddresses.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();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public:
|
||||
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
void buildMetaData() override;
|
||||
void createAndSetAddresses() override;
|
||||
|
||||
protected:
|
||||
size_t keywordCount() const override;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<RifSummaryReaderInterface>> m_readers;
|
||||
|
||||
@@ -158,7 +158,7 @@ bool RifOpmCommonEclipseSummary::open( const QString& fileName, bool includeRest
|
||||
|
||||
if ( !m_standardReader && !m_enhancedReader ) return false;
|
||||
|
||||
buildMetaData();
|
||||
populateTimeSteps();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -176,11 +176,22 @@ std::vector<time_t> RifOpmCommonEclipseSummary::timeSteps( const RifEclipseSumma
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::vector<double>> RifOpmCommonEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress ) const
|
||||
{
|
||||
std::string keyword;
|
||||
|
||||
auto it = m_summaryAddressToKeywordMap.find( resultAddress );
|
||||
if ( it != m_summaryAddressToKeywordMap.end() )
|
||||
{
|
||||
keyword = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
// For ensembles, the result address may not be in the map, so we try to convert it to a text address
|
||||
keyword = resultAddress.toEclipseTextAddress();
|
||||
}
|
||||
|
||||
if ( !keyword.empty() )
|
||||
{
|
||||
std::vector<double> values;
|
||||
auto keyword = it->second;
|
||||
if ( m_enhancedReader )
|
||||
{
|
||||
auto fileValues = m_enhancedReader->get( keyword );
|
||||
@@ -232,41 +243,37 @@ RiaDefines::EclipseUnitSystem RifOpmCommonEclipseSummary::unitSystem() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifOpmCommonEclipseSummary::buildMetaData()
|
||||
size_t RifOpmCommonEclipseSummary::keywordCount() const
|
||||
{
|
||||
std::vector<std::string> keywords;
|
||||
Opm::time_point startOfSimulation;
|
||||
std::vector<float> daysSinceStartOfSimulation;
|
||||
|
||||
if ( m_enhancedReader )
|
||||
{
|
||||
keywords = m_enhancedReader->keywordList();
|
||||
startOfSimulation = m_enhancedReader->startdate();
|
||||
|
||||
if ( m_enhancedReader->numberOfTimeSteps() > 0 )
|
||||
{
|
||||
daysSinceStartOfSimulation = m_enhancedReader->get( "TIME" );
|
||||
}
|
||||
return m_enhancedReader->keywordList().size();
|
||||
}
|
||||
else if ( m_standardReader )
|
||||
{
|
||||
keywords = m_standardReader->keywordList();
|
||||
startOfSimulation = m_standardReader->startdate();
|
||||
if ( m_standardReader->numberOfTimeSteps() > 0 )
|
||||
{
|
||||
daysSinceStartOfSimulation = m_standardReader->get( "TIME" );
|
||||
}
|
||||
return m_standardReader->keywordList().size();
|
||||
}
|
||||
|
||||
const auto startAsTimeT = std::chrono::system_clock::to_time_t( startOfSimulation );
|
||||
const double secondsInOneDay = 24 * 3600;
|
||||
for ( const auto& days : daysSinceStartOfSimulation )
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifOpmCommonEclipseSummary::createAndSetAddresses()
|
||||
{
|
||||
std::vector<std::string> keywords;
|
||||
|
||||
if ( m_enhancedReader )
|
||||
{
|
||||
m_timeSteps.push_back( startAsTimeT + days * secondsInOneDay );
|
||||
keywords = m_enhancedReader->keywordList();
|
||||
}
|
||||
else if ( m_standardReader )
|
||||
{
|
||||
keywords = m_standardReader->keywordList();
|
||||
}
|
||||
|
||||
auto [addresses, addressMap] = RifOpmCommonSummaryTools::buildAddressesAndKeywordMap( keywords );
|
||||
|
||||
m_allResultAddresses = addresses;
|
||||
m_summaryAddressToKeywordMap = addressMap;
|
||||
}
|
||||
@@ -342,9 +349,47 @@ bool RifOpmCommonEclipseSummary::openFileReader( const QString& fileName, bool i
|
||||
return false;
|
||||
}
|
||||
|
||||
populateTimeSteps();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifOpmCommonEclipseSummary::populateTimeSteps()
|
||||
{
|
||||
m_timeSteps.clear();
|
||||
|
||||
Opm::time_point startOfSimulation;
|
||||
std::vector<float> daysSinceStartOfSimulation;
|
||||
|
||||
if ( m_enhancedReader )
|
||||
{
|
||||
startOfSimulation = m_enhancedReader->startdate();
|
||||
|
||||
if ( m_enhancedReader->numberOfTimeSteps() > 0 )
|
||||
{
|
||||
daysSinceStartOfSimulation = m_enhancedReader->get( "TIME" );
|
||||
}
|
||||
}
|
||||
else if ( m_standardReader )
|
||||
{
|
||||
startOfSimulation = m_standardReader->startdate();
|
||||
if ( m_standardReader->numberOfTimeSteps() > 0 )
|
||||
{
|
||||
daysSinceStartOfSimulation = m_standardReader->get( "TIME" );
|
||||
}
|
||||
}
|
||||
|
||||
const auto startAsTimeT = std::chrono::system_clock::to_time_t( startOfSimulation );
|
||||
const double secondsInOneDay = 24 * 3600;
|
||||
for ( const auto& days : daysSinceStartOfSimulation )
|
||||
{
|
||||
m_timeSteps.push_back( startAsTimeT + days * secondsInOneDay );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -80,8 +80,10 @@ public:
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
private:
|
||||
void buildMetaData() override;
|
||||
bool openFileReader( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
size_t keywordCount() const override;
|
||||
void createAndSetAddresses() override;
|
||||
bool openFileReader( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
void populateTimeSteps();
|
||||
|
||||
static void increaseEsmryFileCount();
|
||||
static QString enhancedSummaryFilename( const QString& fileName );
|
||||
|
||||
@@ -75,7 +75,26 @@ bool RifOpmHdf5Summary::open( const QString& headerFileName, bool includeRestart
|
||||
|
||||
if ( !m_eSmry || !m_hdf5Reader ) return false;
|
||||
|
||||
buildMetaData();
|
||||
m_timeSteps.clear();
|
||||
if ( m_eSmry )
|
||||
{
|
||||
// Get time step data from HDF
|
||||
if ( m_hdf5Reader )
|
||||
{
|
||||
m_timeSteps = m_hdf5Reader->timeSteps();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to using opm-reader for time step data
|
||||
auto timePoints = m_eSmry->dates();
|
||||
|
||||
for ( const auto& d : timePoints )
|
||||
{
|
||||
auto timeAsTimeT = std::chrono::system_clock::to_time_t( d );
|
||||
m_timeSteps.push_back( timeAsTimeT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -144,33 +163,14 @@ RiaDefines::EclipseUnitSystem RifOpmHdf5Summary::unitSystem() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifOpmHdf5Summary::buildMetaData()
|
||||
void RifOpmHdf5Summary::createAndSetAddresses()
|
||||
{
|
||||
if ( m_eSmry )
|
||||
{
|
||||
// Get time step data from HDF
|
||||
if ( m_hdf5Reader )
|
||||
{
|
||||
m_timeSteps = m_hdf5Reader->timeSteps();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to using opm-reader for time step data
|
||||
auto timePoints = m_eSmry->dates();
|
||||
|
||||
for ( const auto& d : timePoints )
|
||||
{
|
||||
auto timeAsTimeT = std::chrono::system_clock::to_time_t( d );
|
||||
m_timeSteps.push_back( timeAsTimeT );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto [addresses, smspecIndices, addressToKeywordMap] = RifOpmCommonSummaryTools::buildAddressesSmspecAndKeywordMap( m_eSmry.get() );
|
||||
m_allResultAddresses = addresses;
|
||||
m_adrToSmspecIndices = smspecIndices;
|
||||
m_summaryAddressToKeywordMap = addressToKeywordMap;
|
||||
}
|
||||
auto [addresses, smspecIndices, addressToKeywordMap] = RifOpmCommonSummaryTools::buildAddressesSmspecAndKeywordMap( m_eSmry.get() );
|
||||
m_allResultAddresses = addresses;
|
||||
m_adrToSmspecIndices = smspecIndices;
|
||||
m_summaryAddressToKeywordMap = addressToKeywordMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
private:
|
||||
void buildMetaData() override;
|
||||
void createAndSetAddresses() override;
|
||||
bool openESmryFile( const QString& headerFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
|
||||
private:
|
||||
|
||||
@@ -124,7 +124,6 @@ bool RifReaderEclipseSummary::open( const QString& headerFileName, RiaThreadSafe
|
||||
if ( !isValid && prefSummary->summaryDataReader() == RiaPreferencesSummary::SummaryReaderMode::OPM_COMMON )
|
||||
{
|
||||
auto opmCommonReader = std::make_unique<RifOpmCommonEclipseSummary>();
|
||||
|
||||
opmCommonReader->useEnhancedSummaryFiles( prefSummary->useEnhancedSummaryDataFiles() );
|
||||
opmCommonReader->createEnhancedSummaryFiles( prefSummary->createEnhancedSummaryDataFiles() );
|
||||
isValid = opmCommonReader->open( headerFileName, false, threadSafeLogger );
|
||||
@@ -148,11 +147,6 @@ bool RifReaderEclipseSummary::open( const QString& headerFileName, RiaThreadSafe
|
||||
}
|
||||
}
|
||||
|
||||
if ( isValid )
|
||||
{
|
||||
buildMetaData();
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@@ -229,15 +223,15 @@ std::vector<time_t> RifReaderEclipseSummary::timeSteps( const RifEclipseSummaryA
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::buildMetaData()
|
||||
void RifReaderEclipseSummary::createAndSetAddresses()
|
||||
{
|
||||
m_allResultAddresses.clear();
|
||||
m_allErrorAddresses.clear();
|
||||
|
||||
auto reader = currentSummaryReader();
|
||||
|
||||
if ( reader )
|
||||
if ( auto reader = currentSummaryReader() )
|
||||
{
|
||||
reader->createAndSetAddresses();
|
||||
|
||||
m_allResultAddresses = reader->allResultAddresses();
|
||||
m_allErrorAddresses = reader->allErrorAddresses();
|
||||
}
|
||||
@@ -278,14 +272,22 @@ void RifReaderEclipseSummary::buildMetaData()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifReaderEclipseSummary::keywordCount() const
|
||||
{
|
||||
if ( m_summaryReader ) return m_summaryReader->keywordCount();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifSummaryReaderInterface* RifReaderEclipseSummary::currentSummaryReader() const
|
||||
{
|
||||
if ( m_summaryReader ) return m_summaryReader.get();
|
||||
|
||||
return nullptr;
|
||||
return m_summaryReader.get();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -54,9 +54,10 @@ public:
|
||||
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
void buildMetaData() override;
|
||||
void createAndSetAddresses() override;
|
||||
|
||||
private:
|
||||
size_t keywordCount() const override;
|
||||
RifSummaryReaderInterface* currentSummaryReader() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -78,5 +78,8 @@ std::pair<bool, QString> RifRevealCsvSummaryReader::parse( const QString& fileNa
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
// Build metadata to populate the result addresses based on the readers
|
||||
createAndSetAddresses();
|
||||
|
||||
return std::make_pair( true, caseName );
|
||||
}
|
||||
|
||||
@@ -95,6 +95,36 @@ RiaDefines::EclipseUnitSystem RifSummaryReaderAggregator::unitSystem() const
|
||||
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifSummaryReaderAggregator::keywordCount() const
|
||||
{
|
||||
for ( const auto& reader : m_summaryReaders )
|
||||
{
|
||||
if ( reader->keywordCount() > 0 ) return reader->keywordCount();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifSummaryReaderAggregator::createAndSetAddresses()
|
||||
{
|
||||
for ( const auto& reader : m_summaryReaders )
|
||||
{
|
||||
reader->createAndSetAddresses();
|
||||
|
||||
auto resultAddresses = reader->allResultAddresses();
|
||||
m_allResultAddresses.insert( resultAddresses.begin(), resultAddresses.end() );
|
||||
|
||||
auto errorResultAddresses = reader->allErrorAddresses();
|
||||
m_allErrorAddresses.insert( errorResultAddresses.begin(), errorResultAddresses.end() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -129,15 +159,11 @@ bool RifSummaryReaderAggregator::createReadersAndImportMetaData( RiaThreadSafeLo
|
||||
// Aggregate result addresses
|
||||
for ( const auto& reader : m_summaryReaders )
|
||||
{
|
||||
{
|
||||
auto resultAddresses = reader->allResultAddresses();
|
||||
m_allResultAddresses.insert( resultAddresses.begin(), resultAddresses.end() );
|
||||
}
|
||||
auto resultAddresses = reader->allResultAddresses();
|
||||
m_allResultAddresses.insert( resultAddresses.begin(), resultAddresses.end() );
|
||||
|
||||
{
|
||||
auto errorResultAddresses = reader->allErrorAddresses();
|
||||
m_allErrorAddresses.insert( errorResultAddresses.begin(), errorResultAddresses.end() );
|
||||
}
|
||||
auto errorResultAddresses = reader->allErrorAddresses();
|
||||
m_allErrorAddresses.insert( errorResultAddresses.begin(), errorResultAddresses.end() );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -44,7 +44,10 @@ public:
|
||||
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
void createAndSetAddresses() override;
|
||||
|
||||
private:
|
||||
size_t keywordCount() const override;
|
||||
size_t timeStepCount( RifSummaryReaderInterface* reader ) const;
|
||||
void calculateOverlappingTimeSteps();
|
||||
|
||||
|
||||
@@ -54,10 +54,29 @@ RifEclipseSummaryAddress RifSummaryReaderInterface::errorAddress( const RifEclip
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifSummaryReaderInterface::buildMetaData()
|
||||
void RifSummaryReaderInterface::createAndSetAddresses()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifSummaryReaderInterface::createAddressesIfRequired()
|
||||
{
|
||||
if ( m_allResultAddresses.empty() )
|
||||
{
|
||||
createAndSetAddresses();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifSummaryReaderInterface::keywordCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -66,6 +85,17 @@ int RifSummaryReaderInterface::serialNumber() const
|
||||
return m_serialNumber;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifSummaryReaderInterface::dataObjectCount() const
|
||||
{
|
||||
if ( !m_allResultAddresses.empty() ) return m_allResultAddresses.size();
|
||||
|
||||
// Fallback to keyword count if no addresses are available. This can happen if an ensemble creates addresses for only a single realization.
|
||||
return keywordCount();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -91,5 +121,13 @@ bool RifSummaryReaderInterface::hasAddress( const RifEclipseSummaryAddress& resu
|
||||
static const RifEclipseSummaryAddress defaultAdr = RifEclipseSummaryAddress();
|
||||
if ( resultAddress == defaultAdr ) return true;
|
||||
|
||||
return ( m_allResultAddresses.count( resultAddress ) > 0 );
|
||||
if ( !m_allResultAddresses.empty() )
|
||||
{
|
||||
return ( m_allResultAddresses.count( resultAddress ) > 0 );
|
||||
}
|
||||
|
||||
// This is a fallback for cases where no addresses are present, such as when the summary reader is not yet initialized.
|
||||
// This function should not be used in performance-critical code paths.
|
||||
const auto& [isOk, vals] = values( resultAddress );
|
||||
return isOk && !vals.empty();
|
||||
}
|
||||
|
||||
@@ -52,11 +52,21 @@ public:
|
||||
virtual std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const = 0;
|
||||
virtual RiaDefines::EclipseUnitSystem unitSystem() const = 0;
|
||||
|
||||
virtual void buildMetaData();
|
||||
virtual void createAndSetAddresses();
|
||||
void createAddressesIfRequired();
|
||||
|
||||
int serialNumber() const;
|
||||
|
||||
// Returns the number of result addresses. If no addresses are present, keywordCount() is returned.
|
||||
size_t dataObjectCount() const;
|
||||
|
||||
protected:
|
||||
// The keywordCount is considered a internal method, not to be used by clients. Add a friend class to allow access
|
||||
friend class RifSummaryReaderAggregator;
|
||||
friend class RifMultipleSummaryReaders;
|
||||
friend class RifReaderEclipseSummary;
|
||||
virtual size_t keywordCount() const;
|
||||
|
||||
void increaseSerialNumber();
|
||||
|
||||
std::set<RifEclipseSummaryAddress> m_allResultAddresses; // Result and error addresses
|
||||
|
||||
@@ -58,14 +58,13 @@ void RimSummaryCalculationCollection::updateDataDependingOnCalculations()
|
||||
{
|
||||
if ( !summaryCase ) continue;
|
||||
|
||||
if ( auto reader = summaryCase->summaryReader() )
|
||||
if ( summaryCase->showVectorItemsInProjectTree() )
|
||||
{
|
||||
reader->buildMetaData();
|
||||
|
||||
if ( summaryCase->showVectorItemsInProjectTree() )
|
||||
if ( auto reader = summaryCase->summaryReader() )
|
||||
{
|
||||
summaryCase->onCalculationUpdated();
|
||||
reader->createAndSetAddresses();
|
||||
}
|
||||
summaryCase->onCalculationUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ void RimSummaryCalculationCollection::updateDataDependingOnCalculations()
|
||||
|
||||
if ( auto reader = obs->summaryReader() )
|
||||
{
|
||||
reader->buildMetaData();
|
||||
reader->createAndSetAddresses();
|
||||
obs->onCalculationUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ std::string RifCalculatedSummaryCurveReader::unitName( const RifEclipseSummaryAd
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifCalculatedSummaryCurveReader::buildMetaData()
|
||||
void RifCalculatedSummaryCurveReader::createAndSetAddresses()
|
||||
{
|
||||
m_allResultAddresses.clear();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
|
||||
void buildMetaData() override;
|
||||
void createAndSetAddresses() override;
|
||||
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ void RimCsvUserData::createSummaryReaderInterface()
|
||||
{
|
||||
m_multiSummaryReader = std::make_unique<RifMultipleSummaryReaders>();
|
||||
m_multiSummaryReader->addReader( std::move( csvUserData ) );
|
||||
|
||||
m_multiSummaryReader->addReader( std::make_unique<RifCalculatedSummaryCurveReader>( this ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,6 +355,7 @@ void RimFileSummaryCase::setSummaryData( const std::string& keyword, const std::
|
||||
projectSummaryDataWriter.clearErrorMessages();
|
||||
|
||||
openAndAttachAdditionalReader();
|
||||
m_multiSummaryReader->createAndSetAddresses();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -88,8 +88,8 @@ void RimObservedEclipseUserData::createSummaryReaderInterface()
|
||||
{
|
||||
m_multiSummaryReader = std::make_unique<RifMultipleSummaryReaders>();
|
||||
m_multiSummaryReader->addReader( std::move( myReader ) );
|
||||
|
||||
m_multiSummaryReader->addReader( std::make_unique<RifCalculatedSummaryCurveReader>( this ) );
|
||||
m_multiSummaryReader->createAndSetAddresses();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,16 @@ bool RimSummaryCase::showVectorItemsInProjectTree() const
|
||||
void RimSummaryCase::setShowVectorItemsInProjectTree( bool enable )
|
||||
{
|
||||
m_showSubNodesInTree = enable;
|
||||
|
||||
if ( m_showSubNodesInTree )
|
||||
{
|
||||
if ( auto reader = summaryReader() )
|
||||
{
|
||||
// If the reader has no result addresses, we need to build the metadata to populate the data vector folders
|
||||
reader->createAddressesIfRequired();
|
||||
}
|
||||
}
|
||||
|
||||
updateConnectedEditors();
|
||||
}
|
||||
|
||||
|
||||
@@ -370,33 +370,21 @@ void RimSummaryEnsemble::setAsEnsemble( bool isEnsemble )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<RifEclipseSummaryAddress> RimSummaryEnsemble::ensembleSummaryAddresses() const
|
||||
{
|
||||
std::set<RifEclipseSummaryAddress> addresses;
|
||||
size_t maxAddrCount = 0;
|
||||
int maxAddrIndex = -1;
|
||||
|
||||
for ( int i = 0; i < (int)m_cases.size(); i++ )
|
||||
// For performance reasons, we only return the addresses from the case with the most keywords.
|
||||
// Calling buildMetaData() on all realizations is expensive
|
||||
if ( auto caseWithMostKeywords = RimSummaryEnsembleTools::caseWithMostDataObjects( m_cases.childrenByType() ) )
|
||||
{
|
||||
RimSummaryCase* currCase = m_cases[i];
|
||||
if ( !currCase ) continue;
|
||||
|
||||
RifSummaryReaderInterface* reader = currCase->summaryReader();
|
||||
if ( !reader ) continue;
|
||||
|
||||
size_t addrCount = reader->allResultAddresses().size();
|
||||
if ( addrCount > maxAddrCount )
|
||||
if ( auto reader = caseWithMostKeywords->summaryReader() )
|
||||
{
|
||||
maxAddrCount = addrCount;
|
||||
maxAddrIndex = (int)i;
|
||||
// If the reader has no addresses, we need to build the metadata to populate them
|
||||
// This is typically the case for newly created cases or cases that have not been read yet
|
||||
reader->createAddressesIfRequired();
|
||||
|
||||
return reader->allResultAddresses();
|
||||
}
|
||||
}
|
||||
|
||||
if ( maxAddrIndex >= 0 && m_cases[maxAddrIndex]->summaryReader() )
|
||||
{
|
||||
const std::set<RifEclipseSummaryAddress>& addrs = m_cases[maxAddrIndex]->summaryReader()->allResultAddresses();
|
||||
addresses.insert( addrs.begin(), addrs.end() );
|
||||
}
|
||||
|
||||
return addresses;
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -472,3 +472,37 @@ void RimSummaryEnsembleTools::resetHighlightAllPlots()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryCase* RimSummaryEnsembleTools::caseWithMostDataObjects( const std::vector<RimSummaryCase*>& sourceCases )
|
||||
{
|
||||
size_t maxAddrCount = 0;
|
||||
size_t maxAddrIndex = sourceCases.size();
|
||||
|
||||
for ( size_t i = 0; i < sourceCases.size(); i++ )
|
||||
{
|
||||
auto currCase = sourceCases[i];
|
||||
if ( !currCase ) continue;
|
||||
|
||||
auto reader = currCase->summaryReader();
|
||||
if ( !reader ) continue;
|
||||
|
||||
// If no RifSummaryAddress is created, the number of keywords on file is returned. This can be the case for a realization in an
|
||||
// ensemble.
|
||||
auto addrCount = reader->dataObjectCount();
|
||||
if ( addrCount > maxAddrCount )
|
||||
{
|
||||
maxAddrCount = addrCount;
|
||||
maxAddrIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( maxAddrIndex < sourceCases.size() )
|
||||
{
|
||||
return sourceCases[maxAddrIndex];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -44,4 +44,6 @@ void selectSummaryCasesInProjectTree( const std::vector<
|
||||
void highlightCurvesForSummaryCases( const std::vector<RimSummaryCase*>& sourceCases );
|
||||
void resetHighlightAllPlots();
|
||||
|
||||
RimSummaryCase* caseWithMostDataObjects( const std::vector<RimSummaryCase*>& sourceCases );
|
||||
|
||||
} // namespace RimSummaryEnsembleTools
|
||||
|
||||
@@ -171,7 +171,7 @@ QString RimSummaryCaseSumo::caseName() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCaseSumo::buildMetaData()
|
||||
void RimSummaryCaseSumo::createAndSetAddresses()
|
||||
{
|
||||
if ( m_ensemble )
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
protected:
|
||||
QString caseName() const override;
|
||||
void buildMetaData() override;
|
||||
void createAndSetAddresses() override;
|
||||
|
||||
private:
|
||||
caf::PdmPointer<RimSummaryEnsembleSumo> m_ensemble;
|
||||
|
||||
@@ -441,7 +441,7 @@ void RimSummaryEnsembleSumo::buildMetaData()
|
||||
{
|
||||
for ( auto summaryCase : allSummaryCases() )
|
||||
{
|
||||
summaryCase->summaryReader()->buildMetaData();
|
||||
summaryCase->summaryReader()->createAndSetAddresses();
|
||||
}
|
||||
|
||||
RimSummaryEnsemble::buildMetaData();
|
||||
|
||||
Reference in New Issue
Block a user