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/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
24 #include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRateModel.hpp>
25 #include <opm/parser/eclipse/EclipseState/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 has(const std::string& name, const Phase& phase) const;
104 
105  double get(const std::string& well, const Well::GuideRateTarget target, const RateVector& rates) const;
106  double get(const std::string& group, const Group::GuideRateProdTarget target, const RateVector& rates) const;
107  double get(const std::string& name, const GuideRateModel::Target model_target, const RateVector& rates) const;
108  double get(const std::string& group, const Phase& phase) const;
109 
110  double getSI(const std::string& well, const Well::GuideRateTarget target, const RateVector& rates) const;
111  double getSI(const std::string& group, const Group::GuideRateProdTarget target, const RateVector& rates) const;
112  double getSI(const std::string& wgname, const GuideRateModel::Target target, const RateVector& rates) const;
113  double getSI(const std::string& group, const Phase& phase) const;
114 
115  void init_grvalue(const std::size_t report_step, const std::string& wgname, GuideRateValue value);
116  void init_grvalue_SI(const std::size_t report_step, const std::string& wgname, GuideRateValue value);
117 
118  void updateGuideRateExpiration(const double sim_time,
119  const std::size_t report_step);
120 
121 private:
122  struct GRValState
123  {
124  GuideRateValue curr{};
125  GuideRateValue prev{};
126  };
127 
128  struct pair_hash
129  {
130  template <class T1, class T2>
131  std::size_t operator()(const std::pair<T1, T2>& pair) const
132  {
133  return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
134  }
135  };
136 
137  using GRValPtr = std::unique_ptr<GRValState>;
138  using pair = std::pair<Phase, std::string>;
139 
140  void well_compute(const std::string& wgname,
141  const std::size_t report_step,
142  const double sim_time,
143  const double oil_pot,
144  const double gas_pot,
145  const double wat_pot);
146 
147  void group_compute(const std::string& wgname,
148  const std::size_t report_step,
149  const double sim_time,
150  const double oil_pot,
151  const double gas_pot,
152  const double wat_pot);
153 
154  double eval_form(const GuideRateModel& model,
155  const double oil_pot,
156  const double gas_pot,
157  const double wat_pot) const;
158  double eval_group_pot() const;
159  double eval_group_resvinj() const;
160 
161  void assign_grvalue(const std::string& wgname,
162  const GuideRateModel& model,
163  GuideRateValue&& value);
164  double get_grvalue_result(const GRValState& gr) const;
165 
166  const Schedule& schedule;
167 
168  std::unordered_map<std::string, GRValPtr> values{};
169  std::unordered_map<pair, double, pair_hash> injection_group_values{};
170  std::unordered_map<std::string, RateVector> potentials{};
171  bool guide_rates_expired {false};
172 };
173 
174 } // namespace Opm
175 
176 #endif
Definition: GuideRate.hpp:44
Definition: Schedule.hpp:135
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