From d02ae5e6504cbbb4485550d6bf9f112a90a999bc Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 17 Mar 2021 10:08:35 +0100 Subject: [PATCH] Make sure action results contain well for fully specified condition --- .../Schedule/Action/ActionValue.hpp | 1 + .../EclipseState/Schedule/Action/ASTNode.cpp | 8 +++- .../Schedule/Action/ActionValue.cpp | 3 ++ tests/parser/ACTIONX.cpp | 47 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp index fbeb68a0e..84170374a 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp @@ -42,6 +42,7 @@ namespace Action { class Value { public: explicit Value(double value); + Value(const std::string& wname, double value); Value() = default; Result eval_cmp(TokenType op, const Value& rhs) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp index 0a4f371f1..5d3a237cc 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp @@ -133,7 +133,13 @@ Action::Value ASTNode::value(const Action::Context& context) const { std::string arg_key = this->arg_list[0]; for (size_t index = 1; index < this->arg_list.size(); index++) arg_key += ":" + this->arg_list[index]; - return Action::Value(context.get(this->func, arg_key)); + + auto scalar_value = context.get(this->func, arg_key); + + if (this->func_type == FuncType::well) + return Action::Value(this->arg_list[0], scalar_value); + else + return Action::Value(scalar_value); } } } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.cpp index 661f2b623..4729a7fcf 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.cpp @@ -81,6 +81,9 @@ Value::Value(double value) : is_scalar(true) { } +Value::Value(const std::string& wname, double value) { + this->add_well(wname, value); +} double Value::scalar() const { if (!this->is_scalar) diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index 7e629faf5..89b5d8156 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -1287,3 +1287,50 @@ ENDACTIO } } + +BOOST_AUTO_TEST_CASE(MatchingWellsSpecified1) { + Action::AST ast({"WBHP", "P1", "<", "200"}); + auto st = SummaryState{ TimeService::now() }; + Opm::WListManager wlm; + + st.update_well_var("P1", "WBHP", 150); + Opm::Action::Context context(st, wlm); + auto result = ast.eval(context); + BOOST_CHECK(result); + BOOST_CHECK(result.wells() == std::vector{"P1"}); +} + + +BOOST_AUTO_TEST_CASE(MatchingWellsSpecified2) { + + const auto deck_string = std::string{ R"( +SCHEDULE + +WELSPECS + 'P1' 'OP' 1 1 3.33 'OIL' 7*/ +/ + +ACTIONX +INJECTION 10 / +WBHP P1 < 200.0 / +/ + +WELOPEN + 'WI1' 'OPEN' 5* / +/ + +ENDACTIO + + )"}; + + auto st = SummaryState{ TimeService::now() }; + Schedule sched = make_schedule(deck_string); + Opm::WListManager wlm; + + st.update_well_var("P1", "WBHP", 150); + Opm::Action::Context context(st, wlm); + const auto& action = sched[0].actions.get().get("INJECTION"); + auto result = action.eval(context); + BOOST_CHECK(result); + BOOST_CHECK(result.wells() == std::vector{"P1"}); +}