Merge pull request #2034 from joakim-hove/udq-assign-define

Udq assign define
This commit is contained in:
Joakim Hove 2020-10-21 11:45:41 +02:00 committed by GitHub
commit ba4082b2b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 28 deletions

View File

@ -68,7 +68,7 @@ public:
static UDQDefine serializeObject();
UDQSet eval(UDQContext& context) const;
UDQSet eval(const UDQContext& context) const;
const std::string& keyword() const;
const std::string& input_string() const;
UDQVarType var_type() const;

View File

@ -42,6 +42,7 @@ public:
void add_define(const std::string& udq_key, const UDQSet& result);
void add_assign(std::size_t report_step, const std::string& udq_key, const UDQSet& result);
bool assign(std::size_t report_step, const std::string& udq_key) const;
double undefined_value() const;
std::vector<char> serialize() const;
void deserialize(const std::vector<char>& buffer);
@ -49,7 +50,7 @@ public:
private:
void add(const std::string& udq_key, const UDQSet& result);
double get_wg_var(const std::string& well, const std::string& key, UDQVarType var_type) const;
double undefined_value;
double undef_value;
std::unordered_map<std::string, UDQSet> values;
std::unordered_map<std::string, std::size_t> assignments;
};

View File

@ -298,49 +298,42 @@ namespace Opm {
void UDQConfig::eval(std::size_t report_step, SummaryState& st, UDQState& udq_state) const {
const auto& func_table = this->function_table();
auto undefined_value = this->params().undefinedValue();
UDQContext context(func_table, st, udq_state);
for (const auto& assign : this->assignments(UDQVarType::WELL_VAR)) {
if (udq_state.assign(report_step, assign.keyword())) {
auto ws = assign.eval(st.wells());
context.update_assign(report_step, assign.keyword(), ws);
st.update_udq(ws, undefined_value);
}
}
for (const auto& def : this->definitions(UDQVarType::WELL_VAR)) {
auto ws = def.eval(context);
context.update_define(def.keyword(), ws);
st.update_udq(ws, undefined_value);
}
for (const auto& assign : this->assignments(UDQVarType::GROUP_VAR)) {
if (udq_state.assign(report_step, assign.keyword())) {
auto ws = assign.eval(st.groups());
context.update_assign(report_step, assign.keyword(), ws);
st.update_udq(ws, undefined_value);
}
}
for (const auto& def : this->definitions(UDQVarType::GROUP_VAR)) {
auto ws = def.eval(context);
context.update_define(def.keyword(), ws);
st.update_udq(ws, undefined_value);
}
for (const auto& assign : this->assignments(UDQVarType::FIELD_VAR)) {
if (udq_state.assign(assign.report_step(), assign.keyword())) {
auto ws = assign.eval();
context.update_assign(report_step, assign.keyword(), ws);
st.update_udq(ws, undefined_value);
}
}
for (const auto& def : this->definitions(UDQVarType::FIELD_VAR)) {
auto field_udq = def.eval(context);
context.update_define(def.keyword(), field_udq);
st.update_udq(field_udq, undefined_value);
}
}
}

View File

@ -130,9 +130,11 @@ bool is_udq(const std::string& key) {
void UDQContext::update_assign(std::size_t report_step, const std::string& keyword, const UDQSet& udq_result) {
this->udq_state.add_assign(report_step, keyword, udq_result);
this->summary_state.update_udq(udq_result, this->udq_state.undefined_value());
}
void UDQContext::update_define(const std::string& keyword, const UDQSet& udq_result) {
this->udq_state.add_define(keyword, udq_result);
this->summary_state.update_udq(udq_result, this->udq_state.undefined_value());
}
}

View File

@ -251,13 +251,14 @@ bool dynamic_type_check(UDQVarType lhs, UDQVarType rhs) {
}
UDQSet UDQDefine::eval(UDQContext& context) const {
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);
}
context.update_define(this->keyword(), res);
if (res.var_type() == UDQVarType::SCALAR) {
/*
@ -298,7 +299,6 @@ UDQSet UDQDefine::eval(UDQContext& context) const {
}
}
res.name( this->m_keyword );
return res;
}

View File

@ -40,8 +40,13 @@ bool is_udq(const std::string& key) {
}
double UDQState::undefined_value() const {
return this->undef_value;
}
UDQState::UDQState(double undefined) :
undefined_value(undefined)
undef_value(undefined)
{}
bool UDQState::has(const std::string& key) const {
@ -99,7 +104,7 @@ double UDQState::get(const std::string& key) const {
if (result.defined())
return result.get();
else
return this->undefined_value;
return this->undef_value;
}
double UDQState::get_wg_var(const std::string& wgname, const std::string& key, UDQVarType var_type) const {
@ -118,7 +123,7 @@ double UDQState::get_wg_var(const std::string& wgname, const std::string& key, U
if (result.defined())
return result.get();
else
return this->undefined_value;
return this->undef_value;
}
double UDQState::get_well_var(const std::string& well, const std::string& key) const {
@ -130,7 +135,7 @@ double UDQState::get_group_var(const std::string& group, const std::string& key)
}
bool UDQState::operator==(const UDQState& other) const {
return this->undefined_value == other.undefined_value &&
return this->undef_value == other.undef_value &&
this->values == other.values;
}
@ -146,7 +151,7 @@ bool UDQState::assign(std::size_t report_step, const std::string& udq_key) const
std::vector<char> UDQState::serialize() const {
Serializer ser;
ser.put(this->undefined_value);
ser.put(this->undef_value);
ser.put(this->values.size());
for (const auto& set_pair : this->values) {
ser.put( set_pair.first );
@ -159,7 +164,7 @@ std::vector<char> UDQState::serialize() const {
void UDQState::deserialize(const std::vector<char>& buffer) {
Serializer ser(buffer);
this->undefined_value = ser.get<double>();
this->undef_value = ser.get<double>();
this->values.clear();
{

View File

@ -987,7 +987,7 @@ BOOST_AUTO_TEST_CASE(UDQ_POW_TEST) {
UDQFunctionTable udqft;
UDQParams udqp;
UDQDefine def_pow1(udqp, "WU", location, {"WOPR", "+", "WWPR", "*", "WGOR", "^", "WWIR"});
UDQDefine def_pow2(udqp, "WU", location, {"(", "WOPR", "+", "WWPR", ")", "^", "(", "WOPR", "+" , "WGOR", "*", "WWIR", "-", "WOPT", ")"});
UDQDefine def_pow2(udqp, "WU", location, {"(", "WOPR", "+", "WWPR", ")", "^", "(", "WOPR", "+" , "WGOR", "*", "WWIR", "-", "WBHP", ")"});
SummaryState st(std::chrono::system_clock::now());
UDQState udq_state(udqp.undefinedValue());
UDQContext context(udqft, st, udq_state);
@ -996,7 +996,7 @@ BOOST_AUTO_TEST_CASE(UDQ_POW_TEST) {
st.update_well_var("P1", "WWPR", 2);
st.update_well_var("P1", "WGOR", 3);
st.update_well_var("P1", "WWIR", 4);
st.update_well_var("P1", "WOPT", 7);
st.update_well_var("P1", "WBHP", 7);
auto res_pow1 = def_pow1.eval(context);
auto res_pow2 = def_pow2.eval(context);
@ -1118,10 +1118,10 @@ BOOST_AUTO_TEST_CASE(UDQ_SORTD_NAN) {
st.update_well_var("OP4", "WWIR", 4.0);
auto res1 = def.eval(context);
st.update_udq( res1, 0 );
context.update_define(def.keyword(), res1);
auto res_sort1 = def_sort.eval(context);
st.update_udq( res_sort1 , 0);
context.update_define(def_sort.keyword(), res_sort1);
BOOST_CHECK_EQUAL(res_sort1["OP1"].get(), 1.0);
BOOST_CHECK_EQUAL(res_sort1["OP2"].get(), 2.0);
BOOST_CHECK_EQUAL(res_sort1["OP3"].get(), 3.0);
@ -1132,11 +1132,13 @@ BOOST_AUTO_TEST_CASE(UDQ_SORTD_NAN) {
st.update_well_var("OP1", "WWIR", 0);
auto res2 = def.eval(context);
BOOST_CHECK_EQUAL(res2.defined_size(), 3U);
st.update_udq( res2, 0 );
context.update_define(def.keyword(), res2);
BOOST_CHECK( st.has_well_var("OP4", "WUPR1"));
auto res_sort2 = def_sort.eval(context);
st.update_udq( res_sort2, 0 );
context.update_define(def.keyword(), res2);
BOOST_CHECK_EQUAL(res_sort2.defined_size(), 3U);
BOOST_CHECK_EQUAL(res_sort2["OP2"].get(), 1.0);
BOOST_CHECK_EQUAL(res_sort2["OP3"].get(), 2.0);
@ -1162,10 +1164,7 @@ BOOST_AUTO_TEST_CASE(UDQ_SORTA) {
st.update_well_var("OPU02", "WWCT", 0.0);
auto res1 = def1.eval(context);
st.update_well_var("OPL01", "WUPR1", res1["OPL01"].get());
st.update_well_var("OPL02", "WUPR1", res1["OPL02"].get());
st.update_well_var("OPU01", "WUPR1", res1["OPU01"].get());
st.update_well_var("OPU02", "WUPR1", res1["OPU02"].get());
context.update_define(def1.keyword(), res1);
auto res_sort = def_sort.eval(context);
BOOST_CHECK_EQUAL(res_sort["OPL02"].get(), 1.0);