mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 13:47:12 -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:
@@ -79,6 +79,15 @@ RiaPreferencesSystem::RiaPreferencesSystem()
|
||||
CAF_PDM_InitField( &m_showPdfExportDialog, "showPdfExportDialog", true, "Show PDF Export Dialog" );
|
||||
caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_showPdfExportDialog );
|
||||
|
||||
CAF_PDM_InitField( &m_useImprovedSummaryImport, "useImprovedSummaryImport", false, "Use Improved Summary Import" );
|
||||
caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_useImprovedSummaryImport );
|
||||
|
||||
CAF_PDM_InitField( &m_useMultiThreadingForSummary_TEMPORARY,
|
||||
"useMultiThreadingForSummary",
|
||||
true,
|
||||
"Use Multithreading for Summary Import (TEMPORARY)" );
|
||||
caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_useMultiThreadingForSummary_TEMPORARY );
|
||||
|
||||
CAF_PDM_InitField( &m_gtestFilter, "gtestFilter", QString(), "Unit Test Filter (gtest)" );
|
||||
CAF_PDM_InitField( &m_exportScalingFactor, "exportScalingFactor", -1.0, "Export Scaling Factor (<0 disable)" );
|
||||
|
||||
@@ -220,6 +229,22 @@ double RiaPreferencesSystem::exportPdfScalingFactor() const
|
||||
return m_exportScalingFactor();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaPreferencesSystem::useImprovedSummaryImport() const
|
||||
{
|
||||
return m_useImprovedSummaryImport();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaPreferencesSystem::useMultiThreadingForSummaryImport() const
|
||||
{
|
||||
return m_useMultiThreadingForSummary_TEMPORARY();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -284,6 +309,12 @@ void RiaPreferencesSystem::defineUiOrdering( QString uiConfigName, caf::PdmUiOrd
|
||||
group->add( &m_keywordsForLogging );
|
||||
group->add( &m_gtestFilter );
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Summary Settings - July 2025" );
|
||||
group->add( &m_useImprovedSummaryImport );
|
||||
group->add( &m_useMultiThreadingForSummary_TEMPORARY );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -57,6 +57,9 @@ public:
|
||||
bool showPdfExportDialog() const;
|
||||
double exportPdfScalingFactor() const;
|
||||
|
||||
bool useImprovedSummaryImport() const;
|
||||
bool useMultiThreadingForSummaryImport() const;
|
||||
|
||||
bool logToFile() const;
|
||||
|
||||
EclipseTextFileReaderMode eclipseTextFileReaderMode() const;
|
||||
@@ -85,6 +88,9 @@ private:
|
||||
caf::PdmField<bool> m_showPdfExportDialog;
|
||||
caf::PdmField<double> m_exportScalingFactor;
|
||||
|
||||
caf::PdmField<bool> m_useImprovedSummaryImport;
|
||||
caf::PdmField<bool> m_useMultiThreadingForSummary_TEMPORARY;
|
||||
|
||||
caf::PdmField<bool> m_showProgressBar;
|
||||
caf::PdmField<QString> m_gtestFilter;
|
||||
|
||||
|
||||
@@ -77,7 +77,8 @@ std::vector<RimSummaryCase*> createSummaryCasesFromFiles( const QStringList& fil
|
||||
|
||||
if ( !importFileInfos.empty() )
|
||||
{
|
||||
std::vector<RimSummaryCase*> sumCases = sumCaseColl->createSummaryCasesFromFileInfos( importFileInfos, true );
|
||||
const bool readStateFromFirstFile = true;
|
||||
std::vector<RimSummaryCase*> sumCases = sumCaseColl->createSummaryCasesFromFileInfos( importFileInfos, readStateFromFirstFile );
|
||||
newCases.insert( newCases.end(), sumCases.begin(), sumCases.end() );
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,9 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& fil
|
||||
: nullptr;
|
||||
if ( sumCaseColl )
|
||||
{
|
||||
std::vector<RimSummaryCase*> candidateCases = sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos );
|
||||
const bool readStateFromFirstFile = false;
|
||||
std::vector<RimSummaryCase*> candidateCases =
|
||||
sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos, readStateFromFirstFile );
|
||||
std::vector<RimSummaryCase*> duplicatedCases;
|
||||
|
||||
for ( RimSummaryCase* newSumCase : candidateCases )
|
||||
|
||||
@@ -110,6 +110,8 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifFileTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkImportUtil.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRmsWellPathReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifOpmSummaryTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEnsembleImportConfig.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -217,6 +219,8 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifFileTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkImportUtil.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRmsWellPathReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifOpmSummaryTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEnsembleImportConfig.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifCaseRealizationParametersReader.h"
|
||||
#include "RifFileParseTools.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "RifFileParseTools.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -287,23 +289,11 @@ int RifCaseRealizationParametersFileLocator::realizationNumber( const QString& m
|
||||
QDir dir( modelPath );
|
||||
QString absolutePath = dir.absolutePath();
|
||||
|
||||
return realizationNumberFromFullPath( absolutePath );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RifCaseRealizationParametersFileLocator::realizationNumberFromFullPath( const QString& path )
|
||||
{
|
||||
int resultIndex = -1;
|
||||
|
||||
QRegularExpression pattern( "realization-(\\d+)", QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpressionMatch match = pattern.match( path );
|
||||
|
||||
if ( match.hasMatch() )
|
||||
auto realizationNumber = RifOpmSummaryTools::extractRealizationNumber( absolutePath );
|
||||
if ( realizationNumber.has_value() )
|
||||
{
|
||||
resultIndex = match.captured( 1 ).toInt();
|
||||
return realizationNumber.value();
|
||||
}
|
||||
|
||||
return resultIndex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -94,5 +94,4 @@ class RifCaseRealizationParametersFileLocator
|
||||
public:
|
||||
static QString locate( const QString& modelPath );
|
||||
static int realizationNumber( const QString& modelPath );
|
||||
static int realizationNumberFromFullPath( const QString& path );
|
||||
};
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2025 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 "RifEnsembleImportConfig.h"
|
||||
|
||||
#include "Ensemble/RiaEnsembleImportTools.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RifCaseRealizationParametersReader.h"
|
||||
#include "RifEclipseSummaryTools.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEnsembleImportConfig::shouldCreateEsmryFile() const
|
||||
{
|
||||
return m_shouldCreateEsmryFile;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEnsembleImportConfig::useConfigValues() const
|
||||
{
|
||||
return m_useConfigValues;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RifEnsembleImportConfig::restartFilesForRealization( int realizationNumber ) const
|
||||
{
|
||||
QString numberString = QString::number( realizationNumber );
|
||||
|
||||
std::vector<QString> filePaths;
|
||||
for ( auto pattern : m_restartFileNamePatterns )
|
||||
{
|
||||
filePaths.push_back( pattern.replace( placeholderText(), numberString ) );
|
||||
}
|
||||
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEnsembleImportConfig::computePatternsFromSummaryFilePaths( const QString& filePath1, const QString& filePath2 )
|
||||
{
|
||||
std::vector<QString> warnings;
|
||||
|
||||
auto restartFileNames1 = RifEclipseSummaryTools::getRestartFileNamesOpm( filePath1, warnings );
|
||||
auto paramFilePath1 = RifCaseRealizationParametersFileLocator::locate( filePath1 );
|
||||
|
||||
auto restartFileNames2 = RifEclipseSummaryTools::getRestartFileNamesOpm( filePath2, warnings );
|
||||
auto paramFilePath2 = RifCaseRealizationParametersFileLocator::locate( filePath2 );
|
||||
|
||||
computeRestartPatternsFromTwoRealizations( restartFileNames1, restartFileNames2 );
|
||||
computeParameterFilePathPattern( { paramFilePath1, paramFilePath2 } );
|
||||
|
||||
m_shouldCreateEsmryFile = RifOpmSummaryTools::isEsmryConversionRequired( filePath1 );
|
||||
|
||||
m_useConfigValues = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEnsembleImportConfig::computeRestartPatternsFromTwoRealizations( const std::vector<QString>& restartFilesFirstCase,
|
||||
const std::vector<QString>& restartFilesSecondCase )
|
||||
{
|
||||
m_restartFileNamePatterns.clear();
|
||||
|
||||
if ( restartFilesFirstCase.empty() ) return;
|
||||
|
||||
if ( restartFilesFirstCase.size() != restartFilesSecondCase.size() )
|
||||
{
|
||||
RiaLogging::error( "RifEnsembleImportConfig::computeRestartPatternsFromTwoRealizations: "
|
||||
"The number of restart files for the two realizations do not match." );
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<QString> restartPatterns;
|
||||
|
||||
for ( size_t i = 0; i < restartFilesFirstCase.size(); i++ )
|
||||
{
|
||||
QStringList filePaths;
|
||||
filePaths.push_back( restartFilesFirstCase[i] );
|
||||
filePaths.push_back( restartFilesSecondCase[i] );
|
||||
|
||||
const auto [pattern, range] = RiaEnsembleImportTools::findPathPattern( filePaths, RifEnsembleImportConfig::placeholderText() );
|
||||
restartPatterns.push_back( pattern );
|
||||
}
|
||||
|
||||
m_restartFileNamePatterns = restartPatterns;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifEnsembleImportConfig::pathToParameterFile( int realizationNumber ) const
|
||||
{
|
||||
QString numberString = QString::number( realizationNumber );
|
||||
|
||||
auto parameterFilePath = m_parameterFilePathPattern;
|
||||
parameterFilePath.replace( placeholderText(), numberString );
|
||||
return parameterFilePath;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEnsembleImportConfig::computeParameterFilePathPattern( const std::vector<QString>& filePaths )
|
||||
{
|
||||
m_parameterFilePathPattern.clear();
|
||||
if ( filePaths.size() < 2 )
|
||||
{
|
||||
RiaLogging::error( "RifEnsembleImportConfig::computeParameterFilePathPattern: "
|
||||
"At least two parameter files are required to compute a pattern." );
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList filePathsList;
|
||||
for ( const auto& filePath : filePaths )
|
||||
{
|
||||
filePathsList.push_back( filePath );
|
||||
}
|
||||
|
||||
const auto [pattern, range] = RiaEnsembleImportTools::findPathPattern( filePathsList, RifEnsembleImportConfig::placeholderText() );
|
||||
|
||||
m_parameterFilePathPattern = pattern;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifEnsembleImportConfig::placeholderText()
|
||||
{
|
||||
return "$INDEX";
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2025 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RifEnsembleImportConfig
|
||||
{
|
||||
public:
|
||||
void computePatternsFromSummaryFilePaths( const QString& filePath1, const QString& filePath2 );
|
||||
|
||||
std::vector<QString> restartFilesForRealization( int realizationNumber ) const;
|
||||
QString pathToParameterFile( int realizationNumber ) const;
|
||||
bool shouldCreateEsmryFile() const;
|
||||
bool useConfigValues() const;
|
||||
|
||||
private:
|
||||
void computeRestartPatternsFromTwoRealizations( const std::vector<QString>& restartFilesFirstCase,
|
||||
const std::vector<QString>& restartFilesSecondCase );
|
||||
|
||||
void computeParameterFilePathPattern( const std::vector<QString>& filePaths );
|
||||
|
||||
static QString placeholderText();
|
||||
|
||||
private:
|
||||
bool m_useConfigValues = false;
|
||||
bool m_shouldCreateEsmryFile = false;
|
||||
std::vector<QString> m_restartFileNamePatterns;
|
||||
QString m_parameterFilePathPattern;
|
||||
};
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include "RifHdf5Exporter.h"
|
||||
#include "RifOpmCommonSummary.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -222,7 +222,7 @@ bool RifHdf5SummaryExporter::writeSummaryVectors( RifHdf5Exporter& exporter, Opm
|
||||
const std::string datasetName( "values" );
|
||||
|
||||
std::map<std::string, std::vector<RifEclipseSummaryAddress>> mapVectorNameToSummaryAddresses;
|
||||
auto [addresses, addressToKeywordMap] = RifOpmCommonSummaryTools::buildAddressesAndKeywordMap( sourceSummaryData.keywordList() );
|
||||
auto [addresses, addressToKeywordMap] = RifOpmSummaryTools::buildAddressesAndKeywordMap( sourceSummaryData.keywordList() );
|
||||
for ( const auto& adr : addresses )
|
||||
{
|
||||
auto vectorName = adr.vectorName();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaDefines.h"
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifEnsembleImportConfig.h"
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include <QString>
|
||||
@@ -43,18 +41,7 @@ namespace EclIO
|
||||
} // namespace Opm
|
||||
|
||||
class RiaThreadSafeLogger;
|
||||
|
||||
namespace RifOpmCommonSummaryTools
|
||||
{
|
||||
std::tuple<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, size_t>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
buildAddressesSmspecAndKeywordMap( const Opm::EclIO::ESmry* summaryFile );
|
||||
|
||||
std::pair<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
buildAddressesAndKeywordMap( const std::vector<std::string>& keywords );
|
||||
|
||||
SummaryCategory categoryFromKeyword( const std::string& keyword );
|
||||
|
||||
}; // namespace RifOpmCommonSummaryTools
|
||||
class RifEclipseSummaryAddress;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -69,6 +56,8 @@ public:
|
||||
void useEnhancedSummaryFiles( bool enable );
|
||||
void createEnhancedSummaryFiles( bool enable );
|
||||
|
||||
void setEnsembleImportState( RifEnsembleImportConfig ensembleImportState );
|
||||
|
||||
static void resetEnhancedSummaryFileCount();
|
||||
static size_t numberOfEnhancedSummaryFileCreated();
|
||||
|
||||
@@ -80,15 +69,14 @@ public:
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
private:
|
||||
size_t keywordCount() const override;
|
||||
void createAndSetAddresses() override;
|
||||
bool openFileReader( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
void populateTimeSteps();
|
||||
size_t keywordCount() const override;
|
||||
void createAndSetAddresses() override;
|
||||
bool openFileReader( const QString& fileName, bool includeRestartFiles, bool importEsmryFile, RiaThreadSafeLogger* threadSafeLogger );
|
||||
void populateTimeSteps();
|
||||
std::string keywordForAddress( const RifEclipseSummaryAddress& address ) const;
|
||||
|
||||
static void increaseEsmryFileCount();
|
||||
static QString enhancedSummaryFilename( const QString& fileName );
|
||||
static QString smspecSummaryFilename( const QString& fileName );
|
||||
static bool writeEsmryFile( QString& smspecFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
static void increaseEsmryFileCount();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Opm::EclIO::ESmry> m_standardReader;
|
||||
@@ -101,4 +89,6 @@ private:
|
||||
|
||||
bool m_useEsmryFiles;
|
||||
bool m_createEsmryFiles;
|
||||
|
||||
RifEnsembleImportConfig m_ensembleImportState;
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include "RifHdf5SummaryReader.h"
|
||||
#include "RifOpmCommonSummary.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Disable warning from external library to make sure treat warnings as error works
|
||||
@@ -167,7 +167,7 @@ void RifOpmHdf5Summary::createAndSetAddresses()
|
||||
{
|
||||
if ( m_eSmry )
|
||||
{
|
||||
auto [addresses, smspecIndices, addressToKeywordMap] = RifOpmCommonSummaryTools::buildAddressesSmspecAndKeywordMap( m_eSmry.get() );
|
||||
auto [addresses, smspecIndices, addressToKeywordMap] = RifOpmSummaryTools::buildAddressesSmspecAndKeywordMap( m_eSmry.get() );
|
||||
m_allResultAddresses = addresses;
|
||||
m_adrToSmspecIndices = smspecIndices;
|
||||
m_summaryAddressToKeywordMap = addressToKeywordMap;
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2025 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 "RifOpmSummaryTools.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Disable warning from external library to make sure treat warnings as error works
|
||||
#pragma warning( disable : 4267 )
|
||||
#endif
|
||||
#include "opm/io/eclipse/ESmry.hpp"
|
||||
#include "opm/io/eclipse/ExtESmry.hpp"
|
||||
|
||||
#include "QRegularExpression"
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::tuple<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, size_t>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
RifOpmSummaryTools::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>>
|
||||
RifOpmSummaryTools::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 };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifEclipseSummaryAddressDefines::SummaryCategory RifOpmSummaryTools::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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifOpmSummaryTools::enhancedSummaryFilename( const QString& fileName )
|
||||
{
|
||||
QString s( fileName );
|
||||
return s.replace( ".SMSPEC", ".ESMRY" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifOpmSummaryTools::smspecSummaryFilename( const QString& fileName )
|
||||
{
|
||||
QString s( fileName );
|
||||
return s.replace( ".ESMRY", ".SMSPEC" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOpmSummaryTools::isEsmryConversionRequired( const QString& fileName )
|
||||
{
|
||||
auto candidateEsmryFileName = enhancedSummaryFilename( fileName );
|
||||
auto smspecFileName = smspecSummaryFilename( fileName );
|
||||
|
||||
RiaLogging::debug( "RifOpmSummaryTools::isEsmryConversionRequired" );
|
||||
|
||||
if ( !QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( RiaFilePathTools::isFirstOlderThanSecond( candidateEsmryFileName.toStdString(), smspecFileName.toStdString() ) )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if ( !std::filesystem::remove( candidateEsmryFileName.toStdString() ) )
|
||||
{
|
||||
RiaLogging::error( QString( "Failed to remove file: %1" ).arg( candidateEsmryFileName ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<int, QString> RifOpmSummaryTools::extractRealizationNumber( const QString& path )
|
||||
{
|
||||
QRegularExpression pattern( "realization-(\\d+)", QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpressionMatch match = pattern.match( path );
|
||||
|
||||
if ( match.hasMatch() )
|
||||
{
|
||||
bool ok;
|
||||
int result = match.captured( 1 ).toInt( &ok );
|
||||
if ( ok )
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return std::unexpected( QString( "Invalid realization number format in path: %1" ).arg( path ) );
|
||||
}
|
||||
|
||||
return std::unexpected( QString( "Could not extract realization number from path: %1" ).arg( path ) );
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2025 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <expected>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
namespace EclIO
|
||||
{
|
||||
class ESmry;
|
||||
} // namespace EclIO
|
||||
} // namespace Opm
|
||||
|
||||
namespace RifOpmSummaryTools
|
||||
{
|
||||
std::tuple<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, size_t>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
buildAddressesSmspecAndKeywordMap( const Opm::EclIO::ESmry* summaryFile );
|
||||
|
||||
std::pair<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress, std::string>>
|
||||
buildAddressesAndKeywordMap( const std::vector<std::string>& keywords );
|
||||
|
||||
SummaryCategory categoryFromKeyword( const std::string& keyword );
|
||||
|
||||
QString enhancedSummaryFilename( const QString& fileName );
|
||||
QString smspecSummaryFilename( const QString& fileName );
|
||||
bool isEsmryConversionRequired( const QString& fileName );
|
||||
|
||||
std::expected<int, QString> extractRealizationNumber( const QString& path );
|
||||
|
||||
}; // namespace RifOpmSummaryTools
|
||||
@@ -53,6 +53,14 @@ RifReaderEclipseSummary::~RifReaderEclipseSummary()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::setEnsembleImportState( RifEnsembleImportConfig ensembleImportState )
|
||||
{
|
||||
m_ensembleImportState = ensembleImportState;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -126,6 +134,7 @@ bool RifReaderEclipseSummary::open( const QString& headerFileName, RiaThreadSafe
|
||||
auto opmCommonReader = std::make_unique<RifOpmCommonEclipseSummary>();
|
||||
opmCommonReader->useEnhancedSummaryFiles( prefSummary->useEnhancedSummaryDataFiles() );
|
||||
opmCommonReader->createEnhancedSummaryFiles( prefSummary->createEnhancedSummaryDataFiles() );
|
||||
if ( m_ensembleImportState.useConfigValues() ) opmCommonReader->setEnsembleImportState( m_ensembleImportState );
|
||||
isValid = opmCommonReader->open( headerFileName, false, threadSafeLogger );
|
||||
|
||||
if ( isValid )
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaDefines.h"
|
||||
|
||||
#include "RifEnsembleImportConfig.h"
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include <QString>
|
||||
@@ -47,6 +48,8 @@ public:
|
||||
RifReaderEclipseSummary();
|
||||
~RifReaderEclipseSummary() override;
|
||||
|
||||
void setEnsembleImportState( RifEnsembleImportConfig ensembleImportState );
|
||||
|
||||
bool open( const QString& headerFileName, RiaThreadSafeLogger* threadSafeLogger );
|
||||
|
||||
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
@@ -64,6 +67,8 @@ private:
|
||||
std::unique_ptr<RifSummaryReaderInterface> m_summaryReader;
|
||||
std::set<RifEclipseSummaryAddress> m_differenceAddresses;
|
||||
|
||||
RifEnsembleImportConfig m_ensembleImportState;
|
||||
|
||||
private:
|
||||
//==================================================================================================
|
||||
//
|
||||
|
||||
@@ -142,12 +142,18 @@ size_t RifSummaryReaderAggregator::timeStepCount( RifSummaryReaderInterface* rea
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifSummaryReaderAggregator::createReadersAndImportMetaData( RiaThreadSafeLogger* threadSafeLogger )
|
||||
bool RifSummaryReaderAggregator::createReadersAndImportMetaData( RifEnsembleImportConfig ensembleImportState,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
for ( const auto& fileName : m_fileNames )
|
||||
{
|
||||
auto candidate = std::make_unique<RifReaderEclipseSummary>();
|
||||
auto result = candidate->open( QString::fromStdString( fileName ), threadSafeLogger );
|
||||
if ( ensembleImportState.useConfigValues() )
|
||||
{
|
||||
candidate->setEnsembleImportState( ensembleImportState );
|
||||
}
|
||||
|
||||
auto result = candidate->open( QString::fromStdString( fileName ), threadSafeLogger );
|
||||
if ( result )
|
||||
{
|
||||
m_summaryReaders.push_back( std::move( candidate ) );
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifEnsembleImportConfig.h"
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -37,7 +38,7 @@ class RifSummaryReaderAggregator : public RifSummaryReaderInterface
|
||||
public:
|
||||
RifSummaryReaderAggregator( const std::vector<std::string>& filesOrderedByStartOfHistory );
|
||||
|
||||
bool createReadersAndImportMetaData( RiaThreadSafeLogger* threadSafeLogger );
|
||||
bool createReadersAndImportMetaData( RifEnsembleImportConfig ensembleImportState, RiaThreadSafeLogger* threadSafeLogger );
|
||||
|
||||
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "RifEclipseSummaryTools.h"
|
||||
#include "RifMultipleSummaryReaders.h"
|
||||
#include "RifOpmCommonSummary.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
#include "RifProjectSummaryDataWriter.h"
|
||||
#include "RifReaderEclipseSummary.h"
|
||||
#include "RifReaderOpmRft.h"
|
||||
@@ -39,6 +40,7 @@
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
|
||||
#include "RiaPreferencesSystem.h"
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QUuid>
|
||||
@@ -89,7 +91,8 @@ QString RimFileSummaryCase::caseName() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFileSummaryCase::createSummaryReaderInterfaceThreadSafe( RiaThreadSafeLogger* threadSafeLogger )
|
||||
void RimFileSummaryCase::createSummaryReaderInterfaceThreadSafe( RifEnsembleImportConfig ensembleImportState,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
// RimFileSummaryCase::findRelatedFilesAndCreateReader is a performance bottleneck. The function
|
||||
// RifEclipseSummaryTools::getRestartFile() should be refactored to use opm-common instead of resdata.
|
||||
@@ -101,7 +104,10 @@ void RimFileSummaryCase::createSummaryReaderInterfaceThreadSafe( RiaThreadSafeLo
|
||||
m_fileSummaryReaderId = -1;
|
||||
m_additionalSummaryReaderId = -1;
|
||||
|
||||
auto reader = RimFileSummaryCase::findRelatedFilesAndCreateReader( summaryHeaderFilename(), m_includeRestartFiles, threadSafeLogger );
|
||||
auto reader = RimFileSummaryCase::findRelatedFilesAndCreateReader( summaryHeaderFilename(),
|
||||
m_includeRestartFiles,
|
||||
ensembleImportState,
|
||||
threadSafeLogger );
|
||||
if ( !reader ) return;
|
||||
|
||||
m_fileSummaryReaderId = reader->serialNumber();
|
||||
@@ -119,7 +125,7 @@ void RimFileSummaryCase::createSummaryReaderInterfaceThreadSafe( RiaThreadSafeLo
|
||||
void RimFileSummaryCase::createSummaryReaderInterface()
|
||||
{
|
||||
RiaThreadSafeLogger threadSafeLogger;
|
||||
createSummaryReaderInterfaceThreadSafe( &threadSafeLogger );
|
||||
createSummaryReaderInterfaceThreadSafe( RifEnsembleImportConfig(), &threadSafeLogger );
|
||||
|
||||
auto messages = threadSafeLogger.messages();
|
||||
for ( const auto& m : messages )
|
||||
@@ -155,25 +161,48 @@ void RimFileSummaryCase::createRftReaderInterface()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<RifSummaryReaderInterface> RimFileSummaryCase::findRelatedFilesAndCreateReader( const QString& headerFileName,
|
||||
bool lookForRestartFiles,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
std::unique_ptr<RifSummaryReaderInterface> RimFileSummaryCase::findRelatedFilesAndCreateReader( const QString& headerFileName,
|
||||
bool lookForRestartFiles,
|
||||
RifEnsembleImportConfig ensembleImportState,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
if ( lookForRestartFiles )
|
||||
{
|
||||
auto startTime = RiaLogging::currentTime();
|
||||
|
||||
std::vector<QString> warnings;
|
||||
std::vector<QString> restartFileNames;
|
||||
if ( RiaPreferencesSummary::current()->summaryDataReader() == RiaPreferencesSummary::SummaryReaderMode::OPM_COMMON )
|
||||
{
|
||||
restartFileNames = RifEclipseSummaryTools::getRestartFileNamesOpm( headerFileName, warnings );
|
||||
if ( ensembleImportState.useConfigValues() )
|
||||
{
|
||||
auto realizationNumber = RifOpmSummaryTools::extractRealizationNumber( headerFileName );
|
||||
if ( !realizationNumber.has_value() )
|
||||
{
|
||||
RiaLogging::error( realizationNumber.error() );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
restartFileNames = ensembleImportState.restartFilesForRealization( realizationNumber.value() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the restart file names are not provided, we search for them
|
||||
restartFileNames = RifEclipseSummaryTools::getRestartFileNamesOpm( headerFileName, warnings );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
restartFileNames = RifEclipseSummaryTools::getRestartFileNames( headerFileName, warnings );
|
||||
}
|
||||
|
||||
bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "OpmSummaryImport" );
|
||||
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Searched for restart files for " + headerFileName, startTime );
|
||||
|
||||
if ( !restartFileNames.empty() )
|
||||
{
|
||||
auto startTime = RiaLogging::currentTime();
|
||||
|
||||
std::vector<std::string> summaryFileNames;
|
||||
summaryFileNames.push_back( headerFileName.toStdString() );
|
||||
for ( const auto& fileName : restartFileNames )
|
||||
@@ -185,16 +214,20 @@ std::unique_ptr<RifSummaryReaderInterface> RimFileSummaryCase::findRelatedFilesA
|
||||
std::reverse( summaryFileNames.begin(), summaryFileNames.end() );
|
||||
|
||||
auto summaryReader = std::make_unique<RifSummaryReaderAggregator>( summaryFileNames );
|
||||
if ( !summaryReader->createReadersAndImportMetaData( threadSafeLogger ) )
|
||||
if ( !summaryReader->createReadersAndImportMetaData( ensembleImportState, threadSafeLogger ) )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "OpmSummaryImport" );
|
||||
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Created reader", startTime );
|
||||
|
||||
return summaryReader;
|
||||
}
|
||||
}
|
||||
|
||||
auto summaryFileReader = std::make_unique<RifReaderEclipseSummary>();
|
||||
summaryFileReader->setEnsembleImportState( ensembleImportState );
|
||||
|
||||
// All restart data is taken care of by RifSummaryReaderAggregator, never read restart data from native file
|
||||
// readers
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "RimSummaryCase.h"
|
||||
|
||||
#include "RifEnsembleImportConfig.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -48,9 +50,9 @@ public:
|
||||
QString summaryHeaderFilename() const override;
|
||||
QString caseName() const override;
|
||||
|
||||
void createSummaryReaderInterfaceThreadSafe( RiaThreadSafeLogger* threadSafeLogger );
|
||||
void createSummaryReaderInterface() override;
|
||||
void createRftReaderInterface() override;
|
||||
void createSummaryReaderInterfaceThreadSafe( RifEnsembleImportConfig ensembleImportState, RiaThreadSafeLogger* threadSafeLogger );
|
||||
void createSummaryReaderInterface() override;
|
||||
void createRftReaderInterface() override;
|
||||
RifSummaryReaderInterface* summaryReader() override;
|
||||
RifReaderRftInterface* rftReader() override;
|
||||
void searchForWseglinkAndRecreateRftReader();
|
||||
@@ -60,8 +62,10 @@ public:
|
||||
void setSummaryData( const std::string& keyword, const std::string& unit, const std::vector<float>& values );
|
||||
void onProjectBeingSaved();
|
||||
|
||||
static std::unique_ptr<RifSummaryReaderInterface>
|
||||
findRelatedFilesAndCreateReader( const QString& headerFileName, bool lookForRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
static std::unique_ptr<RifSummaryReaderInterface> findRelatedFilesAndCreateReader( const QString& headerFileName,
|
||||
bool lookForRestartFiles,
|
||||
RifEnsembleImportConfig ensembleImportState,
|
||||
RiaThreadSafeLogger* threadSafeLogger );
|
||||
|
||||
protected:
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
#include "RiaEnsembleNameTools.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferencesSummary.h"
|
||||
#include "RiaPreferencesSystem.h"
|
||||
#include "Summary/RiaSummaryTools.h"
|
||||
|
||||
#include "RifCaseRealizationParametersReader.h"
|
||||
#include "RifEclipseSummaryTools.h"
|
||||
#include "RifOpmCommonSummary.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
#include "RifSummaryCaseRestartSelector.h"
|
||||
#include "Sumo/RimSummaryCaseSumo.h"
|
||||
|
||||
@@ -62,10 +64,12 @@ CAF_PDM_SOURCE_INIT( RimSummaryCaseMainCollection, "SummaryCaseCollection" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Internal function
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void addCaseRealizationParametersIfFound( RimSummaryCase& sumCase, const QString modelFolderOrFile )
|
||||
void addCaseRealizationParametersIfFound( RimSummaryCase& sumCase, const QString modelFolderOrFile, const QString& filePathCandidate )
|
||||
{
|
||||
std::shared_ptr<RigCaseRealizationParameters> parameters;
|
||||
QString parametersFile = RifCaseRealizationParametersFileLocator::locate( modelFolderOrFile );
|
||||
|
||||
QString parametersFile = filePathCandidate.isEmpty() ? RifCaseRealizationParametersFileLocator::locate( modelFolderOrFile )
|
||||
: filePathCandidate;
|
||||
if ( !parametersFile.isEmpty() )
|
||||
{
|
||||
auto reader = RifCaseRealizationReader::createReaderFromFileName( parametersFile );
|
||||
@@ -379,12 +383,21 @@ std::vector<RimSummaryEnsemble*> RimSummaryCaseMainCollection::summaryEnsembles(
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCaseMainCollection::loadAllSummaryCaseData()
|
||||
{
|
||||
std::vector<RimSummaryCase*> sumCases = allSummaryCases();
|
||||
for ( auto ensemble : summaryEnsembles() )
|
||||
{
|
||||
auto sumCases = ensemble->allSummaryCases();
|
||||
|
||||
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases );
|
||||
const bool extractStateFromFirstCase = true;
|
||||
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases, extractStateFromFirstCase );
|
||||
}
|
||||
|
||||
std::vector<RimSummaryCase*> sumCases = topLevelSummaryCases();
|
||||
|
||||
const bool extractStateFromFirstCase = false;
|
||||
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases, extractStateFromFirstCase );
|
||||
|
||||
// Create addresses for all single summary cases (not part of an ensemble)
|
||||
for ( auto sumCase : topLevelSummaryCases() )
|
||||
for ( auto sumCase : sumCases )
|
||||
{
|
||||
if ( sumCase->summaryReader() )
|
||||
{
|
||||
@@ -412,7 +425,7 @@ void RimSummaryCaseMainCollection::initAfterRead()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCaseMainCollection::loadSummaryCaseData( const std::vector<RimSummaryCase*>& summaryCases )
|
||||
void RimSummaryCaseMainCollection::loadSummaryCaseData( const std::vector<RimSummaryCase*>& summaryCases, bool extractStateFromFirstCase )
|
||||
{
|
||||
std::vector<RimFileSummaryCase*> fileSummaryCases;
|
||||
std::vector<RimSummaryCase*> otherSummaryCases;
|
||||
@@ -441,7 +454,7 @@ void RimSummaryCaseMainCollection::loadSummaryCaseData( const std::vector<RimSum
|
||||
|
||||
if ( !fileSummaryCases.empty() )
|
||||
{
|
||||
loadFileSummaryCaseData( fileSummaryCases );
|
||||
loadFileSummaryCaseData( fileSummaryCases, extractStateFromFirstCase );
|
||||
}
|
||||
|
||||
if ( !otherSummaryCases.empty() )
|
||||
@@ -455,7 +468,7 @@ void RimSummaryCaseMainCollection::loadSummaryCaseData( const std::vector<RimSum
|
||||
{
|
||||
sumCase->createSummaryReaderInterface();
|
||||
sumCase->createRftReaderInterface();
|
||||
addCaseRealizationParametersIfFound( *sumCase, sumCase->summaryHeaderFilename() );
|
||||
addCaseRealizationParametersIfFound( *sumCase, sumCase->summaryHeaderFilename(), {} );
|
||||
}
|
||||
|
||||
{
|
||||
@@ -468,7 +481,8 @@ void RimSummaryCaseMainCollection::loadSummaryCaseData( const std::vector<RimSum
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCaseMainCollection::loadFileSummaryCaseData( const std::vector<RimFileSummaryCase*>& fileSummaryCases )
|
||||
void RimSummaryCaseMainCollection::loadFileSummaryCaseData( const std::vector<RimFileSummaryCase*>& fileSummaryCases,
|
||||
bool extractStateFromFirstCase )
|
||||
{
|
||||
RiaPreferencesSummary* prefs = RiaPreferencesSummary::current();
|
||||
|
||||
@@ -505,32 +519,74 @@ void RimSummaryCaseMainCollection::loadFileSummaryCaseData( const std::vector<Ri
|
||||
}
|
||||
#endif
|
||||
|
||||
RifEnsembleImportConfig importState;
|
||||
if ( extractStateFromFirstCase && !RiaPreferencesSystem::current()->useImprovedSummaryImport() )
|
||||
{
|
||||
extractStateFromFirstCase = false;
|
||||
}
|
||||
|
||||
if ( extractStateFromFirstCase )
|
||||
{
|
||||
// If we are extracting state from the first case, we need to make sure that the first case is loaded
|
||||
// before we start loading the rest of the cases.
|
||||
if ( fileSummaryCases.size() > 1 )
|
||||
{
|
||||
std::vector<QString> warnings;
|
||||
|
||||
auto headerFileName0 = fileSummaryCases[0]->summaryHeaderFilename();
|
||||
auto headerFileName1 = fileSummaryCases[1]->summaryHeaderFilename();
|
||||
|
||||
RifEnsembleImportConfig state;
|
||||
state.computePatternsFromSummaryFilePaths( headerFileName0, headerFileName1 );
|
||||
|
||||
importState = state;
|
||||
}
|
||||
}
|
||||
|
||||
// Use openMP when reading file summary case meta data. Avoid using the virtual interface of base class
|
||||
// RimSummaryCase, as it is difficult to make sure all variants of the leaf classes are thread safe.
|
||||
// Only open the summary file reader in parallel loop to reduce risk of multi threading issues
|
||||
|
||||
{
|
||||
caf::ProgressInfo progInfo( fileSummaryCases.size(), "Loading Summary Cases" );
|
||||
|
||||
RiaLogging::info( "Loading Summary Cases" );
|
||||
RifOpmCommonEclipseSummary::resetEnhancedSummaryFileCount();
|
||||
|
||||
RiaThreadSafeLogger threadSafeLogger;
|
||||
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
|
||||
|
||||
// The HDF5 reader requires a special configuration to be thread safe. Disable threading for HDF reader.
|
||||
[[maybe_unused]] bool canUseMultipleTreads =
|
||||
[[maybe_unused]] bool canUseMultipleThreads =
|
||||
( prefs->summaryDataReader() != RiaPreferencesSummary::SummaryReaderMode::HDF5_OPM_COMMON );
|
||||
|
||||
#pragma omp parallel for schedule( dynamic ) if ( canUseMultipleTreads )
|
||||
canUseMultipleThreads = canUseMultipleThreads && RiaPreferencesSystem::current()->useMultiThreadingForSummaryImport();
|
||||
|
||||
#pragma omp parallel for schedule( dynamic ) if ( canUseMultipleThreads )
|
||||
for ( int cIdx = 0; cIdx < static_cast<int>( fileSummaryCases.size() ); ++cIdx )
|
||||
{
|
||||
RimFileSummaryCase* fileSummaryCase = fileSummaryCases[cIdx];
|
||||
if ( fileSummaryCase )
|
||||
{
|
||||
fileSummaryCase->createSummaryReaderInterfaceThreadSafe( &threadSafeLogger );
|
||||
addCaseRealizationParametersIfFound( *fileSummaryCase, fileSummaryCase->summaryHeaderFilename() );
|
||||
fileSummaryCase->createSummaryReaderInterfaceThreadSafe( importState, &threadSafeLogger );
|
||||
|
||||
QString parameterFilePath;
|
||||
if ( importState.useConfigValues() )
|
||||
{
|
||||
auto realizationNumber = RifOpmSummaryTools::extractRealizationNumber( fileSummaryCase->summaryHeaderFilename() );
|
||||
if ( realizationNumber.has_value() )
|
||||
{
|
||||
parameterFilePath = importState.pathToParameterFile( realizationNumber.value() );
|
||||
}
|
||||
}
|
||||
|
||||
auto startTime = RiaLogging::currentTime();
|
||||
addCaseRealizationParametersIfFound( *fileSummaryCase, fileSummaryCase->summaryHeaderFilename(), parameterFilePath );
|
||||
bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "OpmSummaryImport" );
|
||||
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Setting of realization parameters", startTime );
|
||||
}
|
||||
|
||||
RiaLogging::info( QString( "Completed %1" ).arg( fileSummaryCase->summaryHeaderFilename() ) );
|
||||
|
||||
progInfo.setProgress( cIdx );
|
||||
}
|
||||
for ( const auto& txt : threadSafeLogger.messages() )
|
||||
@@ -588,6 +644,7 @@ void RimSummaryCaseMainCollection::onCaseNameChanged( const SignalEmitter* emitt
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimSummaryCase*>
|
||||
RimSummaryCaseMainCollection::createSummaryCasesFromFileInfos( const std::vector<RifSummaryCaseFileResultInfo>& summaryHeaderFileInfos,
|
||||
bool readStateFromFirstFile,
|
||||
bool showProgress )
|
||||
{
|
||||
RimProject* project = RimProject::current();
|
||||
@@ -653,7 +710,7 @@ std::vector<RimSummaryCase*>
|
||||
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
|
||||
}
|
||||
|
||||
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases );
|
||||
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases, readStateFromFirstFile );
|
||||
|
||||
return sumCases;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
std::vector<RimSummaryEnsemble*> summaryEnsembles() const;
|
||||
|
||||
std::vector<RimSummaryCase*> createSummaryCasesFromFileInfos( const std::vector<RifSummaryCaseFileResultInfo>& summaryHeaderFileInfos,
|
||||
bool readStateFromFirstFile,
|
||||
bool showProgress = false );
|
||||
|
||||
RimSummaryCase* findTopLevelSummaryCaseFromFileName( const QString& fileName ) const;
|
||||
@@ -82,8 +83,8 @@ public:
|
||||
private:
|
||||
void initAfterRead() override;
|
||||
|
||||
static void loadSummaryCaseData( const std::vector<RimSummaryCase*>& summaryCases );
|
||||
static void loadFileSummaryCaseData( const std::vector<RimFileSummaryCase*>& fileSummaryCases );
|
||||
static void loadSummaryCaseData( const std::vector<RimSummaryCase*>& summaryCases, bool extractStateFromFirstCase );
|
||||
static void loadFileSummaryCaseData( const std::vector<RimFileSummaryCase*>& fileSummaryCases, bool extractStateFromFirstCase );
|
||||
static RimSummaryEnsemble* defaultAllocator();
|
||||
|
||||
void onCaseNameChanged( const SignalEmitter* emitter );
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "RifCaseRealizationParametersReader.h"
|
||||
#include "RifFileParseTools.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
|
||||
#include <QString>
|
||||
#include <numeric>
|
||||
@@ -102,7 +103,7 @@ TEST( RifCaseRealizationParametersReaderTest, FindRealizationNumber )
|
||||
QString filePath = "d:/gitroot-ceesol/ResInsight-regression-test/ModelData/ensemble_reek_with_params/realization-"
|
||||
"7/iter-0/eclipse/model/3_R001_REEK-7.SMSPEC";
|
||||
|
||||
int realisationNumber = RifCaseRealizationParametersFileLocator::realizationNumberFromFullPath( filePath );
|
||||
|
||||
EXPECT_EQ( 7, realisationNumber );
|
||||
auto realisationNumber = RifOpmSummaryTools::extractRealizationNumber( filePath );
|
||||
EXPECT_TRUE( realisationNumber.has_value() );
|
||||
EXPECT_EQ( 7, realisationNumber.value() );
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "RiaStdStringTools.h"
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifOpmCommonSummary.h"
|
||||
#include "RifOpmSummaryTools.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
@@ -84,7 +84,7 @@ RifEclipseSummaryAddressDefines::SummaryCategory RiuSummaryQuantityNameInfoProvi
|
||||
return RifEclipseSummaryAddressDefines::SummaryCategory::SUMMARY_WELL_COMPLETION;
|
||||
}
|
||||
|
||||
if ( auto category = RifOpmCommonSummaryTools::categoryFromKeyword( vectorName );
|
||||
if ( auto category = RifOpmSummaryTools::categoryFromKeyword( vectorName );
|
||||
category != RifEclipseSummaryAddressDefines::SummaryCategory::SUMMARY_INVALID )
|
||||
{
|
||||
return category;
|
||||
|
||||
Reference in New Issue
Block a user