From f3fbfc41ad9c563cc12f24553eb143ca4405d199 Mon Sep 17 00:00:00 2001 From: Williham Williham Totland Date: Wed, 1 Apr 2020 13:01:45 +0200 Subject: [PATCH] Completes RPTConfig to pass tests. --- .../EclipseState/Schedule/RPTConfig.hpp | 9 +++++ .../EclipseState/Schedule/Schedule.hpp | 3 +- .../EclipseState/Schedule/RPTConfig.cpp | 33 +++++++++++++++++++ .../EclipseState/Schedule/Schedule.cpp | 8 +++++ tests/parser/test_ReportConfig.cpp | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp b/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp index 22e7a319b..a95718a0f 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp @@ -22,11 +22,20 @@ #include #include +#include + namespace Opm { class RPTConfig: public std::unordered_map { +#if __cplusplus <= 201703L public: bool contains(const std::string&) const; +#endif + +public: + using std::unordered_map::unordered_map; + + RPTConfig(const DeckKeyword&); }; } diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 08ee894fc..53d59c888 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -101,6 +100,7 @@ namespace Opm class FieldPropsManager; class Python; class Runspec; + class RPTConfig; class SCHEDULESection; class SummaryState; class TimeMap; @@ -428,6 +428,7 @@ namespace Opm void handleWECON( const DeckKeyword& keyword, size_t currentStep, const ParseContext& parseContext, ErrorGuard& errors); void handleWHISTCTL(const DeckKeyword& keyword, std::size_t currentStep, const ParseContext& parseContext, ErrorGuard& errors); void handleMESSAGES(const DeckKeyword& keyword, size_t currentStep); + void handleRPTSCHED(const DeckKeyword& keyword, size_t currentStep); void handleVFPPROD(const DeckKeyword& vfpprodKeyword, const UnitSystem& unit_system, size_t currentStep); void handleVFPINJ(const DeckKeyword& vfpprodKeyword, const UnitSystem& unit_system, size_t currentStep); void checkUnhandledKeywords( const SCHEDULESection& ) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.cpp index a38b784ab..0f667c3e9 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/RPTConfig.cpp @@ -19,10 +19,43 @@ #include +#include + namespace { + std::pair parse_mnemonic(const std::string& mnemonic) { + const auto pivot { mnemonic.find('=') } ; + + if (pivot == std::string::npos) { + return { mnemonic, 1 } ; + } else { + const auto int_value { std::stoi(mnemonic.substr(pivot + 1)) } ; + + if (!(int_value >= 0)) { + OPM_THROW(std::invalid_argument, "RPTSCHED - " + mnemonic + " - mnemonic value must be an integer greater than 1"); + } + + return { mnemonic.substr(0, pivot), int_value } ; + } + } + } +Opm::RPTConfig::RPTConfig(const DeckKeyword& keyword) : + std::unordered_map {} +{ + const auto& mnemonics { keyword.getStringData() } ; + for (const auto& mnemonic : mnemonics) { + if (mnemonic == "NOTHING") { + clear(); + } else { + emplace(parse_mnemonic(mnemonic)); + } + } +} + +#if __cplusplus <= 201703L bool Opm::RPTConfig::contains(const std::string& key) const { return find(key) != end(); } +#endif diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 17fbb6404..fbd23b9c4 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -453,6 +454,9 @@ Schedule::Schedule(const Deck& deck, const EclipseState& es, const ParseContext& else if (keyword.name() == "MESSAGES") handleMESSAGES(keyword, currentStep); + else if (keyword.name() == "RPTSCHED") + handleRPTSCHED(keyword, currentStep); + else if (keyword.name() == "WEFAC") handleWEFAC(keyword, currentStep, parseContext, errors); @@ -1948,6 +1952,10 @@ void Schedule::iterateScheduleSection(const std::string& input_path, const Parse } } + void Schedule::handleRPTSCHED( const DeckKeyword& keyword, size_t currentStep) { + this->rpt_config.update(currentStep, std::make_shared(keyword)); + } + void Schedule::handleCOMPDAT( const DeckKeyword& keyword, size_t currentStep, const EclipseGrid& grid, const FieldPropsManager& fp, const ParseContext& parseContext, ErrorGuard& errors) { for (const auto& record : keyword) { const std::string& wellNamePattern = record.getItem("WELL").getTrimmedString(0); diff --git a/tests/parser/test_ReportConfig.cpp b/tests/parser/test_ReportConfig.cpp index 50c7f124b..22cde95e8 100644 --- a/tests/parser/test_ReportConfig.cpp +++ b/tests/parser/test_ReportConfig.cpp @@ -24,6 +24,7 @@ #define BOOST_TEST_MODULE ReportConfigTest #include +#include #include #include #include