Make sure DEFINE statements are evaluated in input order

This commit is contained in:
Joakim Hove
2020-08-23 17:19:27 +02:00
parent 718e00ca1f
commit 168aa5602d
3 changed files with 44 additions and 14 deletions

View File

@@ -32,6 +32,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParams.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp>
#include <opm/parser/eclipse/EclipseState/Util/OrderedMap.hpp>
#include <opm/parser/eclipse/EclipseState/Util/IOrderSet.hpp>
namespace Opm {
@@ -111,6 +112,7 @@ namespace Opm {
std::unordered_map<std::string, UDQAssign> m_assignments;
std::unordered_map<std::string, std::string> units;
IOrderSet<std::string> define_order;
OrderedMap<std::string, UDQIndex> input_index;
std::map<UDQVarType, std::size_t> type_count;
};

View File

@@ -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<UDQDefine> UDQConfig::definitions() const {
std::vector<UDQDefine> 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<UDQDefine> UDQConfig::definitions(UDQVarType var_type) const {
std::vector<UDQDefine> 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;
}

View File

@@ -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.
}