mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
Improves summary import for ensemble workflows
- Introducing a configuration system to automatically detect file patterns for restart and parameter files across ensemble realizations. - Adding UI elements to control improved summary import settings. - Modifying summary file reader to use the determined file patterns.
This commit is contained in:
1 parent
f9f9b6b07b
commit
b4e99e9a3a
25 files changed
+810
-313
No files matched your search
@@ -18,9 +18,9 @@
|
||||
|
||||
#include "RifOpmCommonSummary.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Disable warning from external library to make sure treat warnings as error works
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "opm/io/eclipse/ESmry.hpp"
|
||||
#include "opm/io/eclipse/ExtESmry.hpp"
|
||||
|
||||
#include "RiaPreferencesSystem.h"
|
||||
#include <QFileInfo>
|
||||
|
||||
size_t RifOpmCommonEclipseSummary::sm_createdEsmryFileCount = 0;
|
||||
@@ -63,11 +64,21 @@ void RifOpmCommonEclipseSummary::createEnhancedSummaryFiles( bool enable )
|
||||
m_createEsmryFiles = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifOpmCommonEclipseSummary::setEnsembleImportState( RifEnsembleImportConfig ensembleImportState )
|
||||
{
|
||||
m_ensembleImportState = ensembleImportState;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifOpmCommonEclipseSummary::resetEnhancedSummaryFileCount()
|
||||
{
|
||||
// This function can be called from a parallel loop, make it thread safe
|
||||
#pragma omp critical
|
||||
sm_createdEsmryFileCount = 0;
|
||||
}
|
||||
|
||||
@@ -79,6 +90,36 @@ size_t RifOpmCommonEclipseSummary::numberOfEnhancedSummaryFileCreated()
|
||||
return sm_createdEsmryFileCount;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOpmCommonEclipseSummary::writeEsmryFile( QString& smspecFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto temporarySummaryFile = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );
|
||||
|
||||
if ( temporarySummaryFile->numberOfTimeSteps() > 0 )
|
||||
{
|
||||
temporarySummaryFile->make_esmry_file();
|
||||
}
|
||||
|
||||
RifOpmCommonEclipseSummary::increaseEsmryFileCount();
|
||||
}
|
||||
catch ( std::exception& )
|
||||
{
|
||||
if ( threadSafeLogger )
|
||||
{
|
||||
QString txt = QString( "Warning, could not open summary file : %1" ).arg( smspecFileName );
|
||||
threadSafeLogger->warning( txt );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -89,76 +130,56 @@ bool RifOpmCommonEclipseSummary::open( const QString& fileName, bool includeRest
|
||||
//
|
||||
// NB! Always make sure the logic is consistent with the logic in RifHdf5SummaryExporter::ensureHdf5FileIsCreated
|
||||
|
||||
bool writeDataToEsmry = false;
|
||||
auto startTime = RiaLogging::currentTime();
|
||||
|
||||
auto candidateEsmryFileName = enhancedSummaryFilename( fileName );
|
||||
bool isEsmryConversionRequired = m_ensembleImportState.useConfigValues() ? m_ensembleImportState.shouldCreateEsmryFile()
|
||||
: RifOpmSummaryTools::isEsmryConversionRequired( fileName );
|
||||
|
||||
// Make sure to check the smspec file name, as it is supported to import ESMRY files without any SMSPEC data
|
||||
auto smspecFileName = smspecSummaryFilename( fileName );
|
||||
bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "OpmSummaryImport" );
|
||||
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Check if conversion from SMSPEC to ESMRY is required", startTime );
|
||||
|
||||
if ( !QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) && m_createEsmryFiles )
|
||||
bool hasCreatedEsmry = false;
|
||||
if ( isEsmryConversionRequired && m_createEsmryFiles )
|
||||
{
|
||||
writeDataToEsmry = true;
|
||||
auto smspecFileName = RifOpmSummaryTools::smspecSummaryFilename( fileName );
|
||||
if ( writeEsmryFile( smspecFileName, includeRestartFiles, threadSafeLogger ) )
|
||||
{
|
||||
hasCreatedEsmry = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( RiaFilePathTools::isFirstOlderThanSecond( candidateEsmryFileName.toStdString(), smspecFileName.toStdString() ) )
|
||||
bool importEsmryFile = m_useEsmryFiles;
|
||||
|
||||
if ( isEsmryConversionRequired && !hasCreatedEsmry )
|
||||
{
|
||||
// Make sure to check the SMSPEC file name, as it is supported to import ESMRY files without any SMSPEC data.
|
||||
auto smspecFileName = RifOpmSummaryTools::smspecSummaryFilename( fileName );
|
||||
auto candidateEsmryFileName = RifOpmSummaryTools::enhancedSummaryFilename( fileName );
|
||||
|
||||
// If conversion is required, but we do not create ESMRY files, we cannot use the ESMRY file
|
||||
|
||||
importEsmryFile = false;
|
||||
|
||||
QString root = QFileInfo( smspecFileName ).canonicalPath();
|
||||
|
||||
const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
|
||||
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();
|
||||
|
||||
RiaLogging::debug(
|
||||
QString( " %3 : %1 is older than %2, recreating %1." ).arg( esmryFileNameShort ).arg( smspecFileNameShort ).arg( root ) );
|
||||
|
||||
// Check if we have write permission in the folder
|
||||
QFileInfo info( smspecFileName );
|
||||
|
||||
if ( !info.isWritable() )
|
||||
{
|
||||
QString txt =
|
||||
QString( "ESMRY is older than SMSPEC, but export to file %1 failed due to missing write permissions. Aborting operation." )
|
||||
.arg( candidateEsmryFileName );
|
||||
RiaLogging::error( txt );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::remove( candidateEsmryFileName.toStdString() );
|
||||
|
||||
writeDataToEsmry = true;
|
||||
RiaLogging::warning( QString( " %3 : %1 is older than %2, importing data from newest file %2." )
|
||||
.arg( esmryFileNameShort )
|
||||
.arg( smspecFileNameShort )
|
||||
.arg( root ) );
|
||||
}
|
||||
|
||||
if ( writeDataToEsmry )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto temporarySummaryFile = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );
|
||||
|
||||
if ( temporarySummaryFile->numberOfTimeSteps() > 0 )
|
||||
{
|
||||
temporarySummaryFile->make_esmry_file();
|
||||
}
|
||||
|
||||
RifOpmCommonEclipseSummary::increaseEsmryFileCount();
|
||||
}
|
||||
catch ( std::exception& )
|
||||
{
|
||||
if ( threadSafeLogger )
|
||||
{
|
||||
QString txt = QString( "Warning, could not open summary file : %1" ).arg( smspecFileName );
|
||||
threadSafeLogger->warning( txt );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !openFileReader( fileName, includeRestartFiles, threadSafeLogger ) ) return false;
|
||||
auto timeBeforeReader = RiaLogging::currentTime();
|
||||
if ( !openFileReader( fileName, includeRestartFiles, importEsmryFile, threadSafeLogger ) ) return false;
|
||||
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Completed openFileReader", timeBeforeReader );
|
||||
|
||||
if ( !m_standardReader && !m_enhancedReader ) return false;
|
||||
|
||||
auto timeBeforeTimeSteps = RiaLogging::currentTime();
|
||||
populateTimeSteps();
|
||||
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Completed populateTimeSteps", timeBeforeTimeSteps );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -261,7 +282,7 @@ void RifOpmCommonEclipseSummary::createAndSetAddresses()
|
||||
keywords = m_standardReader->keywordList();
|
||||
}
|
||||
|
||||
auto [addresses, addressMap] = RifOpmCommonSummaryTools::buildAddressesAndKeywordMap( keywords );
|
||||
auto [addresses, addressMap] = RifOpmSummaryTools::buildAddressesAndKeywordMap( keywords );
|
||||
m_allResultAddresses = addresses;
|
||||
m_summaryAddressToKeywordMap = addressMap;
|
||||
}
|
||||
@@ -269,50 +290,22 @@ void RifOpmCommonEclipseSummary::createAndSetAddresses()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOpmCommonEclipseSummary::openFileReader( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger )
|
||||
bool RifOpmCommonEclipseSummary::openFileReader( const QString& fileName,
|
||||
bool includeRestartFiles,
|
||||
bool importEsmryFile,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
// Make sure to check the SMSPEC file name, as it is supported to import ESMRY files without any SMSPEC data.
|
||||
auto smspecFileName = smspecSummaryFilename( fileName );
|
||||
auto smspecFileName = RifOpmSummaryTools::smspecSummaryFilename( fileName );
|
||||
auto candidateEsmryFileName = RifOpmSummaryTools::enhancedSummaryFilename( fileName );
|
||||
|
||||
if ( m_useEsmryFiles )
|
||||
if ( importEsmryFile )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto candidateEsmryFileName = enhancedSummaryFilename( fileName );
|
||||
m_enhancedReader = std::make_unique<Opm::EclIO::ExtESmry>( candidateEsmryFileName.toStdString(), includeRestartFiles );
|
||||
|
||||
if ( QFile::exists( candidateEsmryFileName ) )
|
||||
{
|
||||
bool isValidEsmryFile = false;
|
||||
|
||||
if ( !QFile::exists( smspecFileName ) )
|
||||
{
|
||||
// No SMSPEC file present, OK to import ESMRY file
|
||||
isValidEsmryFile = true;
|
||||
}
|
||||
else if ( RiaFilePathTools::isFirstOlderThanSecond( smspecFileName.toStdString(), candidateEsmryFileName.toStdString() ) )
|
||||
{
|
||||
isValidEsmryFile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString root = QFileInfo( smspecFileName ).canonicalPath();
|
||||
|
||||
const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
|
||||
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();
|
||||
|
||||
RiaLogging::warning( QString( " %3 : %1 is older than %2, importing data from newest file %2." )
|
||||
.arg( esmryFileNameShort )
|
||||
.arg( smspecFileNameShort )
|
||||
.arg( root ) );
|
||||
}
|
||||
|
||||
if ( isValidEsmryFile )
|
||||
{
|
||||
m_enhancedReader = std::make_unique<Opm::EclIO::ExtESmry>( candidateEsmryFileName.toStdString(), includeRestartFiles );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
@@ -337,8 +330,6 @@ bool RifOpmCommonEclipseSummary::openFileReader( const QString& fileName, bool i
|
||||
return false;
|
||||
}
|
||||
|
||||
populateTimeSteps();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -402,139 +393,3 @@ void RifOpmCommonEclipseSummary::increaseEsmryFileCount()
|
||||
#pragma omp critical
|
||||
sm_createdEsmryFileCount++;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifOpmCommonEclipseSummary::enhancedSummaryFilename( const QString& fileName )
|
||||
{
|
||||
QString s( fileName );
|
||||
return s.replace( ".SMSPEC", ".ESMRY" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifOpmCommonEclipseSummary::smspecSummaryFilename( const QString& fileName )
|
||||
{
|
||||
QString s( fileName );
|
||||
return s.replace( ".ESMRY", ".SMSPEC" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::tuple<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, size_t>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
RifOpmCommonSummaryTools::buildAddressesSmspecAndKeywordMap( const Opm::EclIO::ESmry* summaryFile )
|
||||
{
|
||||
std::set<RifEclipseSummaryAddress> addresses;
|
||||
std::map<RifEclipseSummaryAddress, size_t> addressToSmspecIndexMap;
|
||||
std::map<RifEclipseSummaryAddress, std::string> addressToKeywordMap;
|
||||
|
||||
if ( summaryFile )
|
||||
{
|
||||
auto keywords = summaryFile->keywordList();
|
||||
for ( const auto& keyword : keywords )
|
||||
{
|
||||
auto eclAdr = RifEclipseSummaryAddress::fromEclipseTextAddress( keyword );
|
||||
if ( !eclAdr.isValid() )
|
||||
{
|
||||
// If a category is not found, use the MISC category
|
||||
eclAdr = RifEclipseSummaryAddress::miscAddress( keyword );
|
||||
}
|
||||
|
||||
if ( eclAdr.isValid() )
|
||||
{
|
||||
addresses.insert( eclAdr );
|
||||
size_t smspecIndex = summaryFile->getSmspecIndexForKeyword( keyword );
|
||||
addressToSmspecIndexMap[eclAdr] = smspecIndex;
|
||||
addressToKeywordMap[eclAdr] = keyword;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { addresses, addressToSmspecIndexMap, addressToKeywordMap };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
RifOpmCommonSummaryTools::buildAddressesAndKeywordMap( const std::vector<std::string>& keywords )
|
||||
{
|
||||
std::set<RifEclipseSummaryAddress> addresses;
|
||||
std::map<RifEclipseSummaryAddress, std::string> addressToKeywordMap;
|
||||
|
||||
std::vector<std::string> invalidKeywords;
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
std::vector<RifEclipseSummaryAddress> threadAddresses;
|
||||
std::vector<std::pair<RifEclipseSummaryAddress, std::string>> threadAddressToKeywordMap;
|
||||
std::vector<std::string> threadInvalidKeywords;
|
||||
|
||||
#pragma omp for
|
||||
for ( int index = 0; index < (int)keywords.size(); index++ )
|
||||
{
|
||||
auto keyword = keywords[index];
|
||||
|
||||
auto eclAdr = RifEclipseSummaryAddress::fromEclipseTextAddress( keyword );
|
||||
if ( !eclAdr.isValid() )
|
||||
{
|
||||
threadInvalidKeywords.push_back( keyword );
|
||||
|
||||
// If a category is not found, use the MISC category
|
||||
eclAdr = RifEclipseSummaryAddress::miscAddress( keyword );
|
||||
}
|
||||
|
||||
if ( eclAdr.isValid() )
|
||||
{
|
||||
threadAddresses.emplace_back( eclAdr );
|
||||
threadAddressToKeywordMap.emplace_back( std::make_pair( eclAdr, keyword ) );
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp critical
|
||||
{
|
||||
addresses.insert( threadAddresses.begin(), threadAddresses.end() );
|
||||
addressToKeywordMap.insert( threadAddressToKeywordMap.begin(), threadAddressToKeywordMap.end() );
|
||||
invalidKeywords.insert( invalidKeywords.end(), threadInvalidKeywords.begin(), threadInvalidKeywords.end() );
|
||||
}
|
||||
|
||||
// DEBUG code
|
||||
// Used to print keywords not being categorized correctly
|
||||
/*
|
||||
for ( const auto& kw : invalidKeywords )
|
||||
{
|
||||
RiaLogging::warning( QString::fromStdString( kw ) );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return { addresses, addressToKeywordMap };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
SummaryCategory RifOpmCommonSummaryTools::categoryFromKeyword( const std::string& keyword )
|
||||
{
|
||||
auto opmCategory = Opm::EclIO::SummaryNode::category_from_keyword( keyword );
|
||||
switch ( opmCategory )
|
||||
{
|
||||
case Opm::EclIO::SummaryNode::Category::Aquifer:
|
||||
return SummaryCategory::SUMMARY_AQUIFER;
|
||||
case Opm::EclIO::SummaryNode::Category::Block:
|
||||
return SummaryCategory::SUMMARY_BLOCK;
|
||||
case Opm::EclIO::SummaryNode::Category::Connection:
|
||||
return SummaryCategory::SUMMARY_WELL_CONNECTION;
|
||||
case Opm::EclIO::SummaryNode::Category::Completion:
|
||||
return SummaryCategory::SUMMARY_WELL_COMPLETION;
|
||||
case Opm::EclIO::SummaryNode::Category::Field:
|
||||
return SummaryCategory::SUMMARY_FIELD;
|
||||
case Opm::EclIO::SummaryNode::Category::Group:
|
||||
return SummaryCategory::SUMMARY_GROUP;
|
||||
}
|
||||
|
||||
return SummaryCategory::SUMMARY_INVALID;
|
||||
}
|
||||
Reference in new issue
Block a user