Merge pull request #1776 from joakim-hove/zwel-fix

Make sure the action name is only added to ZWEL when it is true
This commit is contained in:
Joakim Hove 2020-05-07 11:04:18 +02:00 committed by GitHub
commit b311cef875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 54 deletions

View File

@ -41,11 +41,6 @@ namespace Opm { namespace data {
namespace Opm { namespace RestartIO { namespace Helpers {
struct ActionResStatus {
std::vector<Opm::Action::Result> result;
std::vector<std::string> name;
};
class AggregateWellData
{
public:

View File

@ -101,9 +101,9 @@ public:
void add_well(const std::string& well);
Result& operator|=(const Result& other);
Result& operator=(const Result& src);
Result& operator=(const Result& src);
Result& operator&=(const Result& other);
private:
void assign(bool value);
bool result;

View File

@ -42,8 +42,9 @@
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <string>
#include <optional>
#include <iostream>
#include <string>
// #####################################################################
// Class Opm::RestartIO::Helpers
@ -480,13 +481,12 @@ const std::map<cmp_enum, int> cmpToIndex = {
Opm::Action::Result
act_res(const Opm::Schedule& sched, const Opm::SummaryState& smry, const std::size_t sim_step, std::vector<Opm::Action::ActionX>::const_iterator act_x) {
Opm::Action::Result ar(false);
Opm::Action::Context context(smry);
auto sim_time = sched.simTime(sim_step);
if (act_x->ready(sim_time)) {
ar = act_x->eval(sim_time, context);
}
return {ar};
Opm::Action::Context context(smry);
return act_x->eval(sim_time, context);
} else
return Opm::Action::Result(false);
}
template <class SACNArray>
@ -574,23 +574,18 @@ const std::map<cmp_enum, int> cmpToIndex = {
//Treat well, group and field left hand side conditions
if (it_lhsq != lhsQuantityToIndex.end()) {
std::string wn = "";
//Well variable
if (it_lhsq->first == "W") {
if (it_lhsq->first == "W" && ar) {
//find the well that violates action if relevant
for (const auto& well : wells)
{
if (ar.has_well(well.name())) {
//set well name
wn = well.name();
break;
}
}
auto well_iter = std::find_if(wells.begin(), wells.end(), [&ar](const Opm::Well& well) { return ar.has_well(well.name()); });
if (well_iter != wells.end()) {
const auto& wn = well_iter->name();
if ((it_lhsq->first == "W") && (st.has_well_var(wn, z_data.lhs.quantity)) ) {
sAcn[ind + 4] = st.get_well_var(wn, z_data.lhs.quantity);
sAcn[ind + 6] = st.get_well_var(wn, z_data.lhs.quantity);
sAcn[ind + 8] = st.get_well_var(wn, z_data.lhs.quantity);
if (st.has_well_var(wn, z_data.lhs.quantity)) {
sAcn[ind + 4] = st.get_well_var(wn, z_data.lhs.quantity);
sAcn[ind + 6] = st.get_well_var(wn, z_data.lhs.quantity);
sAcn[ind + 8] = st.get_well_var(wn, z_data.lhs.quantity);
}
}
}
//group variable

View File

@ -722,32 +722,33 @@ namespace {
};
}
Opm::RestartIO::Helpers::ActionResStatus
std::vector<std::pair<std::string, Opm::Action::Result>>
act_res_stat(const Opm::Schedule& sched, const Opm::SummaryState& smry, const std::size_t sim_step) {
std::vector<Opm::Action::Result> act_res;
std::vector<std::string> act_name;
std::vector<std::pair<std::string, Opm::Action::Result>> results;
const auto& acts = sched.actions(sim_step);
Opm::Action::Context context(smry);
auto sim_time = sched.simTime(sim_step);
for (const auto& action : acts.pending(sim_time)) {
act_res.push_back(action->eval(sim_time, context));
act_name.push_back(action->name());
auto result = action->eval(sim_time, context);
if (result)
results.emplace_back( action->name(), std::move(result) );
}
return {act_res, act_name};
return results;
}
template <class ZWellArray>
void staticContrib(const Opm::Well& well, const Opm::RestartIO::Helpers::ActionResStatus& actResStat, ZWellArray& zWell)
void staticContrib(const Opm::Well& well, const std::vector<std::pair<std::string, Opm::Action::Result>>& actResStat, ZWellArray& zWell)
{
using Ix = ::Opm::RestartIO::Helpers::VectorItems::ZWell::index;
zWell[Ix::WellName] = well.name();
//loop over actions to assign action name for relevant wells
for (std::size_t ind = 0; ind < actResStat.result.size(); ind++) {
if (actResStat.result[ind].has_well(well.name())) {
zWell[Ix::ActionX] = actResStat.name[ind];
for (const auto& [action_name, action_result] : actResStat) {
if (action_result.has_well(well.name())) {
zWell[Ix::ActionX] = action_name;
}
}
}
} // ZWell
} // Anonymous

View File

@ -44,7 +44,7 @@ Result::Result(bool result_arg, const WellSet& wells) :
Result::Result(const Result& src)
{
this->result = src.result;
if (src.matching_wells)
if (src.matching_wells)
this->matching_wells.reset( new WellSet(*src.matching_wells) );
}
@ -53,6 +53,9 @@ Result::operator bool() const {
}
std::vector<std::string> Result::wells() const {
if (!this->result)
throw std::logic_error("Programming error: trying to check wells in ActionResult which is false");
if (this->matching_wells)
return this->matching_wells->wells();
else
@ -83,11 +86,11 @@ Result& Result::operator&=(const Result& other) {
return *this;
}
Result& Result::operator=(const Result& src)
Result& Result::operator=(const Result& src)
{
this->result = src.result;
if (src.matching_wells) this->matching_wells.reset( new WellSet(*src.matching_wells) );
return *this;
}
@ -102,6 +105,9 @@ void Result::add_well(const std::string& well) {
}
bool Result::has_well(const std::string& well) const {
if (!this->result)
throw std::logic_error("Programming error: trying to check wells in ActionResult which is false");
if (!this->matching_wells)
return false;

View File

@ -608,8 +608,9 @@ BOOST_AUTO_TEST_CASE(TestFieldAND) {
st.update("FMWPR", 1);
{
auto res = ast.eval(context);
auto wells = res.wells();
BOOST_CHECK(!res);
BOOST_CHECK_THROW(res.wells(), std::logic_error);
BOOST_CHECK_THROW(res.has_well("ABC"), std::logic_error);
}
st.update("FMWPR", 4);
@ -783,19 +784,6 @@ TSTEP
BOOST_AUTO_TEST_CASE(ACTIONRESULT_COPY_EMPTY) {
Action::Result res1(false);
auto res2 = res1;
BOOST_CHECK(!res1);
BOOST_CHECK(!res2);
BOOST_CHECK(res1.wells() == std::vector<std::string>());
BOOST_CHECK(res2.wells() == std::vector<std::string>());
BOOST_CHECK(!res1.has_well("NO"));
BOOST_CHECK(!res2.has_well("NO"));
}
BOOST_AUTO_TEST_CASE(ACTIONRESULT_COPY_WELLS) {
Action::Result res1(true, {"W1", "W2", "W3"});
auto res2 = res1;