Merge pull request #2005 from bska/wellconnections-empty

Add Convenience Predicate WellConnections::empty
This commit is contained in:
Joakim Hove 2020-10-08 08:05:15 +02:00 committed by GitHub
commit cc4f8faa4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 3 deletions

View File

@ -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;

View File

@ -664,7 +664,7 @@ bool Well::updateConnections(std::shared_ptr<WellConnections> connections_arg) {
bool Well::updateConnections(std::shared_ptr<WellConnections> connections_arg, const EclipseGrid& grid, const std::vector<int>& 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" );

View File

@ -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;

View File

@ -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() );