Add function SummaryState::update_udq() to add variables from UDQSet
This commit is contained in:
@@ -62,6 +62,8 @@ namespace Opm{
|
|||||||
st.has_well_var("OPY", "WGOR") => False
|
st.has_well_var("OPY", "WGOR") => False
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class UDQSet;
|
||||||
|
|
||||||
class SummaryState {
|
class SummaryState {
|
||||||
public:
|
public:
|
||||||
typedef std::unordered_map<std::string, double>::const_iterator const_iterator;
|
typedef std::unordered_map<std::string, double>::const_iterator const_iterator;
|
||||||
@@ -85,6 +87,7 @@ public:
|
|||||||
void update_well_var(const std::string& well, const std::string& var, double value);
|
void update_well_var(const std::string& well, const std::string& var, double value);
|
||||||
void update_group_var(const std::string& group, const std::string& var, double value);
|
void update_group_var(const std::string& group, const std::string& var, double value);
|
||||||
void update_elapsed(double delta);
|
void update_elapsed(double delta);
|
||||||
|
void update_udq(const UDQSet& udq_set);
|
||||||
|
|
||||||
double get(const std::string&) const;
|
double get(const std::string&) const;
|
||||||
double get_elapsed() const;
|
double get_elapsed() const;
|
||||||
|
|||||||
@@ -1380,64 +1380,29 @@ void eval_udq(const Opm::Schedule& schedule, std::size_t sim_step, Opm::SummaryS
|
|||||||
const UDQConfig& udq = schedule.getUDQConfig(sim_step);
|
const UDQConfig& udq = schedule.getUDQConfig(sim_step);
|
||||||
const auto& func_table = udq.function_table();
|
const auto& func_table = udq.function_table();
|
||||||
UDQContext context(func_table, st);
|
UDQContext context(func_table, st);
|
||||||
{
|
for (const auto& assign : udq.assignments(UDQVarType::WELL_VAR)) {
|
||||||
const std::vector<std::string> wells = st.wells();
|
auto ws = assign.eval(st.wells());
|
||||||
|
st.update_udq(ws);
|
||||||
for (const auto& assign : udq.assignments(UDQVarType::WELL_VAR)) {
|
|
||||||
auto ws = assign.eval(wells);
|
|
||||||
for (const auto& well : wells) {
|
|
||||||
const auto& udq_value = ws[well];
|
|
||||||
if (udq_value)
|
|
||||||
st.update_well_var(well, ws.name(), udq_value.value());
|
|
||||||
else
|
|
||||||
st.del_well_var(well, ws.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& def : udq.definitions(UDQVarType::WELL_VAR)) {
|
|
||||||
auto ws = def.eval(context);
|
|
||||||
for (const auto& well : wells) {
|
|
||||||
const auto& udq_value = ws[well];
|
|
||||||
if (udq_value)
|
|
||||||
st.update_well_var(well, def.keyword(), udq_value.value());
|
|
||||||
else
|
|
||||||
st.del_well_var(well, ws.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
for (const auto& def : udq.definitions(UDQVarType::WELL_VAR)) {
|
||||||
const std::vector<std::string> groups = st.groups();
|
auto ws = def.eval(context);
|
||||||
|
st.update_udq(ws);
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& assign : udq.assignments(UDQVarType::GROUP_VAR)) {
|
for (const auto& assign : udq.assignments(UDQVarType::GROUP_VAR)) {
|
||||||
auto ws = assign.eval(groups);
|
auto ws = assign.eval(st.groups());
|
||||||
for (const auto& group : groups) {
|
st.update_udq(ws);
|
||||||
const auto& udq_value = ws[group];
|
}
|
||||||
if (udq_value)
|
|
||||||
st.update_group_var(group, ws.name(), udq_value.value());
|
|
||||||
else
|
|
||||||
st.del_group_var(group, ws.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& def : udq.definitions(UDQVarType::GROUP_VAR)) {
|
for (const auto& def : udq.definitions(UDQVarType::GROUP_VAR)) {
|
||||||
auto ws = def.eval(context);
|
auto ws = def.eval(context);
|
||||||
for (const auto& group : groups) {
|
st.update_udq(ws);
|
||||||
const auto& udq_value = ws[group];
|
|
||||||
if (udq_value)
|
|
||||||
st.update_group_var(group, def.keyword(), udq_value.value());
|
|
||||||
else
|
|
||||||
st.del_group_var(group, ws.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& def : udq.definitions(UDQVarType::FIELD_VAR)) {
|
for (const auto& def : udq.definitions(UDQVarType::FIELD_VAR)) {
|
||||||
auto field_udq = def.eval(context);
|
auto field_udq = def.eval(context);
|
||||||
if (field_udq[0])
|
st.update_udq(field_udq);
|
||||||
st.update(def.keyword(), field_udq[0].value());
|
|
||||||
else
|
|
||||||
st.del(def.keyword());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.hpp>
|
||||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||||
|
|
||||||
namespace Opm{
|
namespace Opm{
|
||||||
@@ -146,6 +147,33 @@ namespace {
|
|||||||
this->m_wells.insert(well);
|
this->m_wells.insert(well);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SummaryState::update_udq(const UDQSet& udq_set) {
|
||||||
|
auto var_type = udq_set.var_type();
|
||||||
|
if (var_type == UDQVarType::WELL_VAR) {
|
||||||
|
const std::vector<std::string> wells = this->wells();
|
||||||
|
for (const auto& well : wells) {
|
||||||
|
const auto& udq_value = udq_set[well];
|
||||||
|
if (udq_value)
|
||||||
|
this->update_well_var(well, udq_set.name(), udq_value.value());
|
||||||
|
else
|
||||||
|
this->erase_well_var(well, udq_set.name());
|
||||||
|
}
|
||||||
|
} else if (var_type == UDQVarType::GROUP_VAR) {
|
||||||
|
const std::vector<std::string> groups = this->groups();
|
||||||
|
for (const auto& group : groups) {
|
||||||
|
const auto& udq_value = udq_set[group];
|
||||||
|
if (udq_value)
|
||||||
|
this->update_group_var(group, udq_set.name(), udq_value.value());
|
||||||
|
else
|
||||||
|
this->erase_group_var(group, udq_set.name());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const auto& udq_var = udq_set[0];
|
||||||
|
if (udq_var)
|
||||||
|
this->update(udq_set.name(), udq_var.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SummaryState::set(const std::string& key, double value) {
|
void SummaryState::set(const std::string& key, double value) {
|
||||||
this->values[key] = value;
|
this->values[key] = value;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ bool UDQScalar::defined() const {
|
|||||||
|
|
||||||
double UDQScalar::value() const {
|
double UDQScalar::value() const {
|
||||||
if (!this->m_defined)
|
if (!this->m_defined)
|
||||||
throw std::invalid_argument("UDQSCalar: Value not defined");
|
throw std::invalid_argument("UDQSCalar: Value not defined wgname:" + this->m_wgname);
|
||||||
|
|
||||||
return this->m_value;
|
return this->m_value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1039,6 +1039,30 @@ BOOST_AUTO_TEST_CASE(UDQ_SCALAR_SET) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(UDQ_SORTD_NAN) {
|
||||||
|
UDQParams udqp;
|
||||||
|
UDQFunctionTable udqft;
|
||||||
|
UDQDefine def1(udqp, "WUPR1" , {"1", "/", "(", "WWIR", "'OP*'" , ")"});
|
||||||
|
UDQDefine def_sort(udqp , "WUPR3", {"SORTD", "(", "WUPR1", ")" });
|
||||||
|
SummaryState st(std::chrono::system_clock::now());
|
||||||
|
UDQContext context(udqft, st);
|
||||||
|
|
||||||
|
st.update_well_var("OP1", "WWIR", 1.0);
|
||||||
|
st.update_well_var("OP2", "WWIR", 2.0);
|
||||||
|
st.update_well_var("OP3", "WWIR", 3.0);
|
||||||
|
st.update_well_var("OP4", "WWIR", 4.0);
|
||||||
|
|
||||||
|
auto res1 = def1.eval(context);
|
||||||
|
st.update_udq( res1 );
|
||||||
|
|
||||||
|
auto res_sort = def_sort.eval(context);
|
||||||
|
BOOST_CHECK_EQUAL(res_sort["OP1"].value(), 1.0);
|
||||||
|
BOOST_CHECK_EQUAL(res_sort["OP2"].value(), 2.0);
|
||||||
|
BOOST_CHECK_EQUAL(res_sort["OP3"].value(), 3.0);
|
||||||
|
BOOST_CHECK_EQUAL(res_sort["OP4"].value(), 4.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(UDQ_SORTA) {
|
BOOST_AUTO_TEST_CASE(UDQ_SORTA) {
|
||||||
UDQParams udqp;
|
UDQParams udqp;
|
||||||
|
|||||||
Reference in New Issue
Block a user