diff --git a/opm/core/WellCollection.cpp b/opm/core/WellCollection.cpp index 1a4b02681..44ee8c401 100644 --- a/opm/core/WellCollection.cpp +++ b/opm/core/WellCollection.cpp @@ -57,7 +57,7 @@ namespace Opm parent_as_group->addChild(child); if(child->isLeafNode()) { - leaf_nodes_.push_back(child); + leaf_nodes_.push_back(static_cast(child.get())); } child->setParent(parent); @@ -65,7 +65,7 @@ namespace Opm - const std::vector >& WellCollection::getLeafNodes() const { + const std::vector& WellCollection::getLeafNodes() const { return leaf_nodes_; } @@ -100,7 +100,7 @@ namespace Opm double epsilon) const { for (size_t i = 0; i < leaf_nodes_.size(); i++) { - static_cast(leaf_nodes_[i].get())->conditionsMet(well_bhp, well_rate, grid, result, epsilon); + leaf_nodes_[i]->conditionsMet(well_bhp, well_rate, grid, result, epsilon); } } @@ -110,4 +110,10 @@ namespace Opm roots_[i]->calculateGuideRates(); } } + + void WellCollection::setWellsPointer(const Wells* wells) { + for(size_t i = 0; i < leaf_nodes_.size(); i++) { + leaf_nodes_[i]->setWellsPointer(wells, i); + } + } } diff --git a/opm/core/WellCollection.hpp b/opm/core/WellCollection.hpp index 12d964ddd..1f97c0602 100644 --- a/opm/core/WellCollection.hpp +++ b/opm/core/WellCollection.hpp @@ -49,19 +49,22 @@ namespace Opm const UnstructuredGrid& grid, WellControlResult& result, const double epsilon=1e-8) const; + /// Adds the well pointer to each leaf node (does not take ownership). + void setWellsPointer(const Wells* wells); - const std::vector >& getLeafNodes() const; + const std::vector& getLeafNodes() const; void calculateGuideRates(); WellsGroupInterface* findNode(std::string name); const WellsGroupInterface* findNode(std::string name) const; + private: // To account for the possibility of a forest std::vector > roots_; // This will be used to traverse the bottom nodes. - std::vector > leaf_nodes_; + std::vector leaf_nodes_; }; diff --git a/opm/core/WellsManager.cpp b/opm/core/WellsManager.cpp index 00903645c..b0139544b 100644 --- a/opm/core/WellsManager.cpp +++ b/opm/core/WellsManager.cpp @@ -610,12 +610,7 @@ namespace Opm } std::cout << "Made well struct" << std::endl; - // \TODO comment this. - for (size_t i = 0; i < well_collection_.getLeafNodes().size(); i++) { - WellNode* node = static_cast(well_collection_.getLeafNodes()[i].get()); - // We know that getLeafNodes() is ordered the same way as they're indexed in w_ - node->setWellsPointer(w_, i); - } + well_collection_.setWellsPointer(w_); }