diff --git a/opm/core/wells/WellCollection.cpp b/opm/core/wells/WellCollection.cpp index 260c156fd..d40497c97 100644 --- a/opm/core/wells/WellCollection.cpp +++ b/opm/core/wells/WellCollection.cpp @@ -27,56 +27,52 @@ namespace Opm { - void WellCollection::addChild(GroupConstPtr groupChild, GroupConstPtr groupParent, + void WellCollection::addField(GroupConstPtr fieldGroup, size_t timeStep, const PhaseUsage& phaseUsage) { + WellsGroupInterface* fieldNode = findNode(fieldGroup->name()); + if (fieldNode) { + OPM_THROW(std::runtime_error, "Trying to add FIELD node, but this already exists. Can only have one FIELD node."); + } + + roots_.push_back(createGroupWellsGroup(fieldGroup, timeStep, phaseUsage)); + } + + void WellCollection::addGroup(GroupConstPtr groupChild, std::string parent_name, size_t timeStep, const PhaseUsage& phaseUsage) { - WellsGroupInterface* parent = findNode(groupParent->name()); + WellsGroupInterface* parent = findNode(parent_name); if (!parent) { - roots_.push_back(createGroupWellsGroup(groupParent, timeStep, phaseUsage)); - parent = roots_[roots_.size() - 1].get(); + OPM_THROW(std::runtime_error, "Trying to add child to group named " << parent_name << ", but this does not exist in the WellCollection."); } - std::shared_ptr child = getAndUnRootChild(groupChild->name()); + if (findNode(groupChild->name())) { + OPM_THROW(std::runtime_error, "Trying to add child named " << groupChild->name() << ", but this group is already in the WellCollection."); - if (!child.get()) { - child = createGroupWellsGroup(groupChild, timeStep, phaseUsage); } + std::shared_ptr child = createGroupWellsGroup(groupChild, timeStep, phaseUsage); + WellsGroup* parent_as_group = static_cast (parent); if (!parent_as_group) { - OPM_THROW(std::runtime_error, "Trying to add child to group named " << groupParent->name() << ", but it's not a group."); + OPM_THROW(std::runtime_error, "Trying to add child to group named " << parent->name() << ", but it's not a group."); } parent_as_group->addChild(child); - - if(child->isLeafNode()) { - leaf_nodes_.push_back(static_cast(child.get())); - } - child->setParent(parent); } - void WellCollection::addChild(WellConstPtr wellChild, GroupConstPtr groupParent, - size_t timeStep, const PhaseUsage& phaseUsage) { - WellsGroupInterface* parent = findNode(groupParent->name()); + void WellCollection::addWell(WellConstPtr wellChild, size_t timeStep, const PhaseUsage& phaseUsage) { + WellsGroupInterface* parent = findNode(wellChild->getGroupName(timeStep)); if (!parent) { - roots_.push_back(createGroupWellsGroup(groupParent, timeStep, phaseUsage)); - parent = roots_[roots_.size() - 1].get(); + OPM_THROW(std::runtime_error, "Trying to add child to group named " << wellChild->getGroupName(timeStep) << ", but this group does not exist in the WellCollection."); } - std::shared_ptr child = getAndUnRootChild(wellChild->name()); - - if (!child.get()) { - child = createWellWellsGroup(wellChild, timeStep, phaseUsage); - } + std::shared_ptr child = createWellWellsGroup(wellChild, timeStep, phaseUsage); WellsGroup* parent_as_group = static_cast (parent); if (!parent_as_group) { - OPM_THROW(std::runtime_error, "Trying to add child to group named " << groupParent->name() << ", but it's not a group."); + OPM_THROW(std::runtime_error, "Trying to add child to group named " << wellChild->getGroupName(timeStep) << ", but it's not a group."); } parent_as_group->addChild(child); - if(child->isLeafNode()) { - leaf_nodes_.push_back(static_cast(child.get())); - } + leaf_nodes_.push_back(static_cast(child.get())); child->setParent(parent); } diff --git a/opm/core/wells/WellCollection.hpp b/opm/core/wells/WellCollection.hpp index e017b50b3..a0e36562e 100644 --- a/opm/core/wells/WellCollection.hpp +++ b/opm/core/wells/WellCollection.hpp @@ -40,28 +40,13 @@ namespace Opm { public: - /// Adds and creates if necessary the child to the collection - /// and appends it to parent's children. Also adds and creates the parent - /// if necessary. - /// \param[in] wellChild the child well - /// \param[in] groupParent the parent group - /// \param[in] phaseUsage the phase usage - /// \param[in] timeStep the current time step - void addChild(WellConstPtr wellChild, GroupConstPtr groupParent, + void addField(GroupConstPtr fieldGroup, size_t timeStep, const PhaseUsage& phaseUsage); + + void addWell(WellConstPtr wellChild, size_t timeStep, const PhaseUsage& phaseUsage); + + void addGroup(GroupConstPtr groupChild, std::string parent_name, size_t timeStep, const PhaseUsage& phaseUsage); - - /// Adds and creates if necessary the child to the collection - /// and appends it to parent's children. Also adds and creates the parent - /// if necessary. - /// \param[in] groupChild the child group - /// \param[in] groupParent the parent group - /// \param[in] phaseUsage the phase usage - /// \param[in] timeStep the current time step - void addChild(GroupConstPtr groupChild, GroupConstPtr groupParent, - size_t timeStep, const PhaseUsage& phaseUsage); - - /// Adds and creates if necessary the child to the collection /// and appends it to parent's children. Also adds and creates the parent /// if necessary. diff --git a/tests/test_wellcollection.cpp b/tests/test_wellcollection.cpp index 0c12af446..d22ba3b4b 100644 --- a/tests/test_wellcollection.cpp +++ b/tests/test_wellcollection.cpp @@ -52,22 +52,24 @@ BOOST_AUTO_TEST_CASE(AddWellsAndGroupToCollection) { // Add groups to WellCollection GroupConstPtr fieldGroup = eclipseState->getSchedule()->getGroup(field->name()); + collection.addField(fieldGroup, 2, pu); + for (auto iter = field->begin(); iter != field->end(); ++iter) { GroupConstPtr childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); - collection.addChild(childGroupNode, fieldGroup, 2, pu); + collection.addGroup(childGroupNode, fieldGroup->name(), 2, pu); } GroupConstPtr g1Group = eclipseState->getSchedule()->getGroup(g1->name()); for (auto iter = g1->begin(); iter != g1->end(); ++iter) { GroupConstPtr childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); - collection.addChild(childGroupNode, g1Group, 2, pu); + collection.addGroup(childGroupNode, g1Group->name(), 2, pu); } GroupConstPtr g2Group = eclipseState->getSchedule()->getGroup(g2->name()); for (auto iter = g2->begin(); iter != g2->end(); ++iter) { GroupConstPtr childGroupNode = eclipseState->getSchedule()->getGroup((*iter).second->name()); - collection.addChild(childGroupNode, g2Group, 2, pu); + collection.addGroup(childGroupNode, g2Group->name(), 2, pu); } BOOST_CHECK_EQUAL("FIELD", collection.findNode("FIELD")->name()); @@ -78,8 +80,7 @@ BOOST_AUTO_TEST_CASE(AddWellsAndGroupToCollection) { WellCollection wellCollection; std::vector wells = eclipseState->getSchedule()->getWells(); for (size_t i=0; igetSchedule()->getGroup(wells[i]->getGroupName(2)); - collection.addChild(wells[i], parentGroup, 2, pu); + collection.addWell(wells[i], 2, pu); } BOOST_CHECK_EQUAL("G1", collection.findNode("INJ1")->getParent()->name()); diff --git a/tests/wells_group.data b/tests/wells_group.data index 753d6031e..5d2e58cb2 100755 --- a/tests/wells_group.data +++ b/tests/wells_group.data @@ -42,6 +42,13 @@ WELSPECS 'PROD2' 'G2' 10 10 8400 'OIL' / / +GCONINJE +'G1' GAS RATE 30000 / +/ + +GCONPROD +'G2' ORAT 10000 / +/ WCONINJE 'INJ1' 'WATER' 'OPEN' 'RESV' 10 20 40 /