All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
WellsGroup.hpp
1 /*
2  Copyright 2012 SINTEF ICT, Applied Mathematics.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_WELLSGROUP_HPP
21 #define OPM_WELLSGROUP_HPP
22 
23 #include <opm/core/wells/InjectionSpecification.hpp>
24 #include <opm/core/wells/ProductionSpecification.hpp>
25 #include <opm/core/grid.h>
26 #include <opm/core/props/BlackoilPhases.hpp>
27 
28 #include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
29 #include <opm/parser/eclipse/EclipseState/Schedule/Group.hpp>
30 
31 #include <string>
32 #include <memory>
33 
34 namespace Opm
35 {
36  // Need to forward declare this one, some of the methods in the base
37  // class returns pointers to it.
38  class WellNode;
39 
43  {
45  double res_inj_rates[3];
46  double res_prod_rates[3];
47  double surf_inj_rates[3];
48  double surf_prod_rates[3];
49 
51  void operator+=(const WellPhasesSummed& other);
52  };
53 
55  {
56  public:
57  WellsGroupInterface(const std::string& name,
58  const double efficiency_factor,
59  const ProductionSpecification& prod_spec,
60  const InjectionSpecification& inj_spec,
61  const PhaseUsage& phase_usage);
62  virtual ~WellsGroupInterface();
63 
65  const std::string& name() const;
66 
68  const ProductionSpecification& prodSpec() const;
69 
71  const InjectionSpecification& injSpec() const;
72 
75 
78 
80  const PhaseUsage& phaseUsage() const;
81 
83  virtual bool isLeafNode() const;
84 
87  virtual WellsGroupInterface* findGroup(const std::string& name_of_node) = 0;
88 
91  void setParent(WellsGroupInterface* parent);
92 
94  const WellsGroupInterface* getParent() const;
95 
97 
100  virtual int numberOfLeafNodes() = 0;
101 
126  virtual bool conditionsMet(const std::vector<double>& well_bhp,
127  const std::vector<double>& well_reservoirrates_phase,
128  const std::vector<double>& well_surfacerates_phase,
129  WellPhasesSummed& summed_phases) = 0;
130 
135  // otherwise, all children will be set under group control
136  virtual void applyInjGroupControl(const InjectionSpecification::ControlMode control_mode,
137  const InjectionSpecification::InjectorType injector_type,
138  const double target,
139  const bool only_group) = 0;
144  // otherwise, all children will be set under group control
145  virtual void applyProdGroupControl(const ProductionSpecification::ControlMode control_mode,
146  const double target,
147  const bool only_group) = 0;
148 
161  virtual std::pair<WellNode*, double> getWorstOffending(const std::vector<double>& well_reservoirrates_phase,
162  const std::vector<double>& well_surfacerates_phase,
163  ProductionSpecification::ControlMode mode) = 0;
164 
166  double getTarget(ProductionSpecification::ControlMode mode) const;
167 
169  double getTarget(InjectionSpecification::ControlMode mode) const;
170 
173  virtual void applyProdGroupControls() = 0;
174 
177  virtual void applyInjGroupControls() = 0;
178 
182  virtual double productionGuideRate(bool only_group) = 0;
183 
187  virtual double injectionGuideRate(bool only_group) = 0;
188 
194  virtual double getTotalProductionFlow(const std::vector<double>& phase_flows,
195  const BlackoilPhases::PhaseIndex phase) const = 0;
196 
206  virtual void applyExplicitReinjectionControls(const std::vector<double>& well_reservoirrates_phase,
207  const std::vector<double>& well_surfacerates_phase) = 0;
208 
210  virtual void applyVREPGroupControls(const std::vector<double>& well_voidage_rates,
211  const std::vector<double>& conversion_coeffs) = 0;
212 
213  virtual void applyVREPGroupControl(const double target,
214  const InjectionSpecification::InjectorType injector_type,
215  const std::vector<double>& well_voidage_rates,
216  const std::vector<double>& conversion_coeffs,
217  const bool only_group) = 0;
218 
219  virtual double getTotalVoidageRate(const std::vector<double>& well_voidage_rates) = 0;
220 
225  bool individualControl() const;
226 
228  void setIndividualControl(const bool);
229 
230  virtual double getProductionRate(const std::vector<double>& well_rates,
231  const ProductionSpecification::ControlMode prod_mode) const = 0;
232 
233  virtual void updateWellProductionTargets(const std::vector<double>& well_rates) = 0;
234 
235  virtual void updateWellInjectionTargets(const std::vector<double>& well_rates) = 0;
236 
237  virtual void setTargetUpdated(const bool flag) = 0;
238 
239  // bascially, for the group or wells under group control
240  // they have the potential to adjust their targets to produce more to match the higher level target
241  virtual bool canProduceMore() const = 0;
242 
243  // checking wether group production target converged
244  // if the group is producing following the target, then it should be considered okay
245  // if the group is not producing following the target, then we should check wether the group
246  // should be able to produce more to match the target.
247  // if the group can not produce more, we also consider the effort to match the group target is
248  // also done and the group target converged while we should give a message
249  virtual bool groupProdTargetConverged(const std::vector<double>& well_rates) const = 0;
250 
251  double efficiencyFactor() const;
252 
253  void setEfficiencyFactor(const double efficiency_factor);
254 
255  protected:
257  double rateByMode(const double* res_rates,
258  const double* surf_rates,
259  const ProductionSpecification::ControlMode mode);
260 
262  double rateByMode(const double* res_rates,
263  const double* surf_rates,
264  const InjectionSpecification::ControlMode mode);
265 
266  WellsGroupInterface* parent_;
267 
268  // Whether well is running under the group control target.
269  // Current only consider one level of control.
270  // So not putting it in the WellsGroupInterface yet.
271  bool individual_control_;
272 
273  // Efficiency factor
274  double efficiency_factor_;
275 
276  private:
277  std::string name_;
278  ProductionSpecification production_specification_;
279  InjectionSpecification injection_specification_;
280  PhaseUsage phase_usage_;
281  };
282 
283 
284 
286  {
287  public:
288  WellsGroup(const std::string& name,
289  const double efficiency_factor,
290  const ProductionSpecification& prod_spec,
291  const InjectionSpecification& inj_spec,
292  const PhaseUsage& phase_usage);
293 
294  virtual WellsGroupInterface* findGroup(const std::string& name_of_node);
295 
296  void addChild(std::shared_ptr<WellsGroupInterface> child);
297 
298  virtual bool conditionsMet(const std::vector<double>& well_bhp,
299  const std::vector<double>& well_reservoirrates_phase,
300  const std::vector<double>& well_surfacerates_phase,
301  WellPhasesSummed& summed_phases);
302 
303  virtual int numberOfLeafNodes();
304  virtual std::pair<WellNode*, double> getWorstOffending(const std::vector<double>& well_reservoirrates_phase,
305  const std::vector<double>& well_surfacerates_phase,
306  ProductionSpecification::ControlMode mode);
307 
312  // otherwise, all children will be set under group control
313  virtual void applyInjGroupControl(const InjectionSpecification::ControlMode control_mode,
314  const InjectionSpecification::InjectorType injector_type,
315  const double target,
316  bool only_group);
317 
322  // otherwise, all children will be set under group control
323  virtual void applyProdGroupControl(const ProductionSpecification::ControlMode control_mode,
324  const double target,
325  bool only_group);
326 
329  virtual void applyProdGroupControls();
330 
333  virtual void applyInjGroupControls();
334 
338  virtual double productionGuideRate(bool only_group);
339 
343  virtual double injectionGuideRate(bool only_group);
344 
350  virtual double getTotalProductionFlow(const std::vector<double>& phase_flows,
351  const BlackoilPhases::PhaseIndex phase) const;
352 
362  virtual void applyExplicitReinjectionControls(const std::vector<double>& well_reservoirrates_phase,
363  const std::vector<double>& well_surfacerates_phase);
364 
366  virtual void applyVREPGroupControls(const std::vector<double>& well_voidage_rates,
367  const std::vector<double>& conversion_coeffs);
368 
369  virtual void applyVREPGroupControl(const double target,
370  const InjectionSpecification::InjectorType injector_type,
371  const std::vector<double>& well_voidage_rates,
372  const std::vector<double>& conversion_coeffs,
373  const bool only_group);
374 
375  virtual double getTotalVoidageRate(const std::vector<double>& well_voidage_rates);
376 
377  virtual void updateWellProductionTargets(const std::vector<double>& well_rates);
378 
379  virtual void updateWellInjectionTargets(const std::vector<double>& well_rates);
380 
381  virtual void setTargetUpdated(const bool flag);
382 
383  virtual double getProductionRate(const std::vector<double>& well_rates,
384  const ProductionSpecification::ControlMode prod_mode) const;
385 
386  virtual bool canProduceMore() const;
387 
388  virtual bool groupProdTargetConverged(const std::vector<double>& well_rates) const;
389 
390  private:
391  std::vector<std::shared_ptr<WellsGroupInterface> > children_;
392  };
393 
394 
395 
397  {
398  public:
399  WellNode(const std::string& name,
400  const double efficiency_factor,
401  const ProductionSpecification& prod_spec,
402  const InjectionSpecification& inj_spec,
403  const PhaseUsage& phase_usage);
404 
405  virtual WellsGroupInterface* findGroup(const std::string& name_of_node);
406  virtual bool conditionsMet(const std::vector<double>& well_bhp,
407  const std::vector<double>& well_reservoirrates_phase,
408  const std::vector<double>& well_surfacerates_phase,
409  WellPhasesSummed& summed_phases);
410 
411  virtual bool isLeafNode() const;
412 
413  void setWellsPointer(Wells* wells, int self_index);
414 
415  virtual int numberOfLeafNodes();
416 
417  // Shuts the well (in the well struct)
418  void shutWell();
419 
420  virtual std::pair<WellNode*, double> getWorstOffending(const std::vector<double>& well_reservoirrates_phase,
421  const std::vector<double>& well_surfacerates_phase,
422  ProductionSpecification::ControlMode mode);
423 
429  virtual void applyInjGroupControl(const InjectionSpecification::ControlMode control_mode,
430  const InjectionSpecification::InjectorType injector_type,
431  const double target,
432  bool only_group);
433 
439  virtual void applyProdGroupControl(const ProductionSpecification::ControlMode control_mode,
440  const double target,
441  bool only_group);
442 
445  virtual void applyProdGroupControls();
446 
449  virtual void applyInjGroupControls();
450 
454  virtual double productionGuideRate(bool only_group);
455 
459  virtual double injectionGuideRate(bool only_group);
460 
466  virtual double getTotalProductionFlow(const std::vector<double>& phase_flows,
467  const BlackoilPhases::PhaseIndex phase) const;
468 
470  WellType type() const;
471 
481  virtual void applyExplicitReinjectionControls(const std::vector<double>& well_reservoirrates_phase,
482  const std::vector<double>& well_surfacerates_phase);
483 
485  virtual void applyVREPGroupControls(const std::vector<double>& well_voidage_rates,
486  const std::vector<double>& conversion_coeffs);
487 
488  virtual void applyVREPGroupControl(const double target,
489  const InjectionSpecification::InjectorType injector_type,
490  const std::vector<double>& well_voidage_rates,
491  const std::vector<double>& conversion_coeffs,
492  const bool only_group);
493 
494  virtual double getTotalVoidageRate(const std::vector<double>& well_voidage_rates);
495 
496  int groupControlIndex() const;
497 
498  virtual double getProductionRate(const std::vector<double>& well_rates,
499  const ProductionSpecification::ControlMode prod_mode) const;
500 
501  virtual void updateWellProductionTargets(const std::vector<double>& well_rates);
502 
503  virtual void updateWellInjectionTargets(const std::vector<double>& well_rates);
504 
507  double getAccumulativeEfficiencyFactor() const;
508 
509  bool isProducer() const;
510 
511  bool isInjector() const;
512 
513  int selfIndex() const;
514 
515  bool targetUpdated() const;
516 
517  bool isGuideRateWellPotential() const;
518 
519  void setIsGuideRateWellPotential(const bool flag);
520 
521  virtual void setTargetUpdated(const bool flag);
522 
523  virtual bool canProduceMore() const;
524 
525  virtual bool groupProdTargetConverged(const std::vector<double>& well_rates) const;
526 
527  private:
528  Wells* wells_;
529  int self_index_;
530  int group_control_index_;
531  bool shut_well_;
532  // TODO: used when updating well targets
533  bool target_updated_;
534  // whether the guide rate is specified with well potential
535  // TODO: we have never handle the guide rates for groups, maybe this
536  // is something will go to WellsGroupInterface later
537  bool is_guiderate_wellpotential_;
538  };
539 
544  std::shared_ptr<WellsGroupInterface> createWellWellsGroup(const Well* well, size_t timeStep,
545  const PhaseUsage& phase_usage );
546 
551  std::shared_ptr<WellsGroupInterface> createGroupWellsGroup(const Group& group, size_t timeStep,
552  const PhaseUsage& phase_usage );
553 }
554 
555 #endif /* OPM_WELLSGROUP_HPP */
556 
virtual void applyProdGroupControl(const ProductionSpecification::ControlMode control_mode, const double target, bool only_group)
Sets the current active control to the provided one for all producers within the group.
Definition: WellsGroup.cpp:326
const ProductionSpecification & prodSpec() const
Production specifications for the well or well group.
Definition: WellsGroup.cpp:112
virtual bool conditionsMet(const std::vector< double > &well_bhp, const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase, WellPhasesSummed &summed_phases)
Checks if each condition is met, applies well controls where needed (that is, it either changes the a...
Definition: WellsGroup.cpp:348
virtual bool isLeafNode() const
Definition: WellsGroup.cpp:102
virtual double productionGuideRate(bool only_group)=0
Calculates the production guide rate for the group.
virtual int numberOfLeafNodes()=0
Calculates the number of leaf nodes in the given group.
virtual WellsGroupInterface * findGroup(const std::string &name_of_node)=0
virtual int numberOfLeafNodes()
Calculates the number of leaf nodes in the given group.
Definition: WellsGroup.cpp:457
WellType type() const
Returns the type of the well.
Definition: WellsGroup.cpp:1181
void operator+=(const WellPhasesSummed &other)
Sums each component.
Definition: WellsGroup.cpp:50
const InjectionSpecification & injSpec() const
Injection specifications for the well or well group.
Definition: WellsGroup.cpp:119
Definition: WellsGroup.hpp:396
virtual void applyInjGroupControls()
Applies any injection group control relevant to all children nodes.
Definition: WellsGroup.cpp:1377
virtual std::pair< WellNode *, double > getWorstOffending(const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase, ProductionSpecification::ControlMode mode)
Gets the worst offending well based on the input.
Definition: WellsGroup.cpp:469
virtual double injectionGuideRate(bool only_group)
Calculates the injection guide rate for the group.
Definition: WellsGroup.cpp:1400
double getAccumulativeEfficiencyFactor() const
the efficiency factor for groups are muliplitive, this function return the resulted final efficiency ...
Definition: WellsGroup.cpp:1624
bool individualControl() const
Return whether the well is running under group control target or under their own limit.
Definition: WellsGroup.cpp:240
int groupControlIndex() const
Returning the group control index.
Definition: WellsGroup.cpp:1412
virtual void applyInjGroupControls()=0
Applies any injection group control relevant to all children nodes.
virtual double productionGuideRate(bool only_group)
Calculates the production guide rate for the group.
Definition: WellsGroup.cpp:561
const WellsGroupInterface * getParent() const
Gets the parent of the group, NULL if no parent.
Definition: WellsGroup.cpp:82
virtual bool conditionsMet(const std::vector< double > &well_bhp, const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase, WellPhasesSummed &summed_phases)
Checks if each condition is met, applies well controls where needed (that is, it either changes the a...
Definition: WellsGroup.cpp:929
virtual void applyExplicitReinjectionControls(const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase)
Applies explicit reinjection controls.
Definition: WellsGroup.cpp:623
Definition: ProductionSpecification.hpp:10
virtual void applyProdGroupControl(const ProductionSpecification::ControlMode control_mode, const double target, const bool only_group)=0
Sets the current active control to the provided one for all producers within the group.
virtual bool isLeafNode() const
Definition: WellsGroup.cpp:1025
virtual void applyProdGroupControl(const ProductionSpecification::ControlMode control_mode, const double target, bool only_group)
Sets the current active control to the provided one for all producers within the group.
Definition: WellsGroup.cpp:1291
Data structure aggregating static information about all wells in a scenario.
Definition: wells.h:50
Definition: WellsGroup.hpp:54
virtual void applyVREPGroupControls(const std::vector< double > &well_voidage_rates, const std::vector< double > &conversion_coeffs)
TODO: prototyping a VREP enforcement function.
Definition: WellsGroup.cpp:1201
virtual void applyInjGroupControl(const InjectionSpecification::ControlMode control_mode, const InjectionSpecification::InjectorType injector_type, const double target, const bool only_group)=0
Sets the current active control to the provided one for all injectors within the group.
virtual void applyVREPGroupControls(const std::vector< double > &well_voidage_rates, const std::vector< double > &conversion_coeffs)
TODO: prototyping a VREP enforcement function.
Definition: WellsGroup.cpp:687
bool isInjector() const
Returing whether the well is a injector.
Definition: WellsGroup.cpp:1425
virtual void applyInjGroupControl(const InjectionSpecification::ControlMode control_mode, const InjectionSpecification::InjectorType injector_type, const double target, bool only_group)
Sets the current active control to the provided one for all injectors within the group.
Definition: WellsGroup.cpp:297
Basic information needed for group control (each group should typically not exceed the sum of its lea...
Definition: WellsGroup.hpp:42
virtual void applyExplicitReinjectionControls(const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase)=0
Applies explicit reinjection controls.
Definition: WellsGroup.hpp:285
virtual WellsGroupInterface * findGroup(const std::string &name_of_node)
Definition: WellsGroup.cpp:265
virtual void applyVREPGroupControls(const std::vector< double > &well_voidage_rates, const std::vector< double > &conversion_coeffs)=0
TODO: prototyping a VREP enforcement function.
virtual WellsGroupInterface * findGroup(const std::string &name_of_node)
Definition: WellsGroup.cpp:1015
virtual void applyInjGroupControl(const InjectionSpecification::ControlMode control_mode, const InjectionSpecification::InjectorType injector_type, const double target, bool only_group)
Sets the current active control to the provided one for all injectors within the group.
Definition: WellsGroup.cpp:1082
virtual double injectionGuideRate(bool only_group)=0
Calculates the injection guide rate for the group.
WellType
Well type indicates desired/expected well behaviour.
Definition: wells.h:41
virtual double productionGuideRate(bool only_group)
Calculates the production guide rate for the group.
Definition: WellsGroup.cpp:1385
virtual void applyExplicitReinjectionControls(const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase)
Applies explicit reinjection controls.
Definition: WellsGroup.cpp:1194
virtual std::pair< WellNode *, double > getWorstOffending(const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase, ProductionSpecification::ControlMode mode)
Gets the worst offending well based on the input.
Definition: WellsGroup.cpp:1070
bool isProducer() const
Returing whether the well is a producer.
Definition: WellsGroup.cpp:1419
void setParent(WellsGroupInterface *parent)
Sets the parent.
Definition: WellsGroup.cpp:107
Definition: BlackoilPhases.hpp:36
virtual void applyProdGroupControls()
Applies any production group control relevant to all children nodes.
Definition: WellsGroup.cpp:485
virtual double getTotalProductionFlow(const std::vector< double > &phase_flows, const BlackoilPhases::PhaseIndex phase) const =0
Gets the total production flow of the given phase.
virtual bool conditionsMet(const std::vector< double > &well_bhp, const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase, WellPhasesSummed &summed_phases)=0
Checks if each condition is met, applies well controls where needed (that is, it either changes the a...
Definition: InjectionSpecification.hpp:10
virtual double injectionGuideRate(bool only_group)
Calculates the injection guide rate for the group.
Definition: WellsGroup.cpp:579
double getTarget(ProductionSpecification::ControlMode mode) const
Gets the target rate for the given mode.
Definition: WellsGroup.cpp:189
virtual std::pair< WellNode *, double > getWorstOffending(const std::vector< double > &well_reservoirrates_phase, const std::vector< double > &well_surfacerates_phase, ProductionSpecification::ControlMode mode)=0
Gets the worst offending well based on the input.
virtual int numberOfLeafNodes()
Calculates the number of leaf nodes in the given group.
Definition: WellsGroup.cpp:1036
virtual void applyProdGroupControls()=0
Applies any production group control relevant to all children nodes.
virtual void applyInjGroupControls()
Applies any injection group control relevant to all children nodes.
Definition: WellsGroup.cpp:522
const PhaseUsage & phaseUsage() const
Phase usage information.
Definition: WellsGroup.cpp:97
virtual void applyProdGroupControls()
Applies any production group control relevant to all children nodes.
Definition: WellsGroup.cpp:1372
virtual double getTotalProductionFlow(const std::vector< double > &phase_flows, const BlackoilPhases::PhaseIndex phase) const
Gets the total production flow of the given phase.
Definition: WellsGroup.cpp:594
void setIndividualControl(const bool)
Update the status for individual contrl.
Definition: WellsGroup.cpp:245
const std::string & name() const
The unique identifier for the well or well group.
Definition: WellsGroup.cpp:92
virtual double getTotalProductionFlow(const std::vector< double > &phase_flows, const BlackoilPhases::PhaseIndex phase) const
Gets the total production flow of the given phase.
Definition: WellsGroup.cpp:1163
double rateByMode(const double *res_rates, const double *surf_rates, const ProductionSpecification::ControlMode mode)
Calculates the correct rate for the given ProductionSpecification::ControlMode.
Definition: WellsGroup.cpp:139