From da85405dfacc62b4ae43c198d540e800a0a6d18d Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Wed, 2 May 2012 15:41:05 +0200 Subject: [PATCH] Removed calculateGuideRates and made all guide rate dependent code calculate the guide rate dynamically --- opm/core/WellCollection.cpp | 7 --- opm/core/WellCollection.hpp | 5 --- opm/core/WellsGroup.cpp | 89 ++++++++++++++++++++++++------------- opm/core/WellsGroup.hpp | 37 +++++++++++---- opm/core/WellsManager.cpp | 1 - 5 files changed, 88 insertions(+), 51 deletions(-) diff --git a/opm/core/WellCollection.cpp b/opm/core/WellCollection.cpp index 9d85663ec..f873c259f 100644 --- a/opm/core/WellCollection.cpp +++ b/opm/core/WellCollection.cpp @@ -108,13 +108,6 @@ namespace Opm } return true; } - - void WellCollection::calculateGuideRates() - { - for(size_t i = 0; i < roots_.size(); i++) { - roots_[i]->calculateGuideRates(); - } - } void WellCollection::setWellsPointer(Wells* wells) { for(size_t i = 0; i < leaf_nodes_.size(); i++) { diff --git a/opm/core/WellCollection.hpp b/opm/core/WellCollection.hpp index 76a19cb8e..a5db76d71 100644 --- a/opm/core/WellCollection.hpp +++ b/opm/core/WellCollection.hpp @@ -75,11 +75,6 @@ namespace Opm /// \return A set of pointers to every well in the collection const std::vector& getLeafNodes() const; - /// This will, for each group \f$G\f$ for each well \f$w\in G\f$ calculate - /// the new guide rate \f$\tilde{g}_w\f$ for each well as - /// \f[ \tilde{g}_w := \frac{g_w}{\sum_{w'\in G} g_{w'}}\f] - void calculateGuideRates(); - /// Finds the group with the given name. /// \param[in] the name of the group /// \return the pointer to the group if found, NULL otherwise diff --git a/opm/core/WellsGroup.cpp b/opm/core/WellsGroup.cpp index bc7c1af42..a04ed7249 100644 --- a/opm/core/WellsGroup.cpp +++ b/opm/core/WellsGroup.cpp @@ -247,22 +247,6 @@ namespace Opm { } - - void WellsGroup::calculateGuideRates() - { - double inj_guide_rate_sum = 0.0; - double prod_guide_rate_sum = 0.0; - for (size_t i = 0; i < children_.size(); i++) { - children_[i]->calculateGuideRates(); - inj_guide_rate_sum += children_[i]->injSpec().guide_rate_; - prod_guide_rate_sum += children_[i]->prodSpec().guide_rate_; - } - injSpec().guide_rate_ = inj_guide_rate_sum; - prodSpec().guide_rate_ = prod_guide_rate_sum; - } - - - /// Sets the current active control to the provided one for all injectors within the group. /// After this call, the combined rate (which rate depending on control_mode) of the group /// shall be equal to target. @@ -272,9 +256,11 @@ namespace Opm const double target, const bool forced) { - if (forced || injSpec().control_mode_ == InjectionSpecification::FLD) { + if (forced || injSpec().control_mode_ == InjectionSpecification::FLD + || injSpec().control_mode_ == InjectionSpecification::NONE) { + const double my_guide_rate = injectionGuideRate(!forced); for (size_t i = 0; i < children_.size(); ++i) { - const double child_target = target * children_[i]->injSpec().guide_rate_ / injSpec().guide_rate_; + const double child_target = target * children_[i]->injectionGuideRate(!forced) / my_guide_rate; children_[i]->applyInjGroupControl(control_mode, child_target, true); } injSpec().control_mode_ = InjectionSpecification::FLD; @@ -290,10 +276,11 @@ namespace Opm const double target, const bool forced) { - if (forced - || (prodSpec().control_mode_ == ProductionSpecification::FLD || prodSpec().control_mode_ == ProductionSpecification::NONE)) { + if (forced || (prodSpec().control_mode_ == ProductionSpecification::FLD + || prodSpec().control_mode_ == ProductionSpecification::NONE)) { + const double my_guide_rate = productionGuideRate(!forced); for (size_t i = 0; i < children_.size(); ++i) { - const double child_target = target * children_[i]->prodSpec().guide_rate_ / prodSpec().guide_rate_; + const double child_target = target * children_[i]->productionGuideRate(!forced) / my_guide_rate; children_[i]->applyProdGroupControl(control_mode, child_target, true); } prodSpec().control_mode_ = ProductionSpecification::FLD; @@ -443,12 +430,12 @@ namespace Opm case ProductionSpecification::LRAT: case ProductionSpecification::RESV: { - const double my_guide_rate = prodSpec().guide_rate_; + const double my_guide_rate = productionGuideRate(true); for (size_t i = 0; i < children_.size(); ++i ) { // Apply for all children. // Note, we do _not_ want to call the applyProdGroupControl in this object, // as that would check if we're under group control, something we're not. - const double children_guide_rate = children_[i]->prodSpec().guide_rate_; + const double children_guide_rate = productionGuideRate(true); children_[i]->applyProdGroupControl(prod_mode, (my_guide_rate / children_guide_rate) * getTarget(prod_mode), false); @@ -474,12 +461,12 @@ namespace Opm case InjectionSpecification::RATE: case InjectionSpecification::RESV: { - const double my_guide_rate = injSpec().guide_rate_; + const double my_guide_rate = injectionGuideRate(true); for (size_t i = 0; i < children_.size(); ++i ) { // Apply for all children. // Note, we do _not_ want to call the applyProdGroupControl in this object, // as that would check if we're under group control, something we're not. - const double children_guide_rate = children_[i]->injSpec().guide_rate_; + const double children_guide_rate = children_[i]->injectionGuideRate(true); children_[i]->applyInjGroupControl(inj_mode, (my_guide_rate / children_guide_rate) * getTarget(inj_mode), false); @@ -497,6 +484,30 @@ namespace Opm THROW("Unhandled group injection control mode " << inj_mode); } } + + /// Calculates the production guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + double WellsGroup::productionGuideRate(bool only_group) + { + double sum = 0.0; + for (size_t i = 0; i < children_.size(); ++i) { + sum += children_[i]->productionGuideRate(only_group); + } + return sum; + } + + /// Calculates the injection guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + double WellsGroup::injectionGuideRate(bool only_group) + { + double sum = 0.0; + for (size_t i = 0; i < children_.size(); ++i) { + sum += children_[i]->injectionGuideRate(only_group); + } + return sum; + } @@ -613,11 +624,6 @@ namespace Opm wells_ = wells; self_index_ = self_index; } - - void WellNode::calculateGuideRates() - { - // Empty - } int WellNode::numberOfLeafNodes() { @@ -788,6 +794,29 @@ namespace Opm // Empty } + /// Calculates the production guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + double WellNode::productionGuideRate(bool only_group) + { + if (only_group || prodSpec().control_mode_ == ProductionSpecification::GRUP) { + return prodSpec().guide_rate_; + } + return 0.0; + } + + /// Calculates the injection guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + double WellNode::injectionGuideRate(bool only_group) + { + if (only_group || injSpec().control_mode_ == InjectionSpecification::GRUP) { + return injSpec().guide_rate_; + } + return 0.0; + } + + namespace { diff --git a/opm/core/WellsGroup.hpp b/opm/core/WellsGroup.hpp index fd0c796b1..6fe5508bc 100644 --- a/opm/core/WellsGroup.hpp +++ b/opm/core/WellsGroup.hpp @@ -89,10 +89,6 @@ namespace Opm /// Gets the parent of the group, NULL if no parent. const WellsGroupInterface* getParent() const; - /// Recursively calculate the guide rate for each member of the well group. - /// This should be called after the guide rates are set to the non-normalized values. - virtual void calculateGuideRates() = 0; - /// Calculates the number of leaf nodes in the given group. /// A leaf node is defined to have one leaf node in its group. virtual int numberOfLeafNodes() = 0; @@ -173,6 +169,16 @@ namespace Opm /// If no group control is set, this is called recursively to the children. virtual void applyInjGroupControls() = 0; + /// Calculates the production guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + virtual double productionGuideRate(bool only_group) = 0; + + /// Calculates the injection guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + virtual double injectionGuideRate(bool only_group) = 0; + protected: /// Calculates the correct rate for the given ProductionSpecification::ControlMode double rateByMode(const double* res_rates, @@ -212,9 +218,6 @@ namespace Opm const std::vector& well_surfacerates_phase, WellPhasesSummed& summed_phases); - - virtual void calculateGuideRates(); - virtual int numberOfLeafNodes(); virtual std::pair getWorstOffending(const std::vector& well_reservoirrates_phase, const std::vector& well_surfacerates_phase, @@ -245,6 +248,16 @@ namespace Opm /// Applies any injection group control relevant to all children nodes. /// If no group control is set, this is called recursively to the children. virtual void applyInjGroupControls(); + + /// Calculates the production guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + virtual double productionGuideRate(bool only_group); + + /// Calculates the injection guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + virtual double injectionGuideRate(bool only_group); private: std::vector > children_; @@ -270,7 +283,6 @@ namespace Opm void setWellsPointer(Wells* wells, int self_index); - virtual void calculateGuideRates(); virtual int numberOfLeafNodes(); // Shuts the well (in the well struct) @@ -306,6 +318,15 @@ namespace Opm /// If no group control is set, this is called recursively to the children. virtual void applyInjGroupControls(); + /// Calculates the production guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + virtual double productionGuideRate(bool only_group); + + /// Calculates the injection guide rate for the group. + /// \param[in] only_group If true, will only accumelate guide rates for + /// wells under group control + virtual double injectionGuideRate(bool only_group); private: Wells* wells_; diff --git a/opm/core/WellsManager.cpp b/opm/core/WellsManager.cpp index 19a0ce51d..806180e7a 100644 --- a/opm/core/WellsManager.cpp +++ b/opm/core/WellsManager.cpp @@ -620,7 +620,6 @@ namespace Opm } } } - well_collection_.calculateGuideRates(); well_collection_.setWellsPointer(w_); well_collection_.applyGroupControls(); }