diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp index 7efd9a6b2..9b63a3c27 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp @@ -32,6 +32,7 @@ #include #include #include +#include namespace Opm { @@ -111,6 +112,7 @@ namespace Opm { std::unordered_map m_assignments; std::unordered_map units; + IOrderSet define_order; OrderedMap input_index; std::map type_count; }; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp index a7d5674f3..f9e766fdb 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp @@ -92,6 +92,7 @@ namespace Opm { this->m_definitions.erase( defined_iter ); this->m_definitions.insert( std::make_pair(quantity, UDQDefine(this->udq_params, quantity, expression))); + this->define_order.insert(quantity); } @@ -146,25 +147,20 @@ namespace Opm { std::vector UDQConfig::definitions() const { std::vector ret; - for (const auto& index_pair : this->input_index) { - if (index_pair.second.action == UDQAction::DEFINE) { - const std::string& key = index_pair.first; - ret.push_back(this->m_definitions.at(key)); - } - } + + for (const auto& key : this->define_order) + ret.push_back(this->m_definitions.at(key)); + return ret; } std::vector UDQConfig::definitions(UDQVarType var_type) const { std::vector filtered_defines; - for (const auto& index_pair : this->input_index) { - if (index_pair.second.action == UDQAction::DEFINE) { - const std::string& key = index_pair.first; - const auto& udq_define = this->m_definitions.at(key); - if (udq_define.var_type() == var_type) - filtered_defines.push_back(udq_define); - } + for (const auto& key : this->define_order) { + const auto& udq_define = this->m_definitions.at(key); + if (udq_define.var_type() == var_type) + filtered_defines.push_back(udq_define); } return filtered_defines; } diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 105c2ce12..acf8a33ad 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -1749,6 +1749,25 @@ UDQ } +BOOST_AUTO_TEST_CASE(UDQ_DEFINE_ORDER) { + std::string deck_string = R"( +SCHEDULE +UDQ +ASSIGN FU_PAR1 1.0 / +ASSIGN FU_PAR2 0.0 / +DEFINE FU_PAR3 FMWPR / +DEFINE FU_PAR2 FU_PAR3 / +/ +)"; + auto schedule = make_schedule(deck_string); + const auto& udq = schedule.getUDQConfig(0); + SummaryState st(std::chrono::system_clock::now()); + st.update("FMWPR", 100); + udq.eval(st); + + BOOST_CHECK_EQUAL(st.get("FU_PAR2"), 100); +} + BOOST_AUTO_TEST_CASE(UDQ_UADD_PARSER2) { std::string deck_string = R"( @@ -1798,5 +1817,18 @@ DEFINE FU_PAR24 FU_PAR24 UADD (FU_PAR14 + FU_PAR15) / DEFINE WUGASRA 750000 - WGLIR '*' / / )"; - BOOST_CHECK_NO_THROW( make_schedule(deck_string) ); + auto schedule = make_schedule(deck_string); + const auto& udq = schedule.getUDQConfig(0); + SummaryState st(std::chrono::system_clock::now()); + st.update("FMWPR", 100); + st.update("FMWIN", 100); + st.update("FMWPA", 100); + st.update("FMWIA", 100); + st.update("FOPR", 100); + st.update_well_var("W1", "WGLIR", 1); + st.update_well_var("W2", "WGLIR", 2); + st.update_well_var("W3", "WGLIR", 3); + + // The current testcase has some ordering & defined / undefined issues which + // are not yet solved; therefor no udq.eval() here. }