diff --git a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp index 46dba3e35..1f60ef7b4 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp @@ -91,10 +91,11 @@ public: explicit Result(bool result_arg); Result(bool result_arg, const std::vector& wells); Result(bool result_arg, const WellSet& wells); + Result(const Result& src); explicit operator bool() const; std::vector wells() const; - + bool has_well(const std::string& well); void add_well(const std::string& well); Result& operator|=(const Result& other); @@ -102,6 +103,12 @@ public: private: void assign(bool value); bool result; + /* + The set of matching wells is implemented with pointer semantics to be able + to differentiate between an empty set of wells - like all the wells with + WWCT > 1, and a result set which does not have well information at all - + e.g. FOPR > 0. + */ std::unique_ptr matching_wells; }; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.cpp index 664c2b856..202c6a2f4 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.cpp @@ -40,6 +40,13 @@ Result::Result(bool result_arg, const WellSet& wells) : this->matching_wells.reset( new WellSet(wells) ); } +Result::Result(const Result& src) +{ + this->result = src.result; + if (src.matching_wells) + this->matching_wells.reset( new WellSet(*src.matching_wells) ); +} + Result::operator bool() const { return this->result; @@ -87,6 +94,13 @@ void Result::add_well(const std::string& well) { this->matching_wells->add(well); } +bool Result::has_well(const std::string& well) { + if (!this->matching_wells) + return false; + + return this->matching_wells->contains(well); +} + /******************************************************************/ WellSet::WellSet(const std::vector& wells) diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index 587814588..f909a7128 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -754,3 +754,30 @@ 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()); + BOOST_CHECK(res2.wells() == std::vector()); + + 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; + + BOOST_CHECK(res1); + BOOST_CHECK(res2); + BOOST_CHECK(!res1.has_well("NO")); + BOOST_CHECK(!res2.has_well("NO")); + for (const auto& w : {"W1", "W2", "W3"}) { + BOOST_CHECK(res1.has_well(w)); + BOOST_CHECK(res2.has_well(w)); + } +}