My Project
GuideRate.hpp
1 /*
2  Copyright 2019, 2020 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 #ifndef GUIDE_RATE_HPP
21 #define GUIDE_RATE_HPP
22 
23 #include <opm/input/eclipse/Schedule/Group/Group.hpp>
24 #include <opm/input/eclipse/Schedule/Group/GuideRateModel.hpp>
25 #include <opm/input/eclipse/Schedule/Well/Well.hpp>
26 
27 #include <cstddef>
28 #include <ctime>
29 #include <limits>
30 #include <memory>
31 #include <string>
32 #include <unordered_map>
33 #include <utility>
34 
35 namespace Opm {
36 
37 class Schedule;
38 
39 } // namespace Opm
40 
41 namespace Opm {
42 
43 class GuideRate
44 {
45 public:
46  // used for potentials and well rates
47  struct RateVector {
48  RateVector() = default;
49  RateVector(const double orat, const double grat, const double wrat)
50  : oil_rat(orat)
51  , gas_rat(grat)
52  , wat_rat(wrat)
53  {}
54 
55  double eval(const Well::GuideRateTarget target) const;
56  double eval(const Group::GuideRateProdTarget target) const;
57  double eval(const GuideRateModel::Target target) const;
58 
59  double oil_rat{0.0};
60  double gas_rat{0.0};
61  double wat_rat{0.0};
62  };
63 
64  struct GuideRateValue {
65  GuideRateValue() = default;
66  GuideRateValue(const double t, const double v, const GuideRateModel::Target tg)
67  : sim_time(t)
68  , value (v)
69  , target (tg)
70  {}
71 
72  bool operator==(const GuideRateValue& other) const
73  {
74  return (this->sim_time == other.sim_time)
75  && (this->value == other.value);
76  }
77 
78  bool operator!=(const GuideRateValue& other) const
79  {
80  return !(*this == other);
81  }
82 
83  double sim_time { std::numeric_limits<double>::lowest() };
84  double value { std::numeric_limits<double>::lowest() };
85  GuideRateModel::Target target { GuideRateModel::Target::NONE };
86  };
87 
88  GuideRate(const Schedule& schedule);
89 
90  void compute(const std::string& wgname,
91  const std::size_t report_step,
92  const double sim_time,
93  const double oil_pot,
94  const double gas_pot,
95  const double wat_pot);
96 
97  void compute(const std::string& wgname,
98  const Phase& phase,
99  const std::size_t report_step,
100  const double guide_rate);
101 
102  bool has(const std::string& name) const;
103  bool hasPotentials(const std::string& name) const;
104  bool has(const std::string& name, const Phase& phase) const;
105 
106  double get(const std::string& well, const Well::GuideRateTarget target, const RateVector& rates) const;
107  double get(const std::string& group, const Group::GuideRateProdTarget target, const RateVector& rates) const;
108  double get(const std::string& name, const GuideRateModel::Target model_target, const RateVector& rates) const;
109  double get(const std::string& group, const Phase& phase) const;
110 
111  double getSI(const std::string& well, const Well::GuideRateTarget target, const RateVector& rates) const;
112  double getSI(const std::string& group, const Group::GuideRateProdTarget target, const RateVector& rates) const;
113  double getSI(const std::string& wgname, const GuideRateModel::Target target, const RateVector& rates) const;
114  double getSI(const std::string& group, const Phase& phase) const;
115 
116  void init_grvalue(const std::size_t report_step, const std::string& wgname, GuideRateValue value);
117  void init_grvalue_SI(const std::size_t report_step, const std::string& wgname, GuideRateValue value);
118 
119  void updateGuideRateExpiration(const double sim_time,
120  const std::size_t report_step);
121 
122 private:
123  struct GRValState
124  {
125  GuideRateValue curr{};
126  GuideRateValue prev{};
127  };
128 
129  struct pair_hash
130  {
131  template <class T1, class T2>
132  std::size_t operator()(const std::pair<T1, T2>& pair) const
133  {
134  return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
135  }
136  };
137 
138  using GRValPtr = std::unique_ptr<GRValState>;
139  using pair = std::pair<Phase, std::string>;
140 
141  void well_compute(const std::string& wgname,
142  const std::size_t report_step,
143  const double sim_time,
144  const double oil_pot,
145  const double gas_pot,
146  const double wat_pot);
147 
148  void group_compute(const std::string& wgname,
149  const std::size_t report_step,
150  const double sim_time,
151  const double oil_pot,
152  const double gas_pot,
153  const double wat_pot);
154 
155  double eval_form(const GuideRateModel& model,
156  const double oil_pot,
157  const double gas_pot,
158  const double wat_pot) const;
159  double eval_group_pot() const;
160  double eval_group_resvinj() const;
161 
162  void assign_grvalue(const std::string& wgname,
163  const GuideRateModel& model,
164  GuideRateValue&& value);
165  double get_grvalue_result(const GRValState& gr) const;
166 
167  const Schedule& schedule;
168 
169  std::unordered_map<std::string, GRValPtr> values{};
170  std::unordered_map<pair, double, pair_hash> injection_group_values{};
171  std::unordered_map<std::string, RateVector> potentials{};
172  bool guide_rates_expired {false};
173 };
174 
175 } // namespace Opm
176 
177 #endif
Definition: GuideRate.hpp:44
Definition: Schedule.hpp:138
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: GuideRate.hpp:64
Definition: GuideRate.hpp:47