diff --git a/opm/output/data/Wells.hpp b/opm/output/data/Wells.hpp index f765e2e37..71f6e8cf1 100644 --- a/opm/output/data/Wells.hpp +++ b/opm/output/data/Wells.hpp @@ -210,6 +210,30 @@ namespace Opm { template void read(MessageBufferType& buffer); + const Connection* find_connection(Connection::global_index connection_grid_index) const { + const auto connection = std::find_if( this->connections.begin() , + this->connections.end() , + [=]( const Connection& c ) { + return c.index == connection_grid_index; }); + + if( connection == this->connections.end() ) + return nullptr; + + return &*connection; + } + + Connection* find_connection(Connection::global_index connection_grid_index) { + auto connection = std::find_if( this->connections.begin() , + this->connections.end() , + [=]( const Connection& c ) { + return c.index == connection_grid_index; }); + + if( connection == this->connections.end() ) + return nullptr; + + return &*connection; + } + bool operator==(const Well& well2) const { return rates == well2.rates && diff --git a/tests/test_Wells.cpp b/tests/test_Wells.cpp index 0641022a4..95274a52b 100644 --- a/tests/test_Wells.cpp +++ b/tests/test_Wells.cpp @@ -122,4 +122,10 @@ BOOST_AUTO_TEST_CASE(get_completions) { BOOST_CHECK_EQUAL( 0.0, wellRates.get("OP_2" , 10000 , data::Rates::opt::wat) ); BOOST_CHECK_EQUAL( 26.41 , wellRates.get( "OP_2" , 188 , data::Rates::opt::wat)); + + + BOOST_CHECK(w1.find_connection(1234567) == nullptr); + const auto& conn = w1.find_connection(88); + BOOST_CHECK_EQUAL( 20.41, conn->rates.get(data::Rates::opt::wat)); + BOOST_CHECK_EQUAL( 22.41, conn->rates.get(data::Rates::opt::gas)); }