diff --git a/opm/parser/eclipse/EclipseState/Schedule/Group.cpp b/opm/parser/eclipse/EclipseState/Schedule/Group.cpp index 321855be7..bdaebcce4 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Group.cpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Group.cpp @@ -280,7 +280,7 @@ namespace Opm { } - void Group::delWell(size_t time_step , const std::string& wellName) { + void Group::delWell(size_t time_step, const std::string& wellName) { WellSetConstPtr wellSet = wellMap(time_step); WellSetPtr newWellSet = WellSetPtr( wellSet->shallowCopy() ); diff --git a/opm/parser/eclipse/EclipseState/Schedule/Group.hpp b/opm/parser/eclipse/EclipseState/Schedule/Group.hpp index bf9b46c10..275a28d8e 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Group.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Group.hpp @@ -90,7 +90,7 @@ namespace Opm { WellConstPtr getWell(const std::string& wellName , size_t time_step) const; size_t numWells(size_t time_step); void addWell(size_t time_step , WellPtr well); - void delWell(size_t time_step , const std::string& wellName); + void delWell(size_t time_step, const std::string& wellName ); private: WellSetConstPtr wellMap(size_t time_step) const; diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 7e6a71dfe..e8c949b6c 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -135,10 +135,9 @@ namespace Opm { if (!hasWell(wellName)) { addWell(wellName , currentStep); } - WellPtr well = getWell(wellName); + addWellToGroup( getGroup(groupName) , getWell(wellName) , currentStep); needNewTree = handleGroupFromWELSPECS(record->getItem(1)->getString(0), newTree); - } if (needNewTree) { m_rootGroupTree->add(currentStep, newTree); @@ -312,6 +311,15 @@ namespace Opm { throw std::invalid_argument("Group: " + groupName + " does not exist"); } + void Schedule::addWellToGroup( GroupPtr newGroup , WellPtr well , size_t timeStep) { + const std::string currentGroupName = well->getGroupName(timeStep); + if (currentGroupName != "") { + GroupPtr currentGroup = getGroup( currentGroupName ); + currentGroup->delWell( timeStep , well->name()); + } + well->setGroupName(timeStep , newGroup->name()); + newGroup->addWell(timeStep , well); + } } diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 4bdd367ae..793a2c69c 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -56,6 +56,7 @@ namespace Opm std::map m_groups; boost::shared_ptr > m_rootGroupTree; + void addWellToGroup( GroupPtr newGroup , WellPtr well , size_t timeStep); void initFromDeck(DeckConstPtr deck); void createTimeMap(DeckConstPtr deck); void initRootGroupTreeNode(TimeMapConstPtr timeMap); diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well.cpp b/opm/parser/eclipse/EclipseState/Schedule/Well.cpp index c8cd979fd..3e261a60a 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well.cpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well.cpp @@ -147,7 +147,7 @@ namespace Opm { } - void Well::setGroupName(size_t time_step , const std::string& groupName) { + void Well::setGroupName(size_t time_step, const std::string& groupName ) { m_groupName->add(time_step , groupName); } diff --git a/opm/parser/eclipse/IntegrationTests/ScheduleCreateFromDeck.cpp b/opm/parser/eclipse/IntegrationTests/ScheduleCreateFromDeck.cpp index 97a25e3f0..04d18954a 100644 --- a/opm/parser/eclipse/IntegrationTests/ScheduleCreateFromDeck.cpp +++ b/opm/parser/eclipse/IntegrationTests/ScheduleCreateFromDeck.cpp @@ -286,3 +286,30 @@ BOOST_AUTO_TEST_CASE( WellTestGroups ) { } + +BOOST_AUTO_TEST_CASE( WellTestGroupAndWellRelation ) { + ParserPtr parser(new Parser()); + boost::filesystem::path scheduleFile("testdata/integration_tests/SCHEDULE/SCHEDULE_WELLS_AND_GROUPS"); + DeckPtr deck = parser->parse(scheduleFile.string()); + ScheduleConstPtr sched( new Schedule(deck)); + + GroupPtr group1 = sched->getGroup("GROUP1"); + GroupPtr group2 = sched->getGroup("GROUP2"); + + BOOST_CHECK( group1->hasBeenDefined(0) ); + BOOST_CHECK_EQUAL(false , group2->hasBeenDefined(0)); + BOOST_CHECK( group2->hasBeenDefined(1)); + + BOOST_CHECK_EQUAL( true , group1->hasWell("W_1" , 0)); + BOOST_CHECK_EQUAL( true , group1->hasWell("W_2" , 0)); + BOOST_CHECK_EQUAL( false, group2->hasWell("W_1" , 0)); + BOOST_CHECK_EQUAL( false, group2->hasWell("W_2" , 0)); + + + + BOOST_CHECK_EQUAL( true , group1->hasWell("W_1" , 1)); + BOOST_CHECK_EQUAL( false , group1->hasWell("W_2" , 1)); + BOOST_CHECK_EQUAL( false , group2->hasWell("W_1" , 1)); + BOOST_CHECK_EQUAL( true , group2->hasWell("W_2" , 1)); +} + diff --git a/testdata/integration_tests/SCHEDULE/SCHEDULE_WELLS_AND_GROUPS b/testdata/integration_tests/SCHEDULE/SCHEDULE_WELLS_AND_GROUPS new file mode 100644 index 000000000..599a5125a --- /dev/null +++ b/testdata/integration_tests/SCHEDULE/SCHEDULE_WELLS_AND_GROUPS @@ -0,0 +1,19 @@ +START +10 MAI 2007 / + + +SCHEDULE + +WELSPECS + 'W_1' 'GROUP1' 30 37 1* 'OIL' 7* / + 'W_2' 'GROUP1' 20 51 1* 'OIL' 7* / +/ + +TSTEP + 10 / + + + +WELSPECS + 'W_2' 'GROUP2' 30 37 1* 'OIL' 7* / +/