From 6d478ddb3c2ba7cc3517f1aa1c0fb7fe922eebba Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 3 May 2024 09:52:43 +0200 Subject: [PATCH] Use opm parser to find all VFP data based on a *.DATA file --- .../ProjectDataModel/RiaOpmParserTools.cpp | 151 +++++++++++++----- .../ProjectDataModel/RiaOpmParserTools.h | 21 +-- 2 files changed, 125 insertions(+), 47 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp index c039cd01c5..58cf2c552e 100644 --- a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp @@ -30,6 +30,7 @@ #include "opm/input/eclipse/Parser/Parser.hpp" #include "opm/input/eclipse/Parser/ParserKeywords/I.hpp" #include "opm/input/eclipse/Parser/ParserKeywords/P.hpp" +#include "opm/input/eclipse/Parser/ParserKeywords/T.hpp" #include "opm/input/eclipse/Parser/ParserKeywords/V.hpp" #include "opm/input/eclipse/Parser/ParserKeywords/W.hpp" @@ -37,10 +38,55 @@ #include +namespace RiaOpmParserTools +{ + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaOpmParserTools::extractVfpInjectionTables( const std::string& filename ) +Opm::VFPInjTable createInjectionTable( const Opm::DeckKeyword& keyword ) +{ + Opm::UnitSystem unitSystem; + { + const auto& header = keyword.getRecord( 0 ); + + if ( header.getItem().hasValue( 0 ) ) + { + std::string units_string; + units_string = header.getItem().get( 0 ); + unitSystem = Opm::UnitSystem( units_string ); + } + } + + return { keyword, unitSystem }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +Opm::VFPProdTable createProductionTable( const Opm::DeckKeyword& keyword ) +{ + Opm::UnitSystem unitSystem; + { + const auto& header = keyword.getRecord( 0 ); + + if ( header.getItem().hasValue( 0 ) ) + { + std::string units_string; + units_string = header.getItem().get( 0 ); + unitSystem = Opm::UnitSystem( units_string ); + } + } + + bool gaslift_opt_active = false; + + return { keyword, gaslift_opt_active, unitSystem }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector extractVfpInjectionTables( const std::string& filename ) { std::vector tables; @@ -60,21 +106,7 @@ std::vector RiaOpmParserTools::extractVfpInjectionTables( cons for ( auto kw : keywordList ) { - auto name = kw->name(); - - Opm::UnitSystem unitSystem; - { - const auto& header = kw->getRecord( 0 ); - - if ( header.getItem().hasValue( 0 ) ) - { - std::string units_string; - units_string = header.getItem().get( 0 ); - unitSystem = Opm::UnitSystem( units_string ); - } - } - - Opm::VFPInjTable table( *kw, unitSystem ); + auto table = createInjectionTable( *kw ); tables.push_back( table ); } } @@ -88,7 +120,7 @@ std::vector RiaOpmParserTools::extractVfpInjectionTables( cons //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaOpmParserTools::extractVfpProductionTables( const std::string& filename ) +std::vector extractVfpProductionTables( const std::string& filename ) { std::vector tables; @@ -106,22 +138,7 @@ std::vector RiaOpmParserTools::extractVfpProductionTables( co for ( auto kw : keywordList ) { - auto name = kw->name(); - - Opm::UnitSystem unitSystem; - { - const auto& header = kw->getRecord( 0 ); - - if ( header.getItem().hasValue( 0 ) ) - { - std::string units_string; - units_string = header.getItem().get( 0 ); - unitSystem = Opm::UnitSystem( units_string ); - } - } - - bool gaslift_opt_active = false; - Opm::VFPProdTable table( *kw, gaslift_opt_active, unitSystem ); + auto table = createProductionTable( *kw ); tables.push_back( table ); } } @@ -135,7 +152,65 @@ std::vector RiaOpmParserTools::extractVfpProductionTables( co //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::map>> RiaOpmParserTools::extractWseglink( const std::string& filename ) +std::pair, std::vector> extractVfpTablesFromDataFile( const std::string& dataDeckFilename ) +{ + if ( !std::filesystem::exists( dataDeckFilename ) ) return {}; + + std::vector prodTables; + std::vector injTables; + + try + { + Opm::Parser parser( false ); + + // Required to include the TUNING keyword to avoid parsing error of a Norne DATA file containing the TUNING keyword + // The TUNING keyword is not required nor related to VFP data + std::vector parserKeywords = { Opm::ParserKeywords::VFPPROD(), + Opm::ParserKeywords::VFPINJ(), + Opm::ParserKeywords::INCLUDE(), + Opm::ParserKeywords::TUNING() }; + for ( const auto& kw : parserKeywords ) + { + parser.addParserKeyword( kw ); + } + + Opm::ParseContext parseContext( Opm::InputError::Action::WARN ); + auto deck = parser.parseFile( dataDeckFilename, parseContext ); + + { + std::string prodKeyword = "VFPPROD"; + auto keywordList = deck.getKeywordList( prodKeyword ); + for ( auto kw : keywordList ) + { + auto table = createProductionTable( *kw ); + prodTables.push_back( table ); + } + } + { + std::string injKeyword = "VFPINJ"; + auto keywordList = deck.getKeywordList( injKeyword ); + for ( auto kw : keywordList ) + { + auto table = createInjectionTable( *kw ); + injTables.push_back( table ); + } + } + } + catch ( ... ) + { + QString text = QString( "Error detected when parsing '%1'. Imported data might be missing or incomplete." ) + .arg( QString::fromStdString( dataDeckFilename ) ); + + RiaLogging::warning( text ); + } + + return { prodTables, injTables }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::map>> extractWseglink( const std::string& filename ) { if ( !std::filesystem::exists( filename ) ) return {}; @@ -205,7 +280,7 @@ std::map>> RiaOpmParserTools::extra //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaOpmParserTools::extractWsegAicd( const std::string& filename ) +std::vector extractWsegAicd( const std::string& filename ) { if ( !std::filesystem::exists( filename ) ) return {}; @@ -291,7 +366,7 @@ std::vector RiaOpmParserTools::extractWse //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaOpmParserTools::extractWsegAicdCompletor( const std::string& filename ) +std::vector extractWsegAicdCompletor( const std::string& filename ) { QFile file( QString::fromStdString( filename ) ); if ( !file.open( QFile::ReadOnly ) ) return {}; @@ -346,7 +421,9 @@ std::vector RiaOpmParserTools::extractWse //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::string RiaOpmParserTools::aicdTemplateId() +std::string aicdTemplateId() { return "ID_NUMBER"; } + +} // namespace RiaOpmParserTools diff --git a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h index 473922b596..0841fb579a 100644 --- a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h +++ b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h @@ -28,17 +28,18 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -class RiaOpmParserTools +namespace RiaOpmParserTools { -public: - static std::vector extractVfpInjectionTables( const std::string& filename ); - static std::vector extractVfpProductionTables( const std::string& filename ); +std::vector extractVfpInjectionTables( const std::string& filename ); +std::vector extractVfpProductionTables( const std::string& filename ); - static std::map>> extractWseglink( const std::string& filename ); +std::pair, std::vector> extractVfpTablesFromDataFile( const std::string& dataDeckFilename ); - using AicdTemplateValues = std::map; - static std::vector extractWsegAicd( const std::string& filename ); - static std::vector extractWsegAicdCompletor( const std::string& filename ); +std::map>> extractWseglink( const std::string& filename ); - static std::string aicdTemplateId(); -}; +using AicdTemplateValues = std::map; +std::vector extractWsegAicd( const std::string& filename ); +std::vector extractWsegAicdCompletor( const std::string& filename ); + +std::string aicdTemplateId(); +}; // namespace RiaOpmParserTools