My Project
WellInterfaceGeneric.hpp
1 /*
2  Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3  Copyright 2017 Statoil ASA.
4  Copyright 2017 IRIS
5  Copyright 2019 Norce
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 #ifndef OPM_WELLINTERFACE_GENERIC_HEADER_INCLUDED
25 #define OPM_WELLINTERFACE_GENERIC_HEADER_INCLUDED
26 
27 #include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
28 
29 #include <map>
30 #include <optional>
31 #include <string>
32 #include <vector>
33 
34 namespace Opm
35 {
36 
37 class DeferredLogger;
38 class GuideRate;
39 class ParallelWellInfo;
40 struct PerforationData;
41 struct PhaseUsage;
42 class SummaryState;
43 class VFPProperties;
44 class WellTestState;
45 class WellState;
46 class SingleWellState;
47 class GroupState;
48 class Group;
49 class Schedule;
50 
52 public:
53 
54  WellInterfaceGeneric(const Well& well,
55  const ParallelWellInfo& parallel_well_info,
56  const int time_step,
57  const int pvtRegionIdx,
58  const int num_components,
59  const int num_phases,
60  const int index_of_well,
61  const std::vector<PerforationData>& perf_data);
62 
64  const std::vector<PerforationData>& perforationData() const;
65 
67  const std::string& name() const;
68 
70  bool isInjector() const;
71 
73  bool isProducer() const;
74 
76  const std::vector<int>& cells() const { return well_cells_; }
77 
79  int indexOfWell() const;
80 
81  const Well& wellEcl() const;
82  const PhaseUsage& phaseUsage() const;
83 
85  bool underPredictionMode() const;
86 
87  // whether the well is operable
88  bool isOperableAndSolvable() const;
89 
90  void initCompletions();
91  void closeCompletions(const WellTestState& wellTestState);
92 
93  void setVFPProperties(const VFPProperties* vfp_properties_arg);
94  void setGuideRate(const GuideRate* guide_rate_arg);
95  void setWellEfficiencyFactor(const double efficiency_factor);
96  void setRepRadiusPerfLength(const std::vector<int>& cartesian_to_compressed);
97  void setWsolvent(const double wsolvent);
98  void setDynamicThpLimit(const double thp_limit);
99  void updatePerforatedCell(std::vector<bool>& is_cell_perforated);
100 
102  bool wellHasTHPConstraints(const SummaryState& summaryState) const;
103 
104  void stopWell() {
105  this->wellStatus_ = Well::Status::STOP;
106  }
107 
108  void openWell() {
109  this->wellStatus_ = Well::Status::OPEN;
110  }
111 
112  bool wellIsStopped() const {
113  return this->wellStatus_ == Well::Status::STOP;
114  }
115 
116  int currentStep() const {
117  return this->current_step_;
118  }
119 
120  int pvtRegionIdx() const {
121  return pvtRegionIdx_;
122  }
123 
124  const GuideRate* guideRate() const {
125  return guide_rate_;
126  }
127 
128  int numComponents() const {
129  return num_components_;
130  }
131 
132  int numPhases() const {
133  return number_of_phases_;
134  }
135 
136  int numPerfs() const {
137  return number_of_perforations_;
138  }
139 
140  double refDepth() const {
141  return ref_depth_;
142  }
143 
144  double gravity() const {
145  return gravity_;
146  }
147 
148  const VFPProperties* vfpProperties() const {
149  return vfp_properties_;
150  }
151 
152  const ParallelWellInfo& parallelWellInfo() const {
153  return parallel_well_info_;
154  }
155 
156  const std::vector<double>& perfDepth() const {
157  return perf_depth_;
158  }
159 
160  std::vector<double>& perfDepth() {
161  return perf_depth_;
162  }
163 
164  const std::vector<double>& wellIndex() const {
165  return well_index_;
166  }
167 
168  double getTHPConstraint(const SummaryState& summaryState) const;
169  double getALQ(const WellState& well_state) const;
170  double wsolvent() const;
171 
172  // whether a well is specified with a non-zero and valid VFP table number
173  bool isVFPActive(DeferredLogger& deferred_logger) const;
174 
175  void reportWellSwitching(const SingleWellState& ws, DeferredLogger& deferred_logger) const;
176 
177 protected:
178  bool getAllowCrossFlow() const;
179  double mostStrictBhpFromBhpLimits(const SummaryState& summaryState) const;
180  void updateWellTestStatePhysical(const double simulation_time,
181  const bool write_message_to_opmlog,
182  WellTestState& well_test_state,
183  DeferredLogger& deferred_logger) const;
184 
185 
186  // definition of the struct OperabilityStatus
188  bool isOperableAndSolvable() const {
189  if (!operable_under_only_bhp_limit || !solvable) {
190  return false;
191  } else {
192  return ( (isOperableUnderBHPLimit() || isOperableUnderTHPLimit()) );
193  }
194  }
195 
196  bool isOperableUnderBHPLimit() const {
197  return operable_under_only_bhp_limit && obey_thp_limit_under_bhp_limit;
198  }
199 
200  bool isOperableUnderTHPLimit() const {
201  return can_obtain_bhp_with_thp_limit && obey_bhp_limit_with_thp_limit;
202  }
203 
204  void resetOperability() {
205  operable_under_only_bhp_limit = true;
206  obey_thp_limit_under_bhp_limit = true;
207  can_obtain_bhp_with_thp_limit = true;
208  obey_bhp_limit_with_thp_limit = true;
209  }
210 
211  // whether the well can be operated under bhp limit
212  // without considering other limits.
213  // if it is false, then the well is not operable for sure.
214  bool operable_under_only_bhp_limit = true;
215  // if the well can be operated under bhp limit, will it obey(not violate)
216  // the thp limit when operated under bhp limit
217  bool obey_thp_limit_under_bhp_limit = true;
218  // whether the well operate under the thp limit only
219  bool can_obtain_bhp_with_thp_limit = true;
220  // whether the well obey bhp limit when operated under thp limit
221  bool obey_bhp_limit_with_thp_limit = true;
222  // the well is solveable
223  bool solvable = true;
224  };
225 
226  OperabilityStatus operability_status_;
227 
228  Well well_ecl_;
229 
230  const ParallelWellInfo& parallel_well_info_;
231  const int current_step_;
232 
233  // The pvt region of the well. We assume
234  // We assume a well to not penetrate more than one pvt region.
235  const int pvtRegionIdx_;
236 
237  const int num_components_;
238 
239  // number of phases
240  int number_of_phases_;
241 
242  // the index of well in Wells struct
243  int index_of_well_;
244 
245  const std::vector<PerforationData>* perf_data_;
246 
247  // the vectors used to describe the inflow performance relationship (IPR)
248  // Q = IPR_A - BHP * IPR_B
249  // TODO: it minght need to go to WellInterface, let us implement it in StandardWell first
250  // it is only updated and used for producers for now
251  mutable std::vector<double> ipr_a_;
252  mutable std::vector<double> ipr_b_;
253 
254  // cell index for each well perforation
255  std::vector<int> well_cells_;
256 
257  // well index for each perforation
258  std::vector<double> well_index_;
259 
260  // number of the perforations for this well
261  int number_of_perforations_;
262 
263  // depth for each perforation
264  std::vector<double> perf_depth_;
265 
266  // representative radius of the perforations, used in shear calculation
267  std::vector<double> perf_rep_radius_;
268 
269  // length of the perforations, use in shear calculation
270  std::vector<double> perf_length_;
271 
272  // well bore diameter
273  std::vector<double> bore_diameters_;
274 
275  /*
276  * completions_ contains the mapping from completion id to connection indices
277  * {
278  * 2 : [ConnectionIndex, ConnectionIndex],
279  * 1 : [ConnectionIndex, ConnectionIndex, ConnectionIndex],
280  * 5 : [ConnectionIndex],
281  * 7 : [ConnectionIndex]
282  * ...
283  * }
284  * The integer IDs correspond to the COMPLETION id given by the COMPLUMP keyword.
285  * When there is no COMPLUMP keyword used, a default completion number will be assigned
286  * based on the order of the declaration of the connections.
287  * Since the connections not OPEN is not included in the Wells, so they will not be considered
288  * in this mapping relation.
289  */
290  std::map<int, std::vector<int>> completions_;
291 
292  // reference depth for the BHP
293  double ref_depth_;
294 
295  // saturation table nubmer for each well perforation
296  std::vector<int> saturation_table_number_;
297 
298  Well::Status wellStatus_;
299 
300  const PhaseUsage* phase_usage_;
301 
302  double gravity_;
303  double wsolvent_;
304  std::optional<double> dynamic_thp_limit_;
305 
306  double well_efficiency_factor_;
307  const VFPProperties* vfp_properties_;
308  const GuideRate* guide_rate_;
309 
310  std::vector< std::string> well_control_log_;
311 };
312 
313 }
314 
315 #endif // OPM_WELLINTERFACE_HEADER_INCLUDED
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:252
A thin wrapper class that holds one VFPProdProperties and one VFPInjProperties object.
Definition: VFPProperties.hpp:37
Definition: WellInterfaceGeneric.hpp:51
bool wellHasTHPConstraints(const SummaryState &summaryState) const
Returns true if the well has one or more THP limits/constraints.
Definition: WellInterfaceGeneric.cpp:150
int indexOfWell() const
Index of well in the wells struct and wellState.
Definition: WellInterfaceGeneric.cpp:123
const std::string & name() const
Well name.
Definition: WellInterfaceGeneric.cpp:108
const std::vector< int > & cells() const
Well cells.
Definition: WellInterfaceGeneric.hpp:76
bool underPredictionMode() const
Returns true if the well is currently in prediction mode (i.e. not history mode).
Definition: WellInterfaceGeneric.cpp:205
bool isProducer() const
True if the well is a producer.
Definition: WellInterfaceGeneric.cpp:118
bool isInjector() const
True if the well is an injector.
Definition: WellInterfaceGeneric.cpp:113
const std::vector< PerforationData > & perforationData() const
Get the perforations of the well.
Definition: WellInterfaceGeneric.cpp:103
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:26
Definition: BlackoilPhases.hpp:45
Definition: WellInterfaceGeneric.hpp:187