diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp index 1b9f17e21..cfbb2fed0 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp @@ -19,13 +19,15 @@ #include #include #include - +#include +#include #include #include #include #include #include +#include #include "../../../Parser/raw/RawConsts.hpp" #include "UDQToken.hpp" @@ -240,15 +242,26 @@ void UDQDefine::required_summary(std::unordered_set& summary_keys) } UDQSet UDQDefine::eval(const UDQContext& context) const { - UDQSet res = this->ast->eval(this->m_var_type, context); - res.name( this->m_keyword ); - - if (!dynamic_type_check(this->var_type(), res.var_type())) { - std::string msg = "Invalid runtime type conversion detected when evaluating UDQ"; - throw std::invalid_argument(msg); + std::optional res; + try { + res = this->ast->eval(this->m_var_type, context); + res->name( this->m_keyword ); + if (!dynamic_type_check(this->var_type(), res->var_type())) { + std::string msg = "Invalid runtime type conversion detected when evaluating UDQ"; + throw std::invalid_argument(msg); + } + } catch (const std::exception& exc) { + auto msg = fmt::format("Problem evaluating UDQ {}\n" + "In {} line {}\n" + "Internal error: {}", this->m_keyword, this->m_location.filename, this->m_location.lineno, exc.what()); + OpmLog::error(msg); + std::throw_with_nested(exc); } + if (!res) + throw std::logic_error("Bug in UDQDefine::eval()"); - if (res.var_type() == UDQVarType::SCALAR) { + + if (res->var_type() == UDQVarType::SCALAR) { /* If the right hand side evaluates to a scalar that scalar value should be set for all wells in the wellset: @@ -265,7 +278,7 @@ UDQSet UDQDefine::eval(const UDQContext& context) const { regarding the semantics of group sets. */ - const auto& scalar_value = res[0].value(); + const auto& scalar_value = res->operator[](0).value(); if (this->var_type() == UDQVarType::WELL_VAR) { const std::vector wells = context.wells(); UDQSet well_res = UDQSet::wells(this->m_keyword, wells); @@ -287,7 +300,7 @@ UDQSet UDQDefine::eval(const UDQContext& context) const { } } - return res; + return *res; } const KeywordLocation& UDQDefine::location() const { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.cpp index 5a2827293..9f03dba16 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -485,8 +486,10 @@ UDQSet udq_cast(const UDQSet& lhs, const UDQSet& rhs) { if (lhs.size() != rhs.size()) { if (lhs.var_type() != UDQVarType::SCALAR) { - printf("s1: %ld s2: %ld \n", lhs.size(), rhs.size()); - throw std::logic_error("Type/size mismatch"); + auto msg = fmt::format("Type/size mismatch when combining UDQs {}(size={}, type={}) and {}(size={}, type={})", + lhs.name(), lhs.size(), lhs.var_type(), + rhs.name(), rhs.size(), rhs.var_type()); + throw std::logic_error(msg); } if (rhs.var_type() == UDQVarType::WELL_VAR) diff --git a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp index 5e62702c5..0186743e4 100644 --- a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp @@ -922,7 +922,7 @@ inline void keywordMISC( SummaryConfig::keyword_list& list, if (!udq.has_unit(location.keyword)) { std::string msg = "Summary output requested for UDQ {keyword}\n" "In {file} line {line}\n" - "No unit define in the SCHEDULE section"; + "No unit defined in the SCHEDULE section for {keyword}"; parseContext.handleError(ParseContext::SUMMARY_UDQ_MISSING_UNIT, msg, location, errors); } } diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 331d73a0e..f5e62a065 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -2189,7 +2189,7 @@ UDQ UDQState udq_state(undefined_value); SummaryState st(std::chrono::system_clock::now()); - BOOST_CHECK_THROW(udq.eval(0, st, udq_state), std::out_of_range); + BOOST_CHECK_THROW(udq.eval(0, st, udq_state), std::exception); }