Use WellMatcher() in Schedule::wellNames()

This commit is contained in:
Joakim Hove 2020-10-30 22:17:28 +01:00
parent 7ef7e3017e
commit 14df089f14
3 changed files with 10 additions and 33 deletions

View File

@ -1050,40 +1050,12 @@ private:
std::vector<std::string> Schedule::wellNames(const std::string& pattern, std::size_t timeStep, const std::vector<std::string>& matching_wells) const {
if (pattern.size() == 0)
return {};
// WLIST
if (pattern[0] == '*' && pattern.size() > 1) {
const auto& wlm = this->getWListManager(timeStep);
return wlm.wells(pattern);
}
// Normal pattern matching
auto star_pos = pattern.find('*');
if (star_pos != std::string::npos) {
std::vector<std::string> names;
for (const auto& well_pair : this->wells_static) {
if (name_match(pattern, well_pair.first)) {
const auto& dynamic_state = well_pair.second;
if (dynamic_state.get(timeStep))
names.push_back(well_pair.first);
}
}
return names;
}
// ACTIONX handler
if (pattern == "?")
return { matching_wells.begin(), matching_wells.end() };
// Normal well name without any special characters
if (this->hasWell(pattern)) {
const auto& dynamic_state = this->wells_static.at(pattern);
if (dynamic_state.get(timeStep))
return { pattern };
}
return {};
auto wm = this->wellMatcher(timeStep);
return wm.wells(pattern);
}

View File

@ -146,11 +146,12 @@ UDQSet UDQASTNode::eval(UDQVarType target_type, const UDQContext& context) const
auto data_type = UDQ::targetType(string_value);
if (data_type == UDQVarType::WELL_VAR) {
const auto& all_wells = context.wells();
auto res = UDQSet::wells(string_value, all_wells);
if (this->selector.empty()) {
auto res = UDQSet::wells(string_value, all_wells);
for (const auto& well : all_wells)
res.assign(well, context.get_well_var(well, string_value));
return this->sign * res;
} else {
const std::string& well_pattern = this->selector[0];
if (well_pattern.find('*') == std::string::npos)
@ -160,7 +161,7 @@ UDQSet UDQASTNode::eval(UDQVarType target_type, const UDQContext& context) const
*scalar* - and that scalar value is distributed among all
the wells in the result set.
*/
res.assign( context.get_well_var(well_pattern, string_value));
return this->sign * UDQSet::scalar(string_value, context.get_well_var(well_pattern, string_value));
else {
/*
The right hand side is a set of wells. The result set will
@ -168,11 +169,12 @@ UDQSet UDQASTNode::eval(UDQVarType target_type, const UDQContext& context) const
missing in the right hand set will be undefined in the
result set.
*/
auto res = UDQSet::wells(string_value, all_wells);
for (const auto& wname : context.wells(well_pattern))
res.assign(wname, context.get_well_var(wname, string_value));
return this->sign * res;
}
}
return this->sign * res;
}
if (data_type == UDQVarType::GROUP_VAR) {

View File

@ -2345,6 +2345,7 @@ WLIST
UDQ
DEFINE FU_VAR1 SUM(WOPR '*ILIST') /
DEFINE FU_VAR2 SUM(WOPR '*') /
DEFINE FU_VAR3 WOPR 'P4' /
/
)";
@ -2361,7 +2362,9 @@ UDQ
udq.eval(0, schedule.wellMatcher(0), st, udq_state);
auto fu_var1 = st.get("FU_VAR1");
auto fu_var2 = st.get("FU_VAR2");
auto fu_var3 = st.get("FU_VAR3");
BOOST_CHECK_EQUAL(fu_var1, 6);
BOOST_CHECK_EQUAL(fu_var2, 10);
BOOST_CHECK_EQUAL(fu_var3, 4);
}