opm-common
WellProductionControls.hpp
1 /*
2  Copyright 2019 Equinor ASA.
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 
21 #ifndef WELL_PRODUCTION_CONTROLS_HPP
22 #define WELL_PRODUCTION_CONTROLS_HPP
23 
24 #include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
25 #include <opm/input/eclipse/Schedule/Well/WellEnums.hpp>
26 
27 #include <cmath>
28 
29 namespace Opm {
30 
32 public:
33  explicit WellProductionControls(int controls_arg) :
34  controls(controls_arg)
35  {
36  }
37 
38  bool hasControl(WellProducerCMode cmode_arg) const
39  {
40  return (this->controls & static_cast<int>(cmode_arg)) != 0;
41  }
42 
43  void skipControl(WellProducerCMode cmode_arg) {
44  auto int_arg = static_cast<int>(cmode_arg);
45  if ((this->controls & int_arg) != 0)
46  this->controls -= int_arg;
47  }
48 
49  void addControl(WellProducerCMode cmode_arg) {
50  auto int_arg = static_cast<int>(cmode_arg);
51  if ((this->controls & int_arg) == 0)
52  this->controls += int_arg;
53  }
54 
55  void clearControls(){
56  this->controls = 0;
57  }
58 
59  bool anyZeroRateConstraint() const {
60  auto is_zero = [](const double x)
61  {
62  return std::isfinite(x) && !std::isnormal(x);
63  };
64 
65  if (this->hasControl(WellProducerCMode::ORAT) && is_zero(this->oil_rate)) {
66  return true;
67  }
68 
69  if (this->hasControl(WellProducerCMode::WRAT) && is_zero(this->water_rate)) {
70  return true;
71  }
72 
73  if (this->hasControl(WellProducerCMode::GRAT) && is_zero(this->gas_rate)) {
74  return true;
75  }
76 
77  if (this->hasControl(WellProducerCMode::LRAT) && is_zero(this->liquid_rate)) {
78  return true;
79  }
80 
81  if (this->hasControl(WellProducerCMode::RESV)) {
82  // currently, the RESV constraint for a history matching producers will be calculated based on the reservoir condition
83  // at the moment it is used, and we do not have a fixed resv_rate to check against zero. as a result,
84  // we check whether the historic rates for oil, gas and water are all zero to determine whether it is under zero
85  // RESV constraint for history matching producers.
86  const auto zero_rate = this->prediction_mode
87  ? is_zero(this->resv_rate)
88  : is_zero(this->oil_rate) && is_zero(this->water_rate) && is_zero(this->gas_rate);
89 
90  if (zero_rate) {
91  return true;
92  }
93  }
94 
95  return false;
96  }
97 
98  bool operator==(const WellProductionControls& other) const
99  {
100  return this->cmode == other.cmode &&
101  this->oil_rate == other.oil_rate &&
102  this->water_rate == other.water_rate &&
103  this->gas_rate == other.gas_rate &&
104  this->liquid_rate == other.liquid_rate &&
105  this->resv_rate == other.resv_rate &&
106  this->bhp_history == other.bhp_history &&
107  this->thp_history == other.thp_history &&
108  this->bhp_limit == other.bhp_limit &&
109  this->thp_limit == other.thp_limit &&
110  this->alq_value == other.alq_value &&
111  this->vfp_table_number == other.vfp_table_number &&
112  this->prediction_mode == other.prediction_mode;
113  }
114 
115  WellProducerCMode cmode = WellProducerCMode::NONE;
116  double oil_rate{0};
117  double water_rate{0};
118  double gas_rate{0};
119  double liquid_rate{0};
120  double resv_rate{0};
121  double bhp_history{0};
122  double thp_history{0};
123  double bhp_limit{0};
124  double thp_limit{0};
125  double alq_value{0};
126  int vfp_table_number{0};
127  bool prediction_mode{0};
128 
129 private:
130  int controls;
131 };
132 
133 }
134 
135 #endif
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: WellProductionControls.hpp:31