diff --git a/opm/core/wells/WellCollection.cpp b/opm/core/wells/WellCollection.cpp index 0cc7a9ce..260c156f 100644 --- a/opm/core/wells/WellCollection.cpp +++ b/opm/core/wells/WellCollection.cpp @@ -35,20 +35,8 @@ namespace Opm parent = roots_[roots_.size() - 1].get(); } - std::shared_ptr child; + std::shared_ptr child = getAndUnRootChild(groupChild->name()); - for (size_t i = 0; i < roots_.size(); ++i) { - if (roots_[i]->name() == groupChild->name()) { - child = roots_[i]; - // We've found a new parent to the previously thought root, need to remove it - for(size_t j = i; j < roots_.size() - 1; ++j) { - roots_[j] = roots_[j+1]; - } - - roots_.resize(roots_.size()-1); - break; - } - } if (!child.get()) { child = createGroupWellsGroup(groupChild, timeStep, phaseUsage); } @@ -74,20 +62,8 @@ namespace Opm parent = roots_[roots_.size() - 1].get(); } - std::shared_ptr child; + std::shared_ptr child = getAndUnRootChild(wellChild->name()); - for (size_t i = 0; i < roots_.size(); ++i) { - if (roots_[i]->name() == wellChild->name()) { - child = roots_[i]; - // We've found a new parent to the previously thought root, need to remove it - for(size_t j = i; j < roots_.size() - 1; ++j) { - roots_[j] = roots_[j+1]; - } - - roots_.resize(roots_.size()-1); - break; - } - } if (!child.get()) { child = createWellWellsGroup(wellChild, timeStep, phaseUsage); } @@ -115,20 +91,9 @@ namespace Opm roots_.push_back(createWellsGroup(parent_name, deck)); parent = roots_[roots_.size() - 1].get(); } - std::shared_ptr child; - for (size_t i = 0; i < roots_.size(); ++i) { - if (roots_[i]->name() == child_name) { - child = roots_[i]; - // We've found a new parent to the previously thought root, need to remove it - for(size_t j = i; j < roots_.size() - 1; ++j) { - roots_[j] = roots_[j+1]; - } + std::shared_ptr child = getAndUnRootChild(child_name); - roots_.resize(roots_.size()-1); - break; - } - } if (!child.get()) { child = createWellsGroup(child_name, deck); } @@ -147,6 +112,23 @@ namespace Opm } + std::shared_ptr WellCollection::getAndUnRootChild(std::string child_name) { + std::shared_ptr child; + + for (size_t i = 0; i < roots_.size(); ++i) { + if (roots_[i]->name() == child_name) { + child = roots_[i]; + // We've found a new parent to the previously thought root, need to remove it + for(size_t j = i; j < roots_.size() - 1; ++j) { + roots_[j] = roots_[j+1]; + } + + roots_.resize(roots_.size()-1); + break; + } + } + return child; + } const std::vector& WellCollection::getLeafNodes() const { return leaf_nodes_; diff --git a/opm/core/wells/WellCollection.hpp b/opm/core/wells/WellCollection.hpp index 8933ff03..e017b50b 100644 --- a/opm/core/wells/WellCollection.hpp +++ b/opm/core/wells/WellCollection.hpp @@ -140,6 +140,7 @@ namespace Opm const std::vector& well_surfacerates_phase); private: + std::shared_ptr getAndUnRootChild(std::string child_name); // To account for the possibility of a forest std::vector > roots_;