#7512 Support optimized summary reader

This commit is contained in:
Magne Sjaastad
2021-03-25 12:56:09 +01:00
committed by GitHub
parent 53dbb33e86
commit f5547dd551
41 changed files with 2996 additions and 835 deletions

View File

@@ -60,6 +60,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelDeviationFrkExporter.h
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelPerfsFrkExporter.h
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelAsymmetricFrkExporter.h
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceExporter.h
${CMAKE_CURRENT_LIST_DIR}/RifOpmCommonSummary.h
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
@@ -125,6 +127,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelDeviationFrkExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelPerfsFrkExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelAsymmetricFrkExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifOpmCommonSummary.cpp
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.cpp

View File

@@ -0,0 +1,245 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
#include "opm/io/eclipse/ESmry.hpp"
#ifdef USE_OPENMP
#include <omp.h>
#endif
size_t RifOpmCommonEclipseSummary::sm_createdLodFileCount = 0;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifOpmCommonEclipseSummary::RifOpmCommonEclipseSummary()
: m_useLodsmryFiles( false )
, m_createLodsmryFiles( false )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifOpmCommonEclipseSummary::~RifOpmCommonEclipseSummary()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifOpmCommonEclipseSummary::useLodsmaryFiles( bool enable )
{
m_useLodsmryFiles = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifOpmCommonEclipseSummary::createLodsmaryFiles( bool enable )
{
m_createLodsmryFiles = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifOpmCommonEclipseSummary::resetLodCount()
{
sm_createdLodFileCount = 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RifOpmCommonEclipseSummary::numberOfLodFilesCreated()
{
return sm_createdLodFileCount;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifOpmCommonEclipseSummary::open( const QString& headerFileName, bool includeRestartFiles )
{
m_eSmry = std::make_unique<Opm::EclIO::ESmry>( headerFileName.toStdString(), includeRestartFiles, m_useLodsmryFiles );
if ( m_createLodsmryFiles && !includeRestartFiles )
{
// Create the lodsmry file, no-op if already present.
bool hasFileBeenCreated = m_eSmry->make_lodsmry_file();
if ( hasFileBeenCreated )
{
RifOpmCommonEclipseSummary::increaseLodFileCount();
}
}
if ( !m_eSmry ) return false;
buildMetaData();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<time_t>& RifOpmCommonEclipseSummary::timeSteps( const RifEclipseSummaryAddress& resultAddress ) const
{
return m_timeSteps;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifOpmCommonEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
{
if ( m_eSmry )
{
auto it = m_adrToSummaryNodeIndex.find( resultAddress );
if ( it != m_adrToSummaryNodeIndex.end() )
{
auto index = it->second;
auto node = m_eSmry->summaryNodeList()[index];
auto fileValues = m_eSmry->get( node );
values->insert( values->begin(), fileValues.begin(), fileValues.end() );
}
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifOpmCommonEclipseSummary::unitName( const RifEclipseSummaryAddress& resultAddress ) const
{
if ( m_eSmry )
{
auto it = m_adrToSummaryNodeIndex.find( resultAddress );
if ( it != m_adrToSummaryNodeIndex.end() )
{
auto index = it->second;
auto node = m_eSmry->summaryNodeList()[index];
return m_eSmry->get_unit( node );
}
}
return {};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaDefines::EclipseUnitSystem RifOpmCommonEclipseSummary::unitSystem() const
{
// TODO: Not implemented
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifOpmCommonEclipseSummary::buildMetaData()
{
if ( m_eSmry )
{
auto dates = m_eSmry->dates();
for ( const auto& d : dates )
{
auto timeAsTimeT = std::chrono::system_clock::to_time_t( d );
m_timeSteps.push_back( timeAsTimeT );
}
auto nodes = m_eSmry->summaryNodeList();
for ( size_t i = 0; i < nodes.size(); i++ )
{
auto summaryNode = nodes[i];
auto eclAdr = createAddressFromSummaryNode( summaryNode, m_eSmry.get() );
if ( eclAdr.isValid() )
{
m_allResultAddresses.insert( eclAdr );
m_adrToSummaryNodeIndex[eclAdr] = i;
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifOpmCommonEclipseSummary::increaseLodFileCount()
{
// This function can be called from a parallel loop, make it thread safe
#pragma omp critical
sm_createdLodFileCount++;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifEclipseSummaryAddress RifOpmCommonEclipseSummary::createAddressFromSummaryNode( const Opm::EclIO::SummaryNode& node,
Opm::EclIO::ESmry* summaryFile )
{
int i = -1;
int j = -1;
int k = -1;
switch ( node.category )
{
case Opm::EclIO::SummaryNode::Category::Aquifer:
return RifEclipseSummaryAddress::aquiferAddress( node.keyword, node.number );
break;
case Opm::EclIO::SummaryNode::Category::Well:
return RifEclipseSummaryAddress::wellAddress( node.keyword, node.wgname );
break;
case Opm::EclIO::SummaryNode::Category::Group:
return RifEclipseSummaryAddress::wellGroupAddress( node.keyword, node.wgname );
break;
case Opm::EclIO::SummaryNode::Category::Field:
return RifEclipseSummaryAddress::fieldAddress( node.keyword );
break;
case Opm::EclIO::SummaryNode::Category::Region:
return RifEclipseSummaryAddress::regionAddress( node.keyword, node.number );
break;
case Opm::EclIO::SummaryNode::Category::Block:
summaryFile->ijk_from_global_index( node.number, i, j, k );
return RifEclipseSummaryAddress::blockAddress( node.keyword, i, j, k );
break;
case Opm::EclIO::SummaryNode::Category::Connection:
summaryFile->ijk_from_global_index( node.number, i, j, k );
return RifEclipseSummaryAddress::wellCompletionAddress( node.keyword, node.wgname, i, j, k );
break;
case Opm::EclIO::SummaryNode::Category::Segment:
return RifEclipseSummaryAddress::wellSegmentAddress( node.keyword, node.wgname, node.number );
break;
case Opm::EclIO::SummaryNode::Category::Miscellaneous:
return RifEclipseSummaryAddress::miscAddress( node.keyword );
break;
default:
break;
}
return RifEclipseSummaryAddress();
}

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiaDefines.h"
#include "RifEclipseSummaryAddress.h"
#include "RifSummaryReaderInterface.h"
#include <QString>
#include <QStringList>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
namespace Opm
{
namespace EclIO
{
class ESmry;
struct SummaryNode;
} // namespace EclIO
} // namespace Opm
//==================================================================================================
//
//
//==================================================================================================
class RifOpmCommonEclipseSummary : public RifSummaryReaderInterface
{
public:
RifOpmCommonEclipseSummary();
~RifOpmCommonEclipseSummary();
void useLodsmaryFiles( bool enable );
void createLodsmaryFiles( bool enable );
static void resetLodCount();
static size_t numberOfLodFilesCreated();
bool open( const QString& headerFileName, bool includeRestartFiles );
const std::vector<time_t>& timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
private:
void buildMetaData();
static void increaseLodFileCount();
static RifEclipseSummaryAddress createAddressFromSummaryNode( const Opm::EclIO::SummaryNode& summaryNode,
Opm::EclIO::ESmry* summaryFile );
private:
std::unique_ptr<Opm::EclIO::ESmry> m_eSmry;
std::vector<std::string> m_eSmryKeywords;
std::map<RifEclipseSummaryAddress, size_t> m_adrToSummaryNodeIndex;
std::vector<time_t> m_timeSteps;
static size_t sm_createdLodFileCount;
bool m_useLodsmryFiles;
bool m_createLodsmryFiles;
};

View File

@@ -19,10 +19,13 @@
#include "RifReaderEclipseSummary.h"
#include "RiaFilePathTools.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
#include "RiaStdStringTools.h"
#include "RiaStringEncodingTools.h"
#include "RifEclipseSummaryTools.h"
#include "RifOpmCommonSummary.h"
#include "RifReaderEclipseOutput.h"
#include <cassert>
@@ -86,7 +89,7 @@ ecl_sum_type* openEclSum( const QString& inHeaderFileName, bool includeRestartFi
QString nativeHeaderFileName = QDir::toNativeSeparators( inHeaderFileName );
RifEclipseSummaryTools::findSummaryFiles( nativeHeaderFileName, &headerFileName, &dataFileNames );
if ( headerFileName.isEmpty() || dataFileNames.size() == 0 ) return nullptr;
if ( headerFileName.isEmpty() || dataFileNames.isEmpty() ) return nullptr;
assert( !headerFileName.isEmpty() );
assert( dataFileNames.size() > 0 );
@@ -126,7 +129,7 @@ RifReaderEclipseSummary::RifReaderEclipseSummary()
, m_ecl_SmSpec( nullptr )
, m_unitSystem( RiaDefines::EclipseUnitSystem::UNITS_METRIC )
{
m_valuesCache.reset( new ValuesCache() );
m_valuesCache = std::make_unique<ValuesCache>();
}
//--------------------------------------------------------------------------------------------------
@@ -146,6 +149,30 @@ RifReaderEclipseSummary::~RifReaderEclipseSummary()
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseSummary::open( const QString& headerFileName, bool includeRestartFiles )
{
bool useOpmCommonReader = RiaPreferences::current()->useOptimizedSummaryDataReader();
if ( useOpmCommonReader )
{
bool useLodsmryFiles = RiaPreferences::current()->useOptimizedSummaryDataFiles();
if ( useLodsmryFiles && includeRestartFiles )
{
RiaLogging::error(
"LODSMRY file loading for summary restart files is not supported. Disable one of the options" );
return false;
}
m_opmCommonReader = std::make_unique<RifOpmCommonEclipseSummary>();
m_opmCommonReader->useLodsmaryFiles( RiaPreferences::current()->useOptimizedSummaryDataFiles() );
m_opmCommonReader->createLodsmaryFiles( RiaPreferences::current()->createOptimizedSummaryDataFiles() );
m_opmCommonReader->open( headerFileName, includeRestartFiles );
buildMetaData();
return true;
}
assert( m_ecl_sum == nullptr );
m_ecl_sum = openEclSum( headerFileName, includeRestartFiles );
@@ -241,7 +268,7 @@ RifRestartFileInfo RifReaderEclipseSummary::getFileInfo( const QString& headerFi
RifRestartFileInfo fileInfo;
ecl_sum_type* ecl_sum = openEclSum( headerFileName, false );
std::vector<time_t> timeSteps = getTimeSteps( ecl_sum );
if ( timeSteps.size() > 0 )
if ( !timeSteps.empty() )
{
fileInfo.fileName = headerFileName;
fileInfo.startDate = timeSteps.front();
@@ -426,22 +453,33 @@ RifEclipseSummaryAddress addressFromErtSmSpecNode( const ecl::smspec_node& ertSu
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
{
assert( m_ecl_sum != nullptr );
values->clear();
values->reserve( timeStepCount() );
// assert( m_ecl_sum != nullptr );
const std::vector<double>& cachedValues = m_valuesCache->getValues( resultAddress );
if ( !cachedValues.empty() )
{
values->insert( values->begin(), cachedValues.begin(), cachedValues.end() );
return true;
}
else if ( m_ecl_SmSpec )
if ( m_opmCommonReader )
{
m_opmCommonReader->values( resultAddress, values );
m_valuesCache->insertValues( resultAddress, *values );
return true;
}
if ( m_ecl_SmSpec )
{
if ( m_differenceAddresses.count( resultAddress ) )
{
std::string quantityName = resultAddress.quantityName();
auto historyQuantity = quantityName.substr( 0, quantityName.size() - differenceIdentifier().size() ) +
const std::string& quantityName = resultAddress.quantityName();
auto historyQuantity = quantityName.substr( 0, quantityName.size() - differenceIdentifier().size() ) +
historyIdentifier();
RifEclipseSummaryAddress nativeAdrNoHistory = resultAddress;
@@ -494,13 +532,18 @@ bool RifReaderEclipseSummary::values( const RifEclipseSummaryAddress& resultAddr
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RifReaderEclipseSummary::timeStepCount() const
size_t RifReaderEclipseSummary::timeStepCount() const
{
if ( m_opmCommonReader )
{
return m_timeSteps.size();
}
assert( m_ecl_sum != nullptr );
if ( m_ecl_SmSpec == nullptr ) return 0;
return ecl_sum_get_data_length( m_ecl_sum );
return static_cast<size_t>( ecl_sum_get_data_length( m_ecl_sum ) );
}
//--------------------------------------------------------------------------------------------------
@@ -508,7 +551,7 @@ int RifReaderEclipseSummary::timeStepCount() const
//--------------------------------------------------------------------------------------------------
const std::vector<time_t>& RifReaderEclipseSummary::timeSteps( const RifEclipseSummaryAddress& resultAddress ) const
{
assert( m_ecl_sum != nullptr );
// assert( m_ecl_sum != nullptr );
return m_timeSteps;
}
@@ -535,6 +578,15 @@ void RifReaderEclipseSummary::buildMetaData()
m_allResultAddresses.clear();
m_resultAddressToErtNodeIdx.clear();
if ( m_opmCommonReader )
{
m_allResultAddresses = m_opmCommonReader->allResultAddresses();
m_allErrorAddresses = m_opmCommonReader->allErrorAddresses();
m_timeSteps = m_opmCommonReader->timeSteps( RifEclipseSummaryAddress() );
return;
}
if ( m_ecl_SmSpec )
{
int varCount = ecl_smspec_num_nodes( m_ecl_SmSpec );
@@ -556,7 +608,7 @@ void RifReaderEclipseSummary::buildMetaData()
RifEclipseSummaryAddress adrWithoutHistory;
{
std::string s = adr.quantityName();
const std::string& s = adr.quantityName();
if ( !RiaStdStringTools::endsWith( s, historyIdentifier() ) )
{
RifEclipseSummaryAddress candidate = adr;

View File

@@ -31,6 +31,8 @@
#include <string>
#include <vector>
class RifOpmCommonEclipseSummary;
//==================================================================================================
//
//
@@ -82,7 +84,7 @@ public:
static const std::string historyIdentifier() { return "H"; }
private:
int timeStepCount() const;
size_t timeStepCount() const;
int indexFromAddress( const RifEclipseSummaryAddress& resultAddress ) const;
void buildMetaData();
RifRestartFileInfo getRestartFile( const QString& headerFileName );
@@ -104,6 +106,8 @@ private:
std::set<RifEclipseSummaryAddress> m_differenceAddresses;
std::unique_ptr<RifOpmCommonEclipseSummary> m_opmCommonReader;
//==================================================================================================
//
//==================================================================================================