From 94fae0da30acfe07aa5b3da204a38edeb93f646c Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sat, 23 Mar 2019 17:18:27 +0100 Subject: [PATCH] Remove Schedule::getWells(pattern) --- .../EclipseState/Schedule/Schedule.hpp | 1 - .../EclipseState/Schedule/Schedule.cpp | 33 +------------------ .../SummaryConfig/SummaryConfig.cpp | 33 ++++++++++--------- tests/parser/ScheduleTests.cpp | 20 ----------- tests/parser/WellSolventTests.cpp | 14 ++++---- tests/parser/WellTracerTests.cpp | 18 +++++----- 6 files changed, 34 insertions(+), 85 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 301586ee8..043cf1ee6 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -138,7 +138,6 @@ namespace Opm std::vector< const Group* > getChildGroups(const std::string& group_name, size_t timeStep) const; std::vector< const Well* > getWells(const std::string& group, size_t timeStep) const; std::vector< const Well* > getChildWells(const std::string& group_name, size_t timeStep) const; - std::vector< const Well* > getWellsMatching( const std::string& ) const; const OilVaporizationProperties& getOilVaporizationProperties(size_t timestep) const; const WellTestConfig& wtestConfig(size_t timestep) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 0b81650e2..0e47a204e 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -1926,10 +1926,7 @@ namespace Opm { return wells; } - std::vector< const Well* > Schedule::getWellsMatching( const std::string& wellNamePattern ) const { - auto tmp = const_cast< Schedule* >( this )->getWells( wellNamePattern ); - return { tmp.begin(), tmp.end() }; - } + /* @@ -2010,34 +2007,6 @@ namespace Opm { return names; } - std::vector< Well* > Schedule::getWells(const std::string& wellNamePattern, const std::vector& matching_wells) { - // If we arrive here during the handling the body of a ACTIONX keyword - // we can arrive with wellname '?' and a set of matching wells. - if (wellNamePattern == "?") { - std::vector wells; - for (const auto& well_name : matching_wells) - wells.push_back( std::addressof(m_wells.get(well_name) )); - - return wells; - } else { - auto wildcard_pos = wellNamePattern.find("*"); - - if( wildcard_pos != wellNamePattern.length()-1 ) { - if( m_wells.count( wellNamePattern ) == 0 ) return {}; - return { std::addressof( m_wells.get( wellNamePattern ) ) }; - } - - std::vector< Well* > wells; - for( auto& well_pair : this->m_wells ) { - auto& well = well_pair.second; - if( Well::wellNameInWellNamePattern( well.name(), wellNamePattern ) ) { - wells.push_back( std::addressof( well ) ); - } - } - - return wells; - } - } void Schedule::addGroup(const std::string& groupName, size_t timeStep) { const size_t gseqIndex = m_groups.size(); diff --git a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp index dc2727bde..1485762aa 100644 --- a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp @@ -159,13 +159,13 @@ inline void keywordW( SummaryConfig::keyword_list& list, if (keyword.size() && hasValue(keyword)) { for( const std::string& pattern : keyword.getStringData()) { - auto wells = schedule.getWellsMatching( pattern ); + auto well_names = schedule.wellNames( pattern, schedule.size() - 1 ); - if( wells.empty() ) + if( well_names.empty() ) handleMissingWell( parseContext, errors, keyword.name(), pattern ); - for( const auto* well : wells ) - list.push_back( SummaryConfig::keyword_type( keyword.name(), well->name() )); + for( const auto& well_name : well_names) + list.push_back( SummaryConfig::keyword_type( keyword.name(), well_name )); } } else for (const auto* well : schedule.getWells()) @@ -294,16 +294,15 @@ inline void keywordMISC( SummaryConfig::keyword_list& list, const auto& wellitem = record.getItem( 0 ); - const auto wells = wellitem.defaultApplied( 0 ) - ? schedule.getWells() - : schedule.getWellsMatching( wellitem.getTrimmedString( 0 ) ); + const auto well_names = wellitem.defaultApplied( 0 ) + ? schedule.wellNames() + : schedule.wellNames( wellitem.getTrimmedString( 0 ) ); - if( wells.empty() ) + if( well_names.empty() ) handleMissingWell( parseContext, errors, keyword.name(), wellitem.getTrimmedString( 0 ) ); - for( const auto* well : wells ) { - const auto& name = well->name(); - + for(const auto& name : well_names) { + const auto* well = schedule.getWell(name); /* * we don't want to add completions that don't exist, so we iterate * over a well's completions regardless of the desired block is @@ -470,19 +469,21 @@ inline void keywordMISC( SummaryConfig::keyword_list& list, for (const auto& record : keyword) { const auto& wellitem = record.getItem(0); - const auto& wells = wellitem.defaultApplied(0) - ? schedule.getWells() - : schedule.getWellsMatching(wellitem.getTrimmedString(0)); + const auto& well_names = wellitem.defaultApplied(0) + ? schedule.wellNames() + : schedule.wellNames(wellitem.getTrimmedString(0)); - if (wells.empty()) { + if (well_names.empty()) handleMissingWell(parseContext, errors, keyword.name(), wellitem.getTrimmedString(0)); - } // Negative 1 (< 0) if segment ID defaulted. Defaulted // segment number in record implies all segments. const auto segID = record.getItem(1).defaultApplied(0) ? -1 : record.getItem(1).get(0); + std::vector wells; + for (const auto& well_name : well_names) + wells.push_back( schedule.getWell(well_name) ); makeSegmentNodes(last_timestep, segID, keyword, wells, list); } diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index 07563f498..9dff823b7 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -540,27 +540,7 @@ BOOST_AUTO_TEST_CASE(WellsIterator_HasWells_WellsReturned) { BOOST_CHECK_EQUAL(3U, wells_t3.size()); } -BOOST_AUTO_TEST_CASE(WellsIteratorWithRegex_HasWells_WellsReturned) { - EclipseGrid grid(10,10,10); - auto deck = createDeckWithWells(); - TableManager table ( deck ); - Eclipse3DProperties eclipseProperties ( deck , table, grid); - Runspec runspec (deck); - Schedule schedule(deck, grid , eclipseProperties, runspec); - std::string wellNamePattern; - wellNamePattern = "*"; - auto wells = schedule.getWellsMatching(wellNamePattern); - BOOST_CHECK_EQUAL(3U, wells.size()); - - wellNamePattern = "W_*"; - wells = schedule.getWellsMatching(wellNamePattern); - BOOST_CHECK_EQUAL(2U, wells.size()); - - wellNamePattern = "W_3"; - wells = schedule.getWellsMatching(wellNamePattern); - BOOST_CHECK_EQUAL(1U, wells.size()); -} BOOST_AUTO_TEST_CASE(ReturnNumWellsTimestep) { EclipseGrid grid(10,10,10); diff --git a/tests/parser/WellSolventTests.cpp b/tests/parser/WellSolventTests.cpp index d04467637..337e0aa57 100644 --- a/tests/parser/WellSolventTests.cpp +++ b/tests/parser/WellSolventTests.cpp @@ -204,13 +204,13 @@ BOOST_AUTO_TEST_CASE(TestDynamicWSOLVENT) { const auto& keyword = deck.getKeyword("WSOLVENT"); BOOST_CHECK_EQUAL(keyword.size(),1); const auto& record = keyword.getRecord(0); - const std::string& wellNamesPattern = record.getItem("WELL").getTrimmedString(0); - auto wells_solvent = schedule.getWellsMatching(wellNamesPattern); - BOOST_CHECK_EQUAL(wellNamesPattern, "W_1"); - BOOST_CHECK_EQUAL(wells_solvent[0]->getSolventFraction(0),0); //default 0 - BOOST_CHECK_EQUAL(wells_solvent[0]->getSolventFraction(1),1); - BOOST_CHECK_EQUAL(wells_solvent[0]->getSolventFraction(2),1); - BOOST_CHECK_EQUAL(wells_solvent[0]->getSolventFraction(3),0); + const std::string& well_name = record.getItem("WELL").getTrimmedString(0); + BOOST_CHECK_EQUAL(well_name, "W_1"); + const auto* well = schedule.getWell(well_name); + BOOST_CHECK_EQUAL(well->getSolventFraction(0),0); //default 0 + BOOST_CHECK_EQUAL(well->getSolventFraction(1),1); + BOOST_CHECK_EQUAL(well->getSolventFraction(2),1); + BOOST_CHECK_EQUAL(well->getSolventFraction(3),0); } BOOST_AUTO_TEST_CASE(TestOilInjector) { diff --git a/tests/parser/WellTracerTests.cpp b/tests/parser/WellTracerTests.cpp index e0ef9d57b..00dcc4add 100644 --- a/tests/parser/WellTracerTests.cpp +++ b/tests/parser/WellTracerTests.cpp @@ -151,15 +151,15 @@ BOOST_AUTO_TEST_CASE(TestDynamicWTRACER) { const auto& keyword = deck.getKeyword("WTRACER"); BOOST_CHECK_EQUAL(keyword.size(),1); const auto& record = keyword.getRecord(0); - const std::string& wellNamesPattern = record.getItem("WELL").getTrimmedString(0); - auto wells_Tracer = schedule.getWellsMatching(wellNamesPattern); - BOOST_CHECK_EQUAL(wellNamesPattern, "W_1"); - BOOST_CHECK_EQUAL(wells_Tracer[0]->getTracerProperties(0).getConcentration("I1"),0); //default 0 - BOOST_CHECK_EQUAL(wells_Tracer[0]->getTracerProperties(0).getConcentration("I2"),0); //default 0 - BOOST_CHECK_EQUAL(wells_Tracer[0]->getTracerProperties(1).getConcentration("I1"),1); - BOOST_CHECK_EQUAL(wells_Tracer[0]->getTracerProperties(2).getConcentration("I1"),1); - BOOST_CHECK_EQUAL(wells_Tracer[0]->getTracerProperties(4).getConcentration("I1"),0); - BOOST_CHECK_EQUAL(wells_Tracer[0]->getTracerProperties(4).getConcentration("I2"),1); + const std::string& well_name = record.getItem("WELL").getTrimmedString(0); + BOOST_CHECK_EQUAL(well_name, "W_1"); + const auto* well = schedule.getWell(well_name); + BOOST_CHECK_EQUAL(well->getTracerProperties(0).getConcentration("I1"),0); //default 0 + BOOST_CHECK_EQUAL(well->getTracerProperties(0).getConcentration("I2"),0); //default 0 + BOOST_CHECK_EQUAL(well->getTracerProperties(1).getConcentration("I1"),1); + BOOST_CHECK_EQUAL(well->getTracerProperties(2).getConcentration("I1"),1); + BOOST_CHECK_EQUAL(well->getTracerProperties(4).getConcentration("I1"),0); + BOOST_CHECK_EQUAL(well->getTracerProperties(4).getConcentration("I2"),1); }