Extracted common functionality from the three create functions

This commit is contained in:
Kristian Flikka 2014-02-12 15:45:06 +01:00
parent 36348a8f8a
commit 663eb5a56d
2 changed files with 21 additions and 38 deletions

View File

@ -35,20 +35,8 @@ namespace Opm
parent = roots_[roots_.size() - 1].get();
}
std::shared_ptr<WellsGroupInterface> child;
std::shared_ptr<WellsGroupInterface> 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<WellsGroupInterface> child;
std::shared_ptr<WellsGroupInterface> 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<WellsGroupInterface> 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<WellsGroupInterface> 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<WellsGroupInterface> WellCollection::getAndUnRootChild(std::string child_name) {
std::shared_ptr<WellsGroupInterface> 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<WellNode*>& WellCollection::getLeafNodes() const {
return leaf_nodes_;

View File

@ -140,6 +140,7 @@ namespace Opm
const std::vector<double>& well_surfacerates_phase);
private:
std::shared_ptr<WellsGroupInterface> getAndUnRootChild(std::string child_name);
// To account for the possibility of a forest
std::vector<std::shared_ptr<WellsGroupInterface> > roots_;