From 478ac16a1b8ba06b570d63c3d22f1c23c3671044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Mon, 7 Nov 2016 14:37:00 +0100 Subject: [PATCH] GroupTree interface changed upstream Updates to the slightly modified GroupTree interface from opm-parser. --- opm/core/wells/WellsManager.cpp | 9 --------- opm/core/wells/WellsManager.hpp | 1 - opm/core/wells/WellsManager_impl.hpp | 22 ++++++++++++++++------ tests/test_wellcollection.cpp | 25 +++---------------------- tests/test_wellsgroup.cpp | 8 +++++--- 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 746a6ec2b..ff5c3088c 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -729,15 +729,6 @@ namespace Opm } - void WellsManager::addChildGroups(const GroupTreeNode& parentNode, const Schedule& schedule, size_t timeStep, const PhaseUsage& phaseUsage) { - for (auto childIter = parentNode.begin(); childIter != parentNode.end(); ++childIter) { - const auto& childNode = (*childIter).second; - well_collection_.addGroup(schedule.getGroup(childNode->name()), parentNode.name(), timeStep, phaseUsage); - addChildGroups(*childNode, schedule, timeStep, phaseUsage); - } - } - - void WellsManager::setupGuideRates(std::vector< const Well* >& wells, const size_t timeStep, std::vector& well_data, std::map& well_names_to_index, const PhaseUsage& phaseUsage, const std::vector& well_potentials) { diff --git a/opm/core/wells/WellsManager.hpp b/opm/core/wells/WellsManager.hpp index 4db577c44..35b65585b 100644 --- a/opm/core/wells/WellsManager.hpp +++ b/opm/core/wells/WellsManager.hpp @@ -193,7 +193,6 @@ namespace Opm const std::unordered_set& deactivated_wells, const DynamicListEconLimited& list_econ_limited); - void addChildGroups(const GroupTreeNode& parentNode, const Schedule& schedule, size_t timeStep, const PhaseUsage& phaseUsage); void setupGuideRates(std::vector& wells, const size_t timeStep, std::vector& well_data, std::map& well_names_to_index, const PhaseUsage& phaseUsage, const std::vector& well_potentials); // Data diff --git a/opm/core/wells/WellsManager_impl.hpp b/opm/core/wells/WellsManager_impl.hpp index b6fd9e2c0..31245f535 100644 --- a/opm/core/wells/WellsManager_impl.hpp +++ b/opm/core/wells/WellsManager_impl.hpp @@ -404,13 +404,23 @@ WellsManager::init(const Opm::EclipseState& eclipseState, setupWellControls(wells, timeStep, well_names, pu, wells_on_proc, list_econ_limited); { - const auto& fieldNode = - schedule.getGroupTree(timeStep).getNode("FIELD"); - - const auto& fieldGroup = schedule.getGroup(fieldNode->name()); - + const auto& fieldGroup = schedule.getGroup( "FIELD" ); well_collection_.addField(fieldGroup, timeStep, pu); - addChildGroups(*fieldNode, schedule, timeStep, pu); + + const auto& grouptree = schedule.getGroupTree( timeStep ); + std::vector< std::string > group_stack = { "FIELD" }; + + do { + auto parent = group_stack.back(); + group_stack.pop_back(); + const auto& children = grouptree.children( parent ); + group_stack.insert( group_stack.end(), children.begin(), children.end() ); + + for( const auto& child : children ) { + well_collection_.addGroup( schedule.getGroup( child ), parent, timeStep, pu ); + } + + } while( !group_stack.empty() ); } for (auto w = wells.begin(), e = wells.end(); w != e; ++w) { diff --git a/tests/test_wellcollection.cpp b/tests/test_wellcollection.cpp index 77f30db8a..d1097bf2c 100644 --- a/tests/test_wellcollection.cpp +++ b/tests/test_wellcollection.cpp @@ -47,33 +47,14 @@ BOOST_AUTO_TEST_CASE(AddWellsAndGroupToCollection) { EclipseState eclipseState(deck, parseContext); PhaseUsage pu = phaseUsageFromDeck(eclipseState); - const auto& field=eclipseState.getSchedule().getGroupTree(2).getNode("FIELD"); - const auto& g1=eclipseState.getSchedule().getGroupTree(2).getNode("G1"); - const auto& g2=eclipseState.getSchedule().getGroupTree(2).getNode("G2"); - WellCollection collection; // Add groups to WellCollection - const auto& fieldGroup = eclipseState.getSchedule().getGroup(field->name()); + const auto& fieldGroup = eclipseState.getSchedule().getGroup("FIELD"); collection.addField(fieldGroup, 2, pu); - for (auto iter = field->begin(); iter != field->end(); ++iter) { - const auto& childGroupNode = eclipseState.getSchedule().getGroup((*iter).second->name()); - collection.addGroup(childGroupNode, fieldGroup.name(), 2, pu); - } - - const auto& g1Group = eclipseState.getSchedule().getGroup(g1->name()); - for (auto iter = g1->begin(); iter != g1->end(); ++iter) { - const auto& childGroupNode = eclipseState.getSchedule().getGroup((*iter).second->name()); - collection.addGroup(childGroupNode, g1Group.name(), 2, pu); - } - - - const auto& g2Group = eclipseState.getSchedule().getGroup(g2->name()); - for (auto iter = g2->begin(); iter != g2->end(); ++iter) { - const auto& childGroupNode = eclipseState.getSchedule().getGroup((*iter).second->name()); - collection.addGroup(childGroupNode, g2Group.name(), 2, pu); - } + collection.addGroup( eclipseState.getSchedule().getGroup( "G1" ), fieldGroup.name(), 2, pu); + collection.addGroup( eclipseState.getSchedule().getGroup( "G2" ), fieldGroup.name(), 2, pu); BOOST_CHECK_EQUAL("FIELD", collection.findNode("FIELD")->name()); BOOST_CHECK_EQUAL("FIELD", collection.findNode("G1")->getParent()->name()); diff --git a/tests/test_wellsgroup.cpp b/tests/test_wellsgroup.cpp index a9ce0b023..c645c5a04 100644 --- a/tests/test_wellsgroup.cpp +++ b/tests/test_wellsgroup.cpp @@ -88,10 +88,12 @@ BOOST_AUTO_TEST_CASE(ConstructGroupFromGroup) { EclipseState eclipseState(deck , parseContext); PhaseUsage pu = phaseUsageFromDeck(eclipseState); - auto nodes = eclipseState.getSchedule().getGroupTree(2).getNodes(); + const auto& nodes = eclipseState.getSchedule().getGroupTree(2); + + for( const auto& grp : eclipseState.getSchedule().getGroups() ) { + if( !nodes.exists( grp->name() ) ) continue; + const auto& group = *grp; - for (size_t i=0; iname()); std::shared_ptr wellsGroup = createGroupWellsGroup(group, 2, pu); BOOST_CHECK_EQUAL(group.name(), wellsGroup->name()); if (group.isInjectionGroup(2)) {