Make sure UDQ can use also special summary values like TIME

This commit is contained in:
Joakim Hove 2020-11-15 10:02:34 +01:00
parent e9e56fc5b5
commit e0e5ed1f91
3 changed files with 22 additions and 11 deletions

View File

@ -2069,6 +2069,7 @@ namespace Evaluator {
const auto val = st.get_elapsed() + stepSize;
st.update(this->saveKey_, usys.from_si(m, val));
st.update("TIME", usys.from_si(m, val));
}
private:
@ -2995,6 +2996,7 @@ std::vector<Opm::EclIO::SummaryNode> make_default_nodes(const std::string& keywo
void Opm::out::Summary::SummaryImplementation::configureUDQ(const SummaryConfig& summary_config, const Schedule& sched) {
const std::unordered_set<std::string> time_vectors = {"TIME", "DAY", "MONTH", "YEAR", "YEARS"};
auto nodes = std::vector<Opm::EclIO::SummaryNode> {};
std::unordered_set<std::string> summary_keys;
for (const auto& udq_ptr : sched.udqConfigList())
@ -3007,20 +3009,31 @@ void Opm::out::Summary::SummaryImplementation::configureUDQ(const SummaryConfig&
}
for (const auto& node: nodes) {
// Handler already configured/requested through the normal SummaryConfig path.
if (summary_config.hasSummaryKey(node.unique_key()))
// Handler already exists. Don't add second evaluation.
continue;
// Time related vectors are special cased in the valueKeys_ vector and must be checked explicitly.
if (time_vectors.count(node.keyword) > 0)
continue;
// Handler already registered in the summary evaluator, in some other way.
if ( std::find(this->valueKeys_.begin(), this->valueKeys_.end(), node.unique_key()) != this->valueKeys_.end())
continue;
auto fun_pos = funs.find(node.keyword);
if (fun_pos != funs.end())
if (fun_pos != funs.end()) {
this->extra_parameters.emplace( node.unique_key(), std::make_unique<Evaluator::FunctionRelation>(node, fun_pos->second) );
else {
auto unit = single_values_units.find(node.keyword);
if (unit == single_values_units.end())
throw std::logic_error(fmt::format("Evaluation function for: {} not found ", node.keyword));
this->extra_parameters.emplace( node.unique_key(), std::make_unique<Evaluator::GlobalProcessValue>(node, unit->second));
continue;
}
auto unit = single_values_units.find(node.keyword);
if (unit != single_values_units.end()) {
this->extra_parameters.emplace( node.unique_key(), std::make_unique<Evaluator::GlobalProcessValue>(node, unit->second));
continue;
}
throw std::logic_error(fmt::format("Evaluation function for: {} not found ", node.keyword));
}
}

View File

@ -56,12 +56,10 @@ bool is_udq(const std::string& key) {
the underlying summary state object.
*/
this->add("ELAPSED", 0.0);
this->add("MSUMLINS", 0.0);
this->add("MSUMNEWT", 0.0);
this->add("NEWTON", 0.0);
this->add("TCPU", 0.0);
this->add("TIME", 0.0);
}

View File

@ -583,7 +583,7 @@ BOOST_AUTO_TEST_CASE(UDQ_CONTEXT) {
BOOST_CHECK_EQUAL(*ctx.get("JAN"), 1.0);
BOOST_CHECK_THROW(ctx.get("NO_SUCH_KEY"), std::out_of_range);
for (std::string& key : std::vector<std::string>({"ELAPSED", "MSUMLINS", "MSUMNEWT", "NEWTON", "TCPU", "TIME"}))
for (std::string& key : std::vector<std::string>({"MSUMLINS", "MSUMNEWT", "NEWTON", "TCPU"}))
BOOST_CHECK_NO_THROW( ctx.get(key) );
st.update("SX:KEY", 1.0);