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