2021-03-25 12:56:09 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2021- Equinor ASA
|
|
|
|
|
//
|
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RifOpmCommonSummary.h"
|
|
|
|
|
|
2021-03-26 09:04:34 +01:00
|
|
|
#include "RiaLogging.h"
|
2026-05-06 12:00:10 +02:00
|
|
|
#include "RiaQStringFormatter.h"
|
2021-12-29 14:02:57 +01:00
|
|
|
#include "RiaStdStringTools.h"
|
2025-07-23 15:05:35 +02:00
|
|
|
#include "RifOpmSummaryTools.h"
|
2021-03-26 09:04:34 +01:00
|
|
|
|
2022-07-07 16:42:06 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
// Disable warning from external library to make sure treat warnings as error works
|
|
|
|
|
#pragma warning( disable : 4267 )
|
|
|
|
|
#endif
|
2021-03-25 12:56:09 +01:00
|
|
|
#include "opm/io/eclipse/ESmry.hpp"
|
2021-09-10 12:27:25 +00:00
|
|
|
#include "opm/io/eclipse/ExtESmry.hpp"
|
2021-03-25 12:56:09 +01:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
#include "RiaPreferencesSystem.h"
|
2021-09-10 16:36:25 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
|
|
size_t RifOpmCommonEclipseSummary::sm_createdEsmryFileCount = 0;
|
2021-03-25 12:56:09 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RifOpmCommonEclipseSummary::RifOpmCommonEclipseSummary()
|
2021-09-10 16:36:25 +02:00
|
|
|
: m_useEsmryFiles( false )
|
|
|
|
|
, m_createEsmryFiles( false )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-09-10 16:36:25 +02:00
|
|
|
RifOpmCommonEclipseSummary::~RifOpmCommonEclipseSummary() = default;
|
2021-03-25 12:56:09 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-09-10 16:36:25 +02:00
|
|
|
void RifOpmCommonEclipseSummary::useEnhancedSummaryFiles( bool enable )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2021-09-10 16:36:25 +02:00
|
|
|
m_useEsmryFiles = enable;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-09-10 16:36:25 +02:00
|
|
|
void RifOpmCommonEclipseSummary::createEnhancedSummaryFiles( bool enable )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2021-09-10 16:36:25 +02:00
|
|
|
m_createEsmryFiles = enable;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RifOpmCommonEclipseSummary::setEnsembleImportState( RifEnsembleImportConfig ensembleImportState )
|
|
|
|
|
{
|
|
|
|
|
m_ensembleImportState = ensembleImportState;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 12:56:09 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-09-10 16:36:25 +02:00
|
|
|
void RifOpmCommonEclipseSummary::resetEnhancedSummaryFileCount()
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2025-07-23 15:05:35 +02:00
|
|
|
// This function can be called from a parallel loop, make it thread safe
|
2026-08-24 14:32:17 +02:00
|
|
|
#pragma omp critical( critical_section_createdEsmryFileCount )
|
2021-09-10 16:36:25 +02:00
|
|
|
sm_createdEsmryFileCount = 0;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-09-10 16:36:25 +02:00
|
|
|
size_t RifOpmCommonEclipseSummary::numberOfEnhancedSummaryFileCreated()
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2021-09-10 16:36:25 +02:00
|
|
|
return sm_createdEsmryFileCount;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 12:56:09 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-01-03 14:52:33 +01:00
|
|
|
bool RifOpmCommonEclipseSummary::open( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
// If an ESMRY file is present, and the SMSPEC file is newer than the ESMRY file, the ESMRY file will be recreated.
|
|
|
|
|
// If no ESMRY file is present, the ESMRY file will be created if the flag m_createEsmryFiles is set to true.
|
|
|
|
|
//
|
|
|
|
|
// NB! Always make sure the logic is consistent with the logic in RifHdf5SummaryExporter::ensureHdf5FileIsCreated
|
|
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
auto startTime = RiaLogging::currentTime();
|
2024-04-19 15:09:15 +02:00
|
|
|
|
2025-09-30 07:43:44 +02:00
|
|
|
bool isEsmryConversionRequired = RifOpmSummaryTools::isEsmryConversionRequired( fileName );
|
2024-04-19 15:09:15 +02:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "OpmSummaryImport" );
|
|
|
|
|
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Check if conversion from SMSPEC to ESMRY is required", startTime );
|
2024-04-19 15:09:15 +02:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
bool hasCreatedEsmry = false;
|
|
|
|
|
if ( isEsmryConversionRequired && m_createEsmryFiles )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2025-07-23 15:05:35 +02:00
|
|
|
auto smspecFileName = RifOpmSummaryTools::smspecSummaryFilename( fileName );
|
|
|
|
|
if ( writeEsmryFile( smspecFileName, includeRestartFiles, threadSafeLogger ) )
|
2024-04-19 15:09:15 +02:00
|
|
|
{
|
2025-07-23 15:05:35 +02:00
|
|
|
hasCreatedEsmry = true;
|
2023-01-03 14:52:33 +01:00
|
|
|
}
|
2024-04-19 15:09:15 +02:00
|
|
|
}
|
2021-03-26 13:52:26 +01:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
bool importEsmryFile = m_useEsmryFiles;
|
|
|
|
|
|
|
|
|
|
if ( isEsmryConversionRequired && !hasCreatedEsmry )
|
2024-04-19 15:09:15 +02:00
|
|
|
{
|
2025-07-23 15:05:35 +02:00
|
|
|
// 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 );
|
2024-04-19 15:09:15 +02:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
// If conversion is required, but we do not create ESMRY files, we cannot use the ESMRY file
|
2021-09-10 12:27:25 +00:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
importEsmryFile = false;
|
2024-04-19 15:09:15 +02:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
QString root = QFileInfo( smspecFileName ).canonicalPath();
|
|
|
|
|
|
|
|
|
|
const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
|
|
|
|
|
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();
|
|
|
|
|
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::warning(
|
|
|
|
|
std::format( " {2} : {0} is older than {1}, importing data from newest file {1}.", esmryFileNameShort, smspecFileNameShort, root ) );
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
auto timeBeforeReader = RiaLogging::currentTime();
|
|
|
|
|
if ( !openFileReader( fileName, includeRestartFiles, importEsmryFile, threadSafeLogger ) ) return false;
|
|
|
|
|
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Completed openFileReader", timeBeforeReader );
|
2021-09-10 12:27:25 +00:00
|
|
|
|
2021-09-10 16:36:25 +02:00
|
|
|
if ( !m_standardReader && !m_enhancedReader ) return false;
|
2021-03-25 12:56:09 +01:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
auto timeBeforeTimeSteps = RiaLogging::currentTime();
|
2025-07-17 16:32:25 +02:00
|
|
|
populateTimeSteps();
|
2025-07-23 15:05:35 +02:00
|
|
|
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Completed populateTimeSteps", timeBeforeTimeSteps );
|
2021-03-25 12:56:09 +01:00
|
|
|
|
2026-10-19 14:15:55 +02:00
|
|
|
m_fileName = fileName;
|
|
|
|
|
m_unitSystem = std::nullopt;
|
|
|
|
|
|
2021-03-25 12:56:09 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-13 12:40:08 +01:00
|
|
|
std::vector<time_t> RifOpmCommonEclipseSummary::timeSteps( const RifEclipseSummaryAddress& resultAddress ) const
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
|
|
|
|
return m_timeSteps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-09-29 17:52:31 +02:00
|
|
|
std::pair<bool, std::vector<double>> RifOpmCommonEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress ) const
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2025-07-18 08:05:10 +02:00
|
|
|
std::string keyword = keywordForAddress( resultAddress );
|
2025-07-17 16:32:25 +02:00
|
|
|
if ( !keyword.empty() )
|
2021-09-10 12:27:25 +00:00
|
|
|
{
|
2023-09-29 17:52:31 +02:00
|
|
|
std::vector<double> values;
|
2026-04-15 14:40:25 +02:00
|
|
|
try
|
2021-09-10 12:27:25 +00:00
|
|
|
{
|
2026-04-15 14:40:25 +02:00
|
|
|
if ( m_enhancedReader && m_enhancedReader->hasKey( keyword ) )
|
|
|
|
|
{
|
|
|
|
|
auto fileValues = m_enhancedReader->get( keyword );
|
|
|
|
|
values.insert( values.begin(), fileValues.begin(), fileValues.end() );
|
|
|
|
|
}
|
|
|
|
|
else if ( m_standardReader && m_standardReader->hasKey( keyword ) )
|
|
|
|
|
{
|
|
|
|
|
auto fileValues = m_standardReader->get( keyword );
|
|
|
|
|
values.insert( values.begin(), fileValues.begin(), fileValues.end() );
|
|
|
|
|
}
|
2021-09-10 12:27:25 +00:00
|
|
|
}
|
2026-04-15 14:40:25 +02:00
|
|
|
catch ( const std::exception& e )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::warning( std::format( "Summary reader failed to load keyword '{}': {}", keyword, e.what() ) );
|
2026-04-15 14:40:25 +02:00
|
|
|
return { false, {} };
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
2023-09-29 17:52:31 +02:00
|
|
|
return { true, values };
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-29 17:52:31 +02:00
|
|
|
return { false, {} };
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::string RifOpmCommonEclipseSummary::unitName( const RifEclipseSummaryAddress& resultAddress ) const
|
|
|
|
|
{
|
2021-12-29 14:02:57 +01:00
|
|
|
std::string nameString;
|
2025-07-18 08:05:10 +02:00
|
|
|
|
|
|
|
|
std::string keyword = keywordForAddress( resultAddress );
|
|
|
|
|
if ( !keyword.empty() )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2025-07-18 08:05:10 +02:00
|
|
|
if ( m_enhancedReader && m_enhancedReader->hasKey( keyword ) )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2021-12-29 14:02:57 +01:00
|
|
|
nameString = m_enhancedReader->get_unit( keyword );
|
2021-09-10 11:41:29 +02:00
|
|
|
}
|
2025-07-18 08:05:10 +02:00
|
|
|
else if ( m_standardReader && m_standardReader->hasKey( keyword ) )
|
2021-09-10 11:41:29 +02:00
|
|
|
{
|
2021-12-29 14:02:57 +01:00
|
|
|
nameString = m_standardReader->get_unit( keyword );
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 20:11:49 +02:00
|
|
|
return std::string( RiaStdStringTools::trimString( nameString ) );
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RiaDefines::EclipseUnitSystem RifOpmCommonEclipseSummary::unitSystem() const
|
|
|
|
|
{
|
2026-10-19 14:15:55 +02:00
|
|
|
if ( !m_unitSystem ) m_unitSystem = detectUnitSystem();
|
|
|
|
|
return *m_unitSystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RiaDefines::EclipseUnitSystem RifOpmCommonEclipseSummary::detectUnitSystem() const
|
|
|
|
|
{
|
|
|
|
|
auto smspecFileName = RifOpmSummaryTools::smspecSummaryFilename( m_fileName );
|
|
|
|
|
auto unitSystem = RifOpmSummaryTools::readUnitSystem( smspecFileName );
|
|
|
|
|
|
|
|
|
|
// ESMRY files can be imported without SMSPEC, and ESMRY has no unit system flag
|
|
|
|
|
if ( unitSystem == RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN && m_enhancedReader ) return unitSystemFromVectorUnits();
|
|
|
|
|
|
|
|
|
|
return unitSystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Units from different systems can be mixed (PVT-M, user defined vectors), so only accept a single match
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RiaDefines::EclipseUnitSystem RifOpmCommonEclipseSummary::unitSystemFromVectorUnits() const
|
|
|
|
|
{
|
|
|
|
|
static const std::map<std::string, RiaDefines::EclipseUnitSystem> unitToSystem = {
|
|
|
|
|
{ "PSIA", RiaDefines::EclipseUnitSystem::UNITS_FIELD },
|
|
|
|
|
{ "STB", RiaDefines::EclipseUnitSystem::UNITS_FIELD },
|
|
|
|
|
{ "STB/DAY", RiaDefines::EclipseUnitSystem::UNITS_FIELD },
|
|
|
|
|
{ "MSCF/DAY", RiaDefines::EclipseUnitSystem::UNITS_FIELD },
|
|
|
|
|
{ "BARSA", RiaDefines::EclipseUnitSystem::UNITS_METRIC },
|
|
|
|
|
{ "SM3", RiaDefines::EclipseUnitSystem::UNITS_METRIC },
|
|
|
|
|
{ "SM3/DAY", RiaDefines::EclipseUnitSystem::UNITS_METRIC },
|
|
|
|
|
{ "ATMA", RiaDefines::EclipseUnitSystem::UNITS_LAB },
|
|
|
|
|
{ "SCC", RiaDefines::EclipseUnitSystem::UNITS_LAB },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto detected = RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
|
|
|
|
for ( const auto& keyword : m_enhancedReader->keywordList() )
|
|
|
|
|
{
|
|
|
|
|
const auto unit = std::string( RiaStdStringTools::trimString( m_enhancedReader->get_unit( keyword ) ) );
|
|
|
|
|
auto it = unitToSystem.find( unit );
|
|
|
|
|
if ( it == unitToSystem.end() ) continue;
|
|
|
|
|
|
|
|
|
|
if ( detected == RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN )
|
|
|
|
|
detected = it->second;
|
|
|
|
|
else if ( detected != it->second )
|
|
|
|
|
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return detected;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-07-17 16:32:25 +02:00
|
|
|
size_t RifOpmCommonEclipseSummary::keywordCount() const
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2021-09-10 16:36:25 +02:00
|
|
|
if ( m_enhancedReader )
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
2025-07-17 16:32:25 +02:00
|
|
|
return m_enhancedReader->keywordList().size();
|
2021-09-10 11:41:29 +02:00
|
|
|
}
|
2021-09-13 08:36:51 +02:00
|
|
|
else if ( m_standardReader )
|
2021-09-10 11:41:29 +02:00
|
|
|
{
|
2025-07-17 16:32:25 +02:00
|
|
|
return m_standardReader->keywordList().size();
|
2021-09-10 11:41:29 +02:00
|
|
|
}
|
2021-03-25 12:56:09 +01:00
|
|
|
|
2025-07-17 16:32:25 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RifOpmCommonEclipseSummary::createAndSetAddresses()
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> keywords;
|
|
|
|
|
|
|
|
|
|
if ( m_enhancedReader )
|
2021-09-10 11:41:29 +02:00
|
|
|
{
|
2025-07-17 16:32:25 +02:00
|
|
|
keywords = m_enhancedReader->keywordList();
|
|
|
|
|
}
|
|
|
|
|
else if ( m_standardReader )
|
|
|
|
|
{
|
|
|
|
|
keywords = m_standardReader->keywordList();
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
2021-09-10 11:41:29 +02:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
auto [addresses, addressMap] = RifOpmSummaryTools::buildAddressesAndKeywordMap( keywords );
|
2021-09-10 16:36:25 +02:00
|
|
|
m_allResultAddresses = addresses;
|
|
|
|
|
m_summaryAddressToKeywordMap = addressMap;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 13:52:26 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-07-23 15:05:35 +02:00
|
|
|
bool RifOpmCommonEclipseSummary::openFileReader( const QString& fileName,
|
|
|
|
|
bool includeRestartFiles,
|
|
|
|
|
bool importEsmryFile,
|
|
|
|
|
RiaThreadSafeLogger* threadSafeLogger )
|
2021-03-26 13:52:26 +01:00
|
|
|
{
|
2023-01-03 14:52:33 +01:00
|
|
|
// Make sure to check the SMSPEC file name, as it is supported to import ESMRY files without any SMSPEC data.
|
2025-07-23 15:05:35 +02:00
|
|
|
auto smspecFileName = RifOpmSummaryTools::smspecSummaryFilename( fileName );
|
|
|
|
|
auto candidateEsmryFileName = RifOpmSummaryTools::enhancedSummaryFilename( fileName );
|
2023-01-03 14:52:33 +01:00
|
|
|
|
2025-07-23 15:05:35 +02:00
|
|
|
if ( importEsmryFile )
|
2021-09-10 12:27:25 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-08-21 10:08:08 +02:00
|
|
|
if ( QFile::exists( candidateEsmryFileName ) )
|
|
|
|
|
{
|
|
|
|
|
m_enhancedReader = std::make_unique<Opm::EclIO::ExtESmry>( candidateEsmryFileName.toStdString(), includeRestartFiles );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-09-10 12:27:25 +00:00
|
|
|
}
|
|
|
|
|
catch ( ... )
|
|
|
|
|
{
|
|
|
|
|
// Do not do anything here, try to open the file using standard esmy reader
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 13:52:26 +01:00
|
|
|
try
|
|
|
|
|
{
|
2023-01-03 14:52:33 +01:00
|
|
|
// The standard reader will import data from SMSPEC and UNSMRY files
|
2023-01-10 11:45:37 +01:00
|
|
|
if ( QFile::exists( smspecFileName ) )
|
|
|
|
|
{
|
|
|
|
|
m_standardReader = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );
|
|
|
|
|
}
|
2021-03-26 13:52:26 +01:00
|
|
|
}
|
|
|
|
|
catch ( std::exception& e )
|
|
|
|
|
{
|
|
|
|
|
QString txt = QString( "Optimized Summary Reader error : %1" ).arg( e.what() );
|
2021-04-08 15:53:38 +02:00
|
|
|
|
|
|
|
|
if ( threadSafeLogger ) threadSafeLogger->error( txt );
|
2021-03-26 13:52:26 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 16:32:25 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RifOpmCommonEclipseSummary::populateTimeSteps()
|
|
|
|
|
{
|
|
|
|
|
m_timeSteps.clear();
|
|
|
|
|
|
|
|
|
|
Opm::time_point startOfSimulation;
|
|
|
|
|
std::vector<float> daysSinceStartOfSimulation;
|
|
|
|
|
|
2026-04-15 14:40:25 +02:00
|
|
|
try
|
2025-07-17 16:32:25 +02:00
|
|
|
{
|
2026-04-15 14:40:25 +02:00
|
|
|
if ( m_enhancedReader )
|
|
|
|
|
{
|
|
|
|
|
startOfSimulation = m_enhancedReader->startdate();
|
2025-07-17 16:32:25 +02:00
|
|
|
|
2026-04-15 14:40:25 +02:00
|
|
|
if ( m_enhancedReader->numberOfTimeSteps() > 0 )
|
|
|
|
|
{
|
|
|
|
|
daysSinceStartOfSimulation = m_enhancedReader->get( "TIME" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( m_standardReader )
|
2025-07-17 16:32:25 +02:00
|
|
|
{
|
2026-04-15 14:40:25 +02:00
|
|
|
startOfSimulation = m_standardReader->startdate();
|
|
|
|
|
if ( m_standardReader->numberOfTimeSteps() > 0 )
|
|
|
|
|
{
|
|
|
|
|
daysSinceStartOfSimulation = m_standardReader->get( "TIME" );
|
|
|
|
|
}
|
2025-07-17 16:32:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-15 14:40:25 +02:00
|
|
|
catch ( const std::exception& e )
|
2025-07-17 16:32:25 +02:00
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::warning( std::format( "Summary reader failed to load time steps: {}", e.what() ) );
|
2025-07-17 16:32:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto startAsTimeT = std::chrono::system_clock::to_time_t( startOfSimulation );
|
|
|
|
|
const double secondsInOneDay = 24 * 3600;
|
|
|
|
|
for ( const auto& days : daysSinceStartOfSimulation )
|
|
|
|
|
{
|
|
|
|
|
m_timeSteps.push_back( startAsTimeT + days * secondsInOneDay );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 08:05:10 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::string RifOpmCommonEclipseSummary::keywordForAddress( const RifEclipseSummaryAddress& address ) const
|
|
|
|
|
{
|
|
|
|
|
auto it = m_summaryAddressToKeywordMap.find( address );
|
|
|
|
|
if ( it != m_summaryAddressToKeywordMap.end() )
|
|
|
|
|
{
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-06 12:10:10 +02:00
|
|
|
// For ensembles, the address may not be in the map (createAndSetAddresses() is only called for the realization with the most
|
|
|
|
|
// keywords, for performance reasons), so we try to reconstruct the keyword text instead. This requires
|
|
|
|
|
// RifEclipseSummaryAddress::toEclipseTextAddress() to produce text matching the keyword format used by opm-common's
|
|
|
|
|
// ESmry/ExtESmry readers (e.g. "R1-R2" with no spaces for region-to-region addresses), see
|
|
|
|
|
// https://github.com/OPM/ResInsight/issues/14853
|
2025-07-18 08:05:10 +02:00
|
|
|
return address.toEclipseTextAddress();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 12:56:09 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-09-10 16:36:25 +02:00
|
|
|
void RifOpmCommonEclipseSummary::increaseEsmryFileCount()
|
2021-03-25 12:56:09 +01:00
|
|
|
{
|
|
|
|
|
// This function can be called from a parallel loop, make it thread safe
|
2026-08-24 14:32:17 +02:00
|
|
|
#pragma omp critical( critical_section_createdEsmryFileCount )
|
2021-09-10 16:36:25 +02:00
|
|
|
sm_createdEsmryFileCount++;
|
2021-03-25 12:56:09 +01:00
|
|
|
}
|