From c8cbd32f854b44f53e1762e2891cac434f0aaa5a Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 15 Oct 2021 14:14:20 +0200 Subject: [PATCH] Add method WellContainer::wells() --- opm/simulators/wells/WellContainer.hpp | 9 +++++++++ opm/simulators/wells/WellState.hpp | 4 ++++ tests/test_wellstate.cpp | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/opm/simulators/wells/WellContainer.hpp b/opm/simulators/wells/WellContainer.hpp index 6a7945481..1a517f16e 100644 --- a/opm/simulators/wells/WellContainer.hpp +++ b/opm/simulators/wells/WellContainer.hpp @@ -157,6 +157,15 @@ public: throw std::logic_error("No such well"); } + std::vector wells() const { + std::vector wlist; + for (const auto& [wname, _] : this->index_map) { + (void)_; + wlist.push_back(wname); + } + return wlist; + } + private: void update_if(std::size_t index, const std::string& name, const WellContainer& other) { diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index bffd8ffcf..362c3abaf 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -73,6 +73,10 @@ public: return this->wells_.size(); } + std::vector wells() const { + return this->wells_.wells(); + } + int numWells() const { diff --git a/tests/test_wellstate.cpp b/tests/test_wellstate.cpp index d59c4c2c2..592c058e2 100644 --- a/tests/test_wellstate.cpp +++ b/tests/test_wellstate.cpp @@ -17,8 +17,10 @@ along with OPM. If not, see . */ +#include #include #include +#include #define BOOST_TEST_MODULE WellStateFIBOTest @@ -440,6 +442,9 @@ BOOST_AUTO_TEST_CASE(TESTWellContainer) { BOOST_CHECK_EQUAL(wc.well_name(1), "W2"); BOOST_CHECK_THROW(wc.well_name(10), std::exception); + const auto& wells = wc.wells(); + std::vector expected = {"W1", "W2"}; + BOOST_CHECK( std::is_permutation( wells.begin(), wells.end(), expected.begin(), expected.end()) ); Opm::WellContainer wc2; wc2.copy_welldata(wc);