diff --git a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp index 84170374a..375281e50 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp @@ -23,6 +23,7 @@ enum TokenType { enum class FuncType { none, time, + time_month, region, field, group, diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp index 5d3a237cc..b1641899d 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -161,7 +162,26 @@ Action::Result ASTNode::eval(const Action::Context& context) const { } auto v1 = this->children[0].value(context); - auto v2 = this->children[1].value(context); + Action::Value v2; + + /* + Special casing of MONTH comparisons where in addition symbolic month names + we can compare with numeric months, in the case of numeric months the + numerical value should be rounded before comparison - i.e. + + MNTH = 4.3 + + Should evaluate to true for the month April. + */ + if (this->children[0].func_type == FuncType::time_month) { + const auto& rhs = this->children[1]; + if (rhs.type == TokenType::number) { + v2 = Action::Value(std::round(rhs.number)); + } else + v2 = rhs.value(context); + } else + v2 = this->children[1].value(context); + return v1.eval_cmp(this->type, v2); } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionParser.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionParser.cpp index d16b79c6e..a36f9b696 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionParser.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionParser.cpp @@ -88,7 +88,7 @@ TokenType Parser::get_type(const std::string& arg) { FuncType Parser::get_func(const std::string& arg) { if (arg == "YEAR") return FuncType::time; - if (arg == "MNTH") return FuncType::time; + if (arg == "MNTH") return FuncType::time_month; if (arg == "DAY") return FuncType::time; using Cat = SummaryConfigNode::Category; diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index b590ae53a..5fdf9c476 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -355,6 +355,19 @@ BOOST_AUTO_TEST_CASE(DATE) { BOOST_CHECK( !ast.eval(context)); } +BOOST_AUTO_TEST_CASE(MNTH_NUMERIC) { + Action::AST ast(std::vector{"MNTH", ">=", "6.3"}); + SummaryState st(TimeService::now()); + WListManager wlm; + Action::Context context(st, wlm); + + context.add("MNTH", 5); + BOOST_CHECK( !ast.eval(context)); + + context.add("MNTH", 6); + BOOST_CHECK( ast.eval(context) ); +} + BOOST_AUTO_TEST_CASE(MANUAL1) { Action::AST ast({"GGPR", "FIELD", ">", "50000", "AND", "WGOR", "PR", ">" ,"GGOR", "FIELD"});