Merge pull request #3715 from blattms/backport-of-pr-3708

Don't Reference Non-Existent W/G Names From UDQ Set
This commit is contained in:
Markus Blatt 2023-10-16 15:18:34 +02:00 committed by GitHub
commit c419f8951d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -255,6 +255,11 @@ namespace Opm
if (var_type == UDQVarType::WELL_VAR) {
const std::vector<std::string> wells = this->wells(); // Intentional copy
for (const auto& well : wells) {
if (! udq_set.has(well)) {
this->update_well_var(well, udq_set.name(), undefined_value);
continue;
}
const auto& udq_value = udq_set[well].value();
this->update_well_var(well, udq_set.name(), udq_value.value_or(undefined_value));
}
@ -262,6 +267,11 @@ namespace Opm
else if (var_type == UDQVarType::GROUP_VAR) {
const std::vector<std::string> groups = this->groups(); // Intentional copy
for (const auto& group : groups) {
if (! udq_set.has(group)) {
this->update_group_var(group, udq_set.name(), undefined_value);
continue;
}
const auto& udq_value = udq_set[group].value();
this->update_group_var(group, udq_set.name(), udq_value.value_or(undefined_value));
}

View File

@ -2905,3 +2905,30 @@ BOOST_AUTO_TEST_CASE(UDQ_ASSIGN_SEGMENT)
BOOST_CHECK_EQUAL(all.size(), std::size_t{3}); // Three different SU* variables
}
}
BOOST_AUTO_TEST_CASE(UDQ_Update_SummaryState)
{
auto st = SummaryState { TimeService::now() };
// P2 not yet online
st.update_well_var("P1", "WBHP", 42.0);
st.update_well_var("P2", "WBHP", 0.0);
st.update_well_var("P3", "WBHP", 121.2);
// BB not yet online
st.update_group_var("G1", "GOPR", 1222.0);
st.update_group_var("BB", "GOPR", 0.0);
st.update_group_var("AA", "GOPR", 1234.5);
// P2 not yet online
st.update_udq(UDQSet::wells("WUBAR", { "P1", "P3" }, 17.29), -123.4);
BOOST_CHECK_CLOSE(st.get_well_var("P1", "WUBAR"), 17.29, 1.0e-8);
BOOST_CHECK_CLOSE(st.get_well_var("P2", "WUBAR"), -123.4 , 1.0e-8);
BOOST_CHECK_CLOSE(st.get_well_var("P3", "WUBAR"), 17.29, 1.0e-8);
// BB not yet online
st.update_udq(UDQSet::groups("GUNDA_ST", { "G1", "AA" }, 652.44), -123.4);
BOOST_CHECK_CLOSE(st.get_group_var("AA", "GUNDA_ST"), 652.44, 1.0e-8);
BOOST_CHECK_CLOSE(st.get_group_var("BB", "GUNDA_ST"), -123.4 , 1.0e-8);
BOOST_CHECK_CLOSE(st.get_group_var("G1", "GUNDA_ST"), 652.44, 1.0e-8);
}