From fd3000cd310d2a40115d705ee907ceb893a47ffb Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 25 Jun 2018 16:21:51 +0200 Subject: [PATCH] WellConnections::add() does not inspect IJK --- .../EclipseState/Schedule/Connection.hpp | 8 +-- .../MSW/updatingConnectionsWithSegments.hpp | 2 +- .../eclipse/EclipseState/Schedule/Well.hpp | 1 + .../EclipseState/Schedule/MSW/Compsegs.cpp | 5 +- .../MSW/updatingConnectionsWithSegments.cpp | 9 ++- .../EclipseState/Schedule/Schedule.cpp | 7 +-- .../eclipse/EclipseState/Schedule/Well.cpp | 9 +++ .../EclipseState/Schedule/WellConnections.cpp | 63 +++++++++++++------ tests/parser/ConnectionTests.cpp | 14 ----- tests/parser/MultisegmentWellTests.cpp | 2 +- tests/parser/WellTests.cpp | 35 ----------- tests/parser/integration/ParseKEYWORD.cpp | 12 ++-- 12 files changed, 73 insertions(+), 94 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp b/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp index 226113c95..10a04081f 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp @@ -80,6 +80,10 @@ namespace Opm { bool operator==( const Connection& ) const; bool operator!=( const Connection& ) const; + // related segment number + // -1 means the completion is not related to segment + int m_segment_number = -1; + double m_center_depth; private: int m_i, m_j, m_k; @@ -93,10 +97,6 @@ namespace Opm { WellCompletion::DirectionEnum m_direction; Value getDiameterAsValueObject() const; Value getSkinFactorAsValueObject() const; - // related segment number - // -1 means the completion is not related to segment - int m_segment_number = -1; - double m_center_depth; }; } diff --git a/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.hpp b/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.hpp index 222d412a2..23283487a 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.hpp @@ -26,7 +26,7 @@ #include namespace Opm { - WellConnections * updatingConnectionsWithSegments(const DeckKeyword& compsegs, const WellConnections& input_connections, const WellSegments& segments); + WellConnections * newConnectionsWithSegments(const DeckKeyword& compsegs, const WellConnections& input_connections, const WellSegments& segments); } #endif diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well.hpp index 25d689c36..ccf567d50 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well.hpp @@ -166,6 +166,7 @@ namespace Opm { void addEvent(ScheduleEvents::Events event, size_t reportStep); bool hasEvent(uint64_t eventMask, size_t reportStep) const; void handleCOMPDAT(size_t time_step, const DeckRecord& record, const EclipseGrid& grid, const Eclipse3DProperties& eclipseProperties); + void handleCOMPSEGS(const DeckKeyword& keyword, size_t time_step); /* Will remove all completions which are attached to inactive cells. Will diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp index 5308dc6c3..99e37a833 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp @@ -238,8 +238,9 @@ namespace Opm { const int j = compseg.m_j; const int k = compseg.m_k; - const Connection& connection = connection_set.getFromIJK( i, j, k ); - connection_set.add(Connection(connection, compseg.m_segment_number, compseg.m_center_depth) ); + Connection& connection = connection_set.getFromIJK( i, j, k ); + connection.m_segment_number = compseg.m_segment_number; + connection.m_center_depth = compseg.m_center_depth; } for (size_t ic = 0; ic < connection_set.size(); ++ic) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.cpp index e48fbcd2e..04e426957 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.cpp @@ -22,12 +22,11 @@ namespace Opm { - - WellConnections * updatingConnectionsWithSegments(const DeckKeyword& compsegs, - const WellConnections& input_connections, - const WellSegments& segment_set) + WellConnections * newConnectionsWithSegments(const DeckKeyword& compsegs, + const WellConnections& input_connections, + const WellSegments& segment_set) { - WellConnections * new_connection_set = new WellConnections(input_connections); + WellConnections * new_connection_set = new WellConnections(input_connections); std::vector compsegs_vector = Compsegs::compsegsFromCOMPSEGSKeyword( compsegs ); Compsegs::processCOMPSEGS(compsegs_vector, segment_set); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 549a66a80..46a94e639 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -1455,12 +1455,7 @@ namespace Opm { const auto& record1 = keyword.getRecord(0); const std::string& well_name = record1.getItem("WELL").getTrimmedString(0); auto& well = this->m_wells.get( well_name ); - - const auto& segment_set = well.getWellSegments(currentStep); - const auto& completion_set = well.getConnections( currentStep ); - WellConnections * new_completion_set = updatingConnectionsWithSegments(keyword, completion_set, segment_set); - - well.updateWellConnections(currentStep, new_completion_set); + well.handleCOMPSEGS(keyword, currentStep); } void Schedule::handleWGRUPCON( const DeckKeyword& keyword, size_t currentStep) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp index 7de072cb3..964d97a04 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -598,4 +599,12 @@ namespace Opm { this->updateWellConnections(time_step, connections); } + + void Well::handleCOMPSEGS(const DeckKeyword& keyword, size_t time_step) { + const auto& segment_set = this->getWellSegments(time_step); + const auto& completion_set = this->getConnections( time_step ); + WellConnections * new_connection_set = newConnectionsWithSegments(keyword, completion_set, segment_set); + this->updateWellConnections(time_step, new_connection_set); + } + } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp index ec8c74d76..0778e40e6 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp @@ -131,14 +131,37 @@ namespace Opm { if (defaultSatTable) satTableId = satnum.iget(grid.getGlobalIndex(I,J,k)); - this->addConnection(I,J,k, - grid.getCellDepth( I,J,k ), - state, - connectionTransmissibilityFactor, - diameter, - skinFactor, - satTableId, - direction ); + auto same_ijk = [&]( const Connection& c ) { + return c.sameCoordinate( I,J,k ); + }; + + auto prev = std::find_if( this->m_connections.begin(), + this->m_connections.end(), + same_ijk ); + + if (prev == this->m_connections.end()) { + this->addConnection(I,J,k, + grid.getCellDepth( I,J,k ), + state, + connectionTransmissibilityFactor, + diameter, + skinFactor, + satTableId, + direction ); + } else { + // The complnum value carries over; the rest of the state is fully specified by + // the current COMPDAT keyword. + int complnum = prev->complnum(); + *prev = Connection(I,J,k, + complnum, + grid.getCellDepth(I,J,k), + state, + connectionTransmissibilityFactor, + diameter, + skinFactor, + satTableId, + direction ); + } } } @@ -174,21 +197,21 @@ namespace Opm { void WellConnections::add( Connection connection ) { - auto same = [&]( const Connection& c ) { - return c.sameCoordinate( connection ); - }; + //auto same = [&]( const Connection& c ) { + // return c.sameCoordinate( connection ); + //}; - auto prev = std::find_if( this->m_connections.begin(), - this->m_connections.end(), - same ); + //auto prev = std::find_if( this->m_connections.begin(), + // this->m_connections.end(), + // same ); - if( prev != this->m_connections.end() ) { - // update the completion, but preserve it's number - *prev = Connection( connection, prev->complnum() ); - return; - } + //if( prev != this->m_connections.end() ) { + // // update the completion, but preserve it's number + // *prev = Connection( connection, prev->complnum() ); + // return; + //} - m_connections.emplace_back( connection ); + m_connections.emplace_back( connection ); } bool WellConnections::allConnectionsShut( ) const { diff --git a/tests/parser/ConnectionTests.cpp b/tests/parser/ConnectionTests.cpp index 5f123909f..cbeba5133 100644 --- a/tests/parser/ConnectionTests.cpp +++ b/tests/parser/ConnectionTests.cpp @@ -122,20 +122,6 @@ BOOST_AUTO_TEST_CASE(WellConnectionsGetOutOfRangeThrows) { -BOOST_AUTO_TEST_CASE(AddCompletionSameCellUpdates) { - Opm::WellConnections completionSet; - Opm::Connection completion1( 10,10,10, 1, 0.0, Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - Opm::Connection completion2( 10,10,10, 1, 0.0,Opm::WellCompletion::SHUT , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - - - completionSet.add( completion1 ); - BOOST_CHECK_EQUAL( 1U , completionSet.size() ); - - completionSet.add( completion2 ); - BOOST_CHECK_EQUAL( 1U , completionSet.size() ); -} - - BOOST_AUTO_TEST_CASE(AddCompletionCopy) { Opm::WellConnections completionSet; diff --git a/tests/parser/MultisegmentWellTests.cpp b/tests/parser/MultisegmentWellTests.cpp index bced9f3a2..ee04b4a86 100644 --- a/tests/parser/MultisegmentWellTests.cpp +++ b/tests/parser/MultisegmentWellTests.cpp @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(MultisegmentWellTest) { BOOST_CHECK_EQUAL(6U, segment_set.size()); - const Opm::WellConnections * new_connection_set = Opm::updatingConnectionsWithSegments(compsegs, connection_set, segment_set); + const Opm::WellConnections * new_connection_set = Opm::newConnectionsWithSegments(compsegs, connection_set, segment_set); BOOST_CHECK_EQUAL(7U, new_connection_set->size()); diff --git a/tests/parser/WellTests.cpp b/tests/parser/WellTests.cpp index 6cc94e383..87d6108b2 100644 --- a/tests/parser/WellTests.cpp +++ b/tests/parser/WellTests.cpp @@ -337,41 +337,6 @@ BOOST_AUTO_TEST_CASE(NewWellZeroCompletions) { BOOST_CHECK_EQUAL( 0U , well.getConnections( 0 ).size() ); } - -BOOST_AUTO_TEST_CASE(UpdateCompletions) { - auto timeMap = createXDaysTimeMap(10); - - Opm::Well well("WELL1" , 0, 0, 0.0, Opm::Phase::OIL, timeMap , 0); - const auto& completions = well.getConnections( 0 ); - BOOST_CHECK_EQUAL( 0U , completions.size()); - - Opm::Connection comp1( 10 , 10 , 10 , 1, 10, Opm::WellCompletion::AUTO , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - Opm::Connection comp2( 10 , 10 , 11 , 1, 11, Opm::WellCompletion::SHUT , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - Opm::Connection comp3( 10 , 10 , 12 , 1, 12, Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - Opm::Connection comp4( 10 , 10 , 12 , 1, 12, Opm::WellCompletion::SHUT , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - Opm::Connection comp5( 10 , 10 , 13 , 1, 13, Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); - - //std::vector newCompletions2{ comp4 , comp5}; Newer c++ - - std::vector< Opm::Connection > newCompletions, newCompletions2; - newCompletions.push_back( comp1 ); - newCompletions.push_back( comp2 ); - newCompletions.push_back( comp3 ); - - newCompletions2.push_back( comp4 ); - newCompletions2.push_back( comp5 ); - - BOOST_CHECK_EQUAL( 3U , newCompletions.size()); - well.addConnections( 5 , newCompletions ); - BOOST_CHECK_EQUAL( 3U , well.getConnections( 5 ).size()); - BOOST_CHECK_EQUAL( comp3 , well.getConnections( 5 ).get(2)); - - well.addConnections( 6 , newCompletions2 ); - - BOOST_CHECK_EQUAL( 4U , well.getConnections( 6 ).size()); - BOOST_CHECK_EQUAL( comp4 , well.getConnections( 6 ).get(2)); -} - // Helper function for CompletionOrder test. inline Opm::Connection connection( int i, int j, int k, int complnum = 1 ) { return Opm::Connection { i, j, k, diff --git a/tests/parser/integration/ParseKEYWORD.cpp b/tests/parser/integration/ParseKEYWORD.cpp index 02149bfe2..f47d3c3e5 100644 --- a/tests/parser/integration/ParseKEYWORD.cpp +++ b/tests/parser/integration/ParseKEYWORD.cpp @@ -443,13 +443,8 @@ BOOST_AUTO_TEST_CASE( MULTREGT_ECLIPSE_STATE ) { BOOST_AUTO_TEST_CASE( MULTISEGMENT_ABS ) { const Parser parser; const std::string deckFile(pathprefix() + "SCHEDULE/SCHEDULE_MULTISEGMENT_WELL"); - const auto deck = parser.parseFile(deckFile, ParseContext()); const ParseContext parseContext; - const EclipseState state(deck, parseContext); - const auto& grid = state.getInputGrid(); - const TableManager table ( deck ); - const Eclipse3DProperties eclipseProperties ( deck , table, grid); - const Schedule sched(deck, grid, eclipseProperties, Phases(true, true, true), parseContext ); + const auto deck = parser.parseFile(deckFile, parseContext); // for WELSEGS keyword const auto& kw = deck.getKeyword("WELSEGS"); @@ -568,6 +563,11 @@ BOOST_AUTO_TEST_CASE( MULTISEGMENT_ABS ) { BOOST_CHECK_EQUAL( 3237.5, distance_end ); } + const EclipseState state(deck, parseContext); + const auto& grid = state.getInputGrid(); + const TableManager table ( deck ); + const Eclipse3DProperties eclipseProperties ( deck , table, grid); + const Schedule sched(deck, grid, eclipseProperties, Phases(true, true, true), parseContext ); // checking the relation between segments and completions // and also the depth of completions {