Add functionality to extract required summary keys from UDQConfig
This commit is contained in:
parent
faa1e7dc4d
commit
b53acbc6a7
@ -23,6 +23,7 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
@ -58,6 +59,7 @@ public:
|
||||
UDQASTNode* get_right() const;
|
||||
|
||||
bool operator==(const UDQASTNode& data) const;
|
||||
void required_summary(std::unordered_set<std::string>& summary_keys) const;
|
||||
|
||||
template<class Serializer>
|
||||
void serializeOp(Serializer& serializer)
|
||||
|
@ -79,6 +79,8 @@ namespace Opm {
|
||||
const UDQFunctionTable& function_table() const;
|
||||
|
||||
bool operator==(const UDQConfig& config) const;
|
||||
void required_summary(std::unordered_set<std::string>& summary_keys) const;
|
||||
|
||||
|
||||
template<class Serializer>
|
||||
void serializeOp(Serializer& serializer)
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQEnums.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.hpp>
|
||||
@ -73,6 +74,7 @@ public:
|
||||
const std::string& input_string() const;
|
||||
UDQVarType var_type() const;
|
||||
std::set<UDQTokenType> func_tokens() const;
|
||||
void required_summary(std::unordered_set<std::string>& summary_keys) const;
|
||||
|
||||
bool operator==(const UDQDefine& data) const;
|
||||
|
||||
|
@ -311,4 +311,34 @@ bool UDQASTNode::operator==(const UDQASTNode& data) const {
|
||||
selector == data.selector;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool is_udq(const std::string& key) {
|
||||
if (key.size() < 2)
|
||||
return false;
|
||||
|
||||
if (key[1] != 'U')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UDQASTNode::required_summary(std::unordered_set<std::string>& summary_keys) const {
|
||||
if (this->type == UDQTokenType::ecl_expr) {
|
||||
if (std::holds_alternative<std::string>(this->value)) {
|
||||
const auto& keyword = std::get<std::string>(this->value);
|
||||
if (!is_udq(keyword))
|
||||
summary_keys.insert(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->left)
|
||||
this->left->required_summary(summary_keys);
|
||||
|
||||
if (this->right)
|
||||
this->right->required_summary(summary_keys);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -342,6 +342,16 @@ namespace Opm {
|
||||
context.update_define(def.keyword(), field_udq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDQConfig::required_summary(std::unordered_set<std::string>& summary_keys) const {
|
||||
for (const auto& def_pair : this->m_definitions) {
|
||||
const auto& udq_def = def_pair.second;
|
||||
udq_def.required_summary(summary_keys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -251,6 +251,11 @@ bool dynamic_type_check(UDQVarType lhs, UDQVarType rhs) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void UDQDefine::required_summary(std::unordered_set<std::string>& summary_keys) const {
|
||||
this->ast->required_summary(summary_keys);
|
||||
}
|
||||
|
||||
UDQSet UDQDefine::eval(const UDQContext& context) const {
|
||||
UDQSet res = this->ast->eval(this->m_var_type, context);
|
||||
res.name( this->m_keyword );
|
||||
|
@ -1964,9 +1964,18 @@ DEFINE WUGASRA 750000 - WGLIR '*' /
|
||||
st.update_well_var("W3", "WGLIR", 3);
|
||||
|
||||
udq.eval(0, st, udq_state);
|
||||
|
||||
// The current testcase has some ordering & defined / undefined issues which
|
||||
// are not yet solved; therefor no udq.eval() here.
|
||||
{
|
||||
std::unordered_set<std::string> required_keys;
|
||||
udq.required_summary(required_keys);
|
||||
BOOST_CHECK_EQUAL( required_keys.size(), 7);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("TIMESTEP"), 1);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("FMWPR"), 1);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("WGLIR"), 1);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("FOPR"), 1);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("FMWIN"), 1);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("FMWPA"), 1);
|
||||
BOOST_CHECK_EQUAL( required_keys.count("FMWIA"), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2200,6 +2209,11 @@ UDQ
|
||||
auto undefined_value = udq.params().undefinedValue();
|
||||
UDQState udq_state(undefined_value);
|
||||
SummaryState st(std::chrono::system_clock::now());
|
||||
{
|
||||
std::unordered_set<std::string> required_keys;
|
||||
udq.required_summary(required_keys);
|
||||
BOOST_CHECK(required_keys.empty());
|
||||
}
|
||||
|
||||
udq.eval(0, st, udq_state);
|
||||
BOOST_CHECK_EQUAL(st.get("FU_VAR1"), 10);
|
||||
|
Loading…
Reference in New Issue
Block a user