opm-common
Connection.hpp
1 /*
2  Copyright 2013 Statoil 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 COMPLETION_HPP_
21 #define COMPLETION_HPP_
22 
23 #include <opm/utility/CopyablePtr.hpp>
24 
25 #include <opm/input/eclipse/Schedule/Well/ConnectionEconLimits.hpp>
26 #include <opm/input/eclipse/Schedule/Well/FilterCake.hpp>
27 #include <opm/input/eclipse/Schedule/Well/WINJMULT.hpp>
28 
29 #include <array>
30 #include <cstddef>
31 #include <optional>
32 #include <string>
33 #include <string_view>
34 #include <vector>
35 
36 namespace Opm {
37  class DeckKeyword;
38  class DeckRecord;
39  class ScheduleGrid;
40  class FieldPropsManager;
41 } // namespace Opm
42 
43 namespace Opm { namespace RestartIO {
44  struct RstConnection;
45 }} // namespace Opm::RestartIO
46 
47 namespace Opm {
48 
49  enum class ConnectionOrder {
50  DEPTH,
51  INPUT,
52  TRACK,
53  };
54 
55  class Connection
56  {
57  public:
58  enum class State {
59  OPEN = 1,
60  SHUT = 2,
61  AUTO = 3, // Seems like the AUTO state can not be serialized to restart files.
62  };
63 
64  static std::string State2String(State enumValue);
65  static State StateFromString(std::string_view stringValue);
66 
67 
68  enum class Direction {
69  X = 1,
70  Y = 2,
71  Z = 3,
72  };
73 
74  static std::string Direction2String(const Direction enumValue);
75  static Direction DirectionFromString(std::string_view stringValue);
76 
77 
78  using Order = ConnectionOrder;
79 
80  static std::string Order2String(Order enumValue);
81  static Order OrderFromString(std::string_view comporderStringValue);
82 
83 
84  enum class CTFKind {
85  DeckValue,
86  Defaulted,
87  DynamicFracturing,
88  };
89 
90 
94  {
97  double CF{};
98 
100  double Kh{};
101 
103  double Ke{};
104 
106  double rw{};
107 
109  double r0{};
110 
113  double re{};
114 
117 
119  double skin_factor{};
120 
123  double d_factor{};
124 
128 
130  double peaceman_denom{};
131 
134 
138  bool operator==(const CTFProperties& that) const;
139 
143  bool operator!=(const CTFProperties& that) const
144  {
145  return ! (*this == that);
146  }
147 
155  template <class Serializer>
156  void serializeOp(Serializer& serializer)
157  {
158  serializer(this->CF);
159  serializer(this->Kh);
160  serializer(this->Ke);
161  serializer(this->rw);
162  serializer(this->r0);
163  serializer(this->re);
164  serializer(this->connection_length);
165  serializer(this->skin_factor);
166  serializer(this->d_factor);
167  serializer(this->static_dfac_corr_coeff);
168  serializer(this->peaceman_denom);
169  }
170  };
171 
172 
173  Connection() = default;
174  Connection(int i, int j, int k,
175  std::size_t global_index,
176  int complnum,
177  State state,
178  Direction direction,
179  CTFKind ctf_kind,
180  const int satTableId,
181  double depth,
182  const CTFProperties& ctf_properties,
183  const std::size_t sort_value,
184  const bool defaultSatTabId,
185  int lgr_grid_ = 0);
186 
187  Connection(const RestartIO::RstConnection& rst_connection,
188  const ScheduleGrid& grid,
189  const FieldPropsManager& fp);
190 
191  static Connection serializationTestObject();
192 
193  bool attachedToSegment() const;
194  bool sameCoordinate(const int i, const int j, const int k) const;
195  int getI() const;
196  int getJ() const;
197  int getK() const;
198  std::size_t global_index() const;
199  int get_lgr_level() const {return lgr_grid;}
200  State state() const;
201  Direction dir() const;
202  double depth() const;
203  int satTableId() const;
204  int complnum() const;
205  int segment() const;
206  double wpimult() const;
207  double CF() const;
208  double Kh() const;
209  double Ke() const;
210  double rw() const;
211  double r0() const;
212  double re() const;
213  double connectionLength() const;
214  double skinFactor() const;
215  double dFactor() const;
216  CTFKind kind() const;
217  const InjMult& injmult() const;
218  bool activeInjMult() const;
219  const FilterCake& getFilterCake() const;
220  bool filterCakeActive() const;
221  double getFilterCakeRadius() const;
222  double getFilterCakeArea() const;
223 
224  const ConnectionEconLimits& econLimits() const;
225  bool hasEconLimits() const;
226 
227  const CTFProperties& ctfProperties() const
228  {
229  return this->ctf_properties_;
230  }
231 
232  std::size_t sort_value() const;
233  bool getDefaultSatTabId() const;
234  const std::optional<std::pair<double, double>>& perf_range() const;
235  std::string str() const;
236 
237  bool ctfAssignedFromInput() const
238  {
239  return this->m_ctfkind == CTFKind::DeckValue;
240  }
241 
242  bool operator==(const Connection&) const;
243  bool operator!=(const Connection& that) const
244  {
245  return ! (*this == that);
246  }
247 
248  void setInjMult(const InjMult& inj_mult);
249  void setFilterCake(const FilterCake& filter_cake);
250  void setEconLimits(const ConnectionEconLimits& econ_limits);
251  void setState(State state);
252  void setComplnum(int compnum);
253  void setSkinFactor(double skin_factor);
254  void setDFactor(double d_factor);
255  void setKe(double Ke);
256  void setCF(double CF);
257  void setDefaultSatTabId(bool id);
258  void setStaticDFacCorrCoeff(const double c);
259 
260  void scaleWellPi(double wellPi);
261  bool prepareWellPIScaling();
262  bool applyWellPIScaling(const double scaleFactor);
263 
264  void updateSegmentRST(int segment_number_arg,
265  double center_depth_arg);
266  void updateSegment(int segment_number_arg,
267  double center_depth_arg,
268  std::size_t compseg_insert_index,
269  const std::optional<std::pair<double,double>>& perf_range);
270 
271  template<class Serializer>
272  void serializeOp(Serializer& serializer)
273  {
274  serializer(this->direction);
275  serializer(this->center_depth);
276  serializer(this->open_state);
277  serializer(this->sat_tableId);
278  serializer(this->m_complnum);
279  serializer(this->ctf_properties_);
280  serializer(this->ijk);
281  serializer(this->lgr_grid);
282  serializer(this->m_ctfkind);
283  serializer(this->m_global_index);
284  serializer(this->m_injmult);
285  serializer(this->m_sort_value);
286  serializer(this->m_perf_range);
287  serializer(this->m_defaultSatTabId);
288  serializer(this->segment_number);
289  serializer(this->m_wpimult);
290  serializer(this->m_subject_to_welpi);
291  serializer(this->m_filter_cake);
292  serializer(this->m_econ_limits);
293  }
294 
295  private:
296  // Note to maintainer: If you add new members to this list, then
297  // please also update the operator==(), serializeOp(), and
298  // serializationTestObject() member functions.
299  Direction direction { Direction::Z };
300  double center_depth { 0.0 };
301  State open_state { State::SHUT };
302  int sat_tableId { -1 };
303  int m_complnum { -1 };
304  CTFProperties ctf_properties_{};
305 
306  std::array<int,3> ijk{};
307  int lgr_grid{0};
308  CTFKind m_ctfkind { CTFKind::DeckValue };
309  std::optional<InjMult> m_injmult{};
310  std::size_t m_global_index{};
311 
312  /*
313  The sort_value member is a peculiar quantity. The connections are
314  assembled in the WellConnections class. During the lifetime of the
315  connections there are three different sort orders which are all
316  relevant:
317 
318  input: This is the ordering implied be the order of the
319  connections in the input deck.
320 
321  simulation: This is the ordering the connections have in
322  WellConnections container during the simulation and RFT output.
323 
324  restart: This is the ordering the connections have when they are
325  written out to a restart file.
326 
327  Exactly what consitutes input, simulation and restart ordering, and
328  how the connections transition between the three during application
329  lifetime is different from MSW and normal wells.
330 
331  normal wells: For normal wells the simulation order is given by the
332  COMPORD keyword, and then when the connections are serialized to the
333  restart file they are written in input order; i.e. we have:
334 
335  input == restart and simulation given COMPORD
336 
337  To recover the input order when creating the restart files the
338  sort_value member corresponds to the insert index for normal wells.
339 
340  MSW wells: For MSW wells the wells simulator order[*] is given by
341  COMPSEGS keyword, the COMPORD keyword is ignored. The connections are
342  sorted in WellConnections::order() and then retain that order for all
343  eternity i.e.
344 
345  input and simulation == restart
346 
347  Now the important point is that the COMPSEGS detail used to perform
348  this sorting is not available when loading from a restart file, but
349  then the connections are already sorted correctly. I.e. *after* a
350  restart we will have:
351 
352  input(from restart) == simulation == restart
353 
354  The sort_value member is used to sort the connections into restart
355  ordering. In the case of normal wells this corresponds to recovering
356  the input order, whereas for MSW wells this is equivalent to the
357  simulation order.
358 
359  [*]: For MSW wells the topology is given by the segments and entered
360  explicitly, so the truth is probably that the storage order
361  during simulation makes no difference?
362  */
363  std::size_t m_sort_value{};
364 
365  std::optional<std::pair<double,double>> m_perf_range{};
366  bool m_defaultSatTabId{true};
367 
368  // Associate segment number
369  //
370  // 0 means the connection is not associated to a segment.
371  int segment_number { 0 };
372 
373  double m_wpimult { 1.0 };
374 
375  // Whether or not this Connection is subject to WELPI scaling.
376  bool m_subject_to_welpi { false };
377 
378  std::optional<FilterCake> m_filter_cake{};
379 
380  Utility::CopyablePtr<ConnectionEconLimits> m_econ_limits{};
381 
382  static std::string CTFKindToString(const CTFKind);
383  };
384 
385 } // namespace Opm
386 
387 #endif // COMPLETION_HPP_
double connection_length
Length of connection&#39;s perfororation interval.
Definition: Connection.hpp:116
double rw
Connection&#39;s wellbore radius.
Definition: Connection.hpp:106
Definition: Connection.hpp:55
void serializeOp(Serializer &serializer)
Serialisation operator.
Definition: Connection.hpp:156
double re
Connection&#39;s area equivalent radius–mostly for use by the polymer code.
Definition: Connection.hpp:113
Quantities that go into calculating the connection transmissibility factor.
Definition: Connection.hpp:93
double Kh
Static &#39;Kh&#39; product.
Definition: Connection.hpp:100
bool operator==(const CTFProperties &that) const
Equality operator.
Definition: Connection.cpp:95
double r0
Connection&#39;s pressure equivalent radius.
Definition: Connection.hpp:109
double Ke
Effective permeability.
Definition: Connection.hpp:103
Definition: FieldPropsManager.hpp:42
double static_dfac_corr_coeff
Product of certain static elements of D-factor correlation law (WDFACCOR keyword).
Definition: Connection.hpp:127
bool operator!=(const CTFProperties &that) const
Inequality operator.
Definition: Connection.hpp:143
double skin_factor
Connection&#39;s skin factor.
Definition: Connection.hpp:119
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Collection of intersected cells and associate properties for all simulation grids, i.e., the main grid and all LGRs in the simulation run.
Definition: ScheduleGrid.hpp:49
double d_factor
Connection&#39;s D factor-i.e., the flow-dependent skin factor for gas.
Definition: Connection.hpp:123
static CTFProperties serializationTestObject()
Serialisation test object.
Definition: Connection.cpp:76
Definition: DeckValue.hpp:30
double peaceman_denom
Denominator in peaceman&#39;s formula-i.e., log(r0/rw) + skin.
Definition: Connection.hpp:130
double CF
Static connection transmissibility factor calculated from input quantities.
Definition: Connection.hpp:97
Class for (de-)serializing.
Definition: Serializer.hpp:95
Definition: connection.hpp:35