From 25d7e99413f779ec43016a66d0759f9feb2cadae Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sat, 9 Mar 2019 09:46:59 +0100 Subject: [PATCH] Add UDQInput methods has_keyword() and has_unit() --- .../eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp | 6 +++++- .../eclipse/EclipseState/Schedule/UDQ/UDQInput.cpp | 11 +++++++++++ tests/parser/UDQTests.cpp | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp index d21bc8974..faa6bfca5 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp @@ -21,8 +21,9 @@ #ifndef UDQINPUT_HPP_ #define UDQINPUT_HPP_ -#include #include +#include +#include #include #include @@ -37,6 +38,8 @@ namespace Opm { void add_record(const DeckRecord& record); const std::vector& expressions() const noexcept; const std::string& unit(const std::string& key) const; + bool has_unit(const std::string& keyword) const; + bool has_keyword(const std::string& keyword) const; void assign_unit(const std::string& keyword, const std::string& unit); const std::vector& assignments() const; std::vector assignments(UDQVarType var_type) const; @@ -44,6 +47,7 @@ namespace Opm { std::vector m_expressions; std::vector m_assignments; std::unordered_map units; + std::unordered_set keywords; }; } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.cpp index 1b4e7bd3d..79e3f6855 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.cpp @@ -49,6 +49,8 @@ namespace Opm { this->m_assignments.emplace_back( quantity, selector, value ); } else this->m_expressions.emplace_back(action, quantity, data); + + this->keywords.insert(quantity); } @@ -94,4 +96,13 @@ namespace Opm { } this->units[keyword] = unit; } + + bool UDQInput::has_unit(const std::string& keyword) const { + return (this->units.count(keyword) > 0); + } + + bool UDQInput::has_keyword(const std::string& keyword) const { + return (this->keywords.count(keyword) > 0); + } + } diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 0921c5cf0..12fb5945a 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -153,6 +153,7 @@ UDQ ASSIGN WUBHP 0.0 / UNITS WUBHP 'BARSA' / DEFINE FUOPR AVEG(WOPR) + 1/ + ASSIGN WUXUNIT 0.0 / / DATES @@ -172,6 +173,10 @@ UDQ BOOST_CHECK_THROW( udq.unit("NO_SUCH_KEY"), std::invalid_argument ); BOOST_CHECK_EQUAL( udq.unit("WUBHP"), "BARSA"); + BOOST_CHECK( udq.has_keyword("WUBHP") ); + BOOST_CHECK( !udq.has_keyword("NO_SUCH_KEY") ); + BOOST_CHECK( !udq.has_unit("WUXUNIT")); + BOOST_CHECK( udq.has_unit("WUBHP")); Parser parser; auto deck = parser.parseString(input);