From 4a9ec1403e5653eb5c754eee067daeb953cddd47 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 8 Sep 2020 08:19:17 +0200 Subject: [PATCH] UDQ: get from an unknown summary variable throws std::out_of_range --- .../EclipseState/Schedule/UDQ/UDQContext.cpp | 15 +++------------ tests/parser/UDQTests.cpp | 13 +++++-------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.cpp index af06b83e9..af11b0d9d 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.cpp @@ -83,10 +83,7 @@ bool is_udq(const std::string& key) { if (pair_ptr != this->values.end()) return pair_ptr->second; - if (this->summary_state.has(key)) - return this->summary_state.get(key); - - return std::nullopt; + return this->summary_state.get(key); } std::optional UDQContext::get_well_var(const std::string& well, const std::string& var) const { @@ -96,10 +93,7 @@ bool is_udq(const std::string& key) { return std::nullopt; } - if (this->summary_state.has_well_var(well, var)) - return this->summary_state.get_well_var(well, var); - - return std::nullopt; + return this->summary_state.get_well_var(well, var); } std::optional UDQContext::get_group_var(const std::string& group, const std::string& var) const { @@ -109,10 +103,7 @@ bool is_udq(const std::string& key) { return std::nullopt; } - if (this->summary_state.has_group_var(group, var)) - return this->summary_state.get_group_var(group, var); - - return std::nullopt; + return this->summary_state.get_group_var(group, var); } std::vector UDQContext::wells() const { diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 9b62332e3..bf38df12f 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -564,9 +564,7 @@ BOOST_AUTO_TEST_CASE(UDQ_CONTEXT) { UDQState udq_state(udqp.undefinedValue()); UDQContext ctx(func_table, st, udq_state); BOOST_CHECK_EQUAL(*ctx.get("JAN"), 1.0); - - auto invalid = ctx.get("NO_SUCH_KEY"); - BOOST_CHECK(!invalid.has_value()); + BOOST_CHECK_THROW(ctx.get("NO_SUCH_KEY"), std::out_of_range); for (std::string& key : std::vector({"ELAPSED", "MSUMLINS", "MSUMNEWT", "NEWTON", "TCPU", "TIME", "TIMESTEP"})) BOOST_CHECK_NO_THROW( ctx.get(key) ); @@ -2137,14 +2135,14 @@ DEFINE FU_VAR91 GOPR TEST / -BOOST_AUTO_TEST_CASE(UDQ_ASSIGN) { + +BOOST_AUTO_TEST_CASE(UDQ_KEY_ERROR) { std::string deck_string = R"( -- udq #2 SCHEDULE UDQ - ASSIGN FU_VAR1 5 / - DEFINE FU_VAR1 FU_VAR1 + 5 / + DEFINE FU_VAR1 FOPR * 5 / / )"; @@ -2154,6 +2152,5 @@ UDQ UDQState udq_state(undefined_value); SummaryState st(std::chrono::system_clock::now()); - udq.eval(0, st, udq_state); - BOOST_CHECK_EQUAL(st.get("FU_VAR1"), 10); + BOOST_CHECK_THROW(udq.eval(0, st, udq_state), std::out_of_range); }