diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp index dd348ef1e..bc6406077 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp @@ -61,6 +61,7 @@ namespace Opm { void add( Connection ); size_t size() const; + bool empty() const; const Connection& operator[](size_t index) const; const Connection& get(size_t index) const; const Connection& getFromIJK(const int i, const int j, const int k) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp index 8f397c080..bd608fa42 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp @@ -664,7 +664,7 @@ bool Well::updateConnections(std::shared_ptr connections_arg) { bool Well::updateConnections(std::shared_ptr connections_arg, const EclipseGrid& grid, const std::vector& pvtnum) { bool update = this->updateConnections(connections_arg); - if (this->pvt_table == 0 && this->connections->size() > 0) { + if (this->pvt_table == 0 && !this->connections->empty()) { const auto& lowest = this->connections->lowest(); auto active_index = grid.activeIndex(lowest.global_index()); this->pvt_table = pvtnum[active_index]; @@ -778,7 +778,7 @@ double Well::getRefDepth() const { return this->ref_depth; // ref depth was defaulted and we get the depth of the first completion - if( this->connections->size() == 0 ) { + if( this->connections->empty() ) { throw std::invalid_argument( "No completions defined for well: " + name() + ". Can not infer reference depth" ); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp index c721b43c9..d4c8f97f8 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp @@ -417,6 +417,10 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction return m_connections.size(); } + bool WellConnections::empty() const { + return this->size() == size_t{0}; + } + const Connection& WellConnections::get(size_t index) const { return (*this)[index]; } @@ -466,7 +470,7 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction } bool WellConnections::allConnectionsShut( ) const { - if (this->size() == 0) + if (this->empty()) return false; diff --git a/tests/parser/ConnectionTests.cpp b/tests/parser/ConnectionTests.cpp index ec1eb8cb2..1494c0aa8 100644 --- a/tests/parser/ConnectionTests.cpp +++ b/tests/parser/ConnectionTests.cpp @@ -61,6 +61,7 @@ inline std::ostream& operator<<( std::ostream& stream, const WellConnections& cs BOOST_AUTO_TEST_CASE(CreateWellConnectionsOK) { Opm::WellConnections completionSet(Opm::Connection::Order::TRACK, 1,1); + BOOST_CHECK_MESSAGE( completionSet.empty(), "Default-constructed completion set must be empty" ); BOOST_CHECK_EQUAL( 0U , completionSet.size() ); BOOST_CHECK(!completionSet.allConnectionsShut()); } @@ -75,6 +76,7 @@ BOOST_AUTO_TEST_CASE(AddCompletionSizeCorrect) { Opm::Connection completion2( 10,10,11, 102, 1, 0.0, Opm::Connection::State::SHUT , 99.88, 355.113, 0.25, 0.0, 0.0, 0, dir, kind, 0, true); completionSet.add( completion1 ); BOOST_CHECK_EQUAL( 1U , completionSet.size() ); + BOOST_CHECK_MESSAGE( !completionSet.empty(), "Non-empty completion set must not be empty" ); completionSet.add( completion2 ); BOOST_CHECK_EQUAL( 2U , completionSet.size() );