From b35e78df9fdf0e13e89aa7d355781cf1ce32b83c Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 5 Sep 2021 13:42:45 +0200 Subject: [PATCH] Introduce convenience functions to convert int <-> Actionx OR/AND --- .../Schedule/Action/Condition.hpp | 2 ++ .../output/eclipse/AggregateActionxData.cpp | 18 +------------ .../Schedule/Action/Condition.cpp | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.hpp b/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.hpp index 012b7e89f..b0ecabcab 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.hpp @@ -90,6 +90,8 @@ enum class Comparator { std::string cmp_string; + static Logical logic_from_int(int); + int logic_as_int() const; bool open_paren() const; bool close_paren() const; bool operator==(const Condition& data) const; diff --git a/src/opm/output/eclipse/AggregateActionxData.cpp b/src/opm/output/eclipse/AggregateActionxData.cpp index 547838935..7f430329c 100644 --- a/src/opm/output/eclipse/AggregateActionxData.cpp +++ b/src/opm/output/eclipse/AggregateActionxData.cpp @@ -103,11 +103,6 @@ const std::map rhsQuantityToIndex = { }; using logic_enum = Opm::Action::Condition::Logical; -const std::map logicalToIndex_13 = { - {logic_enum::AND, 1}, - {logic_enum::OR, 2}, - {logic_enum::END, 0}, -}; const std::map logicalToIndex_17 = { {logic_enum::AND, 1}, @@ -406,18 +401,7 @@ const std::map cmpToIndex = { iAcn[ind + 12] = it_lhs_it->second; } - /*item [13] - relates to operator - OR is 2 - AND is 1 - */ - const auto it_logic_13 = logicalToIndex_13.find(cond.logic); - if (it_logic_13 != logicalToIndex_13.end()) { - iAcn[ind + 13] = it_logic_13->second; - } - else { - std::cout << "Unknown Boolean operator type for condition: " << cond.lhs.quantity << std::endl; - throw std::invalid_argument("Actionx: " + actx.name()); - } + iAcn[ind + 13] = cond.logic_as_int(); /* item[15] is a parameter that indicates whether left_paren or right_paren is used in an expression * = 0 : no open_paren or left_paren, or both open_paren and right_paren diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.cpp index 2dcb82002..cb1478fb3 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/Condition.cpp @@ -170,6 +170,31 @@ bool Condition::close_paren() const { return !this->left_paren && this->right_paren; } +Condition::Logical Condition::logic_from_int(int int_logic) { + if (int_logic == 0) + return Logical::END; + + if (int_logic == 1) + return Logical::AND; + + if (int_logic == 2) + return Logical::OR; + + throw std::logic_error("Unknown integer value"); +} + +int Condition::logic_as_int() const { + switch (this->logic) { + case Logical::END: + return 0; + case Logical::AND: + return 1; + case Logical::OR: + return 2; + default: + throw std::logic_error("What the f...?"); + } +} } }