opm-common
WellConnections.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 CONNECTIONSET_HPP_
21 #define CONNECTIONSET_HPP_
22 
23 #include <opm/input/eclipse/Schedule/Well/Connection.hpp>
24 
25 #include <array>
26 #include <cstddef>
27 #include <optional>
28 #include <string>
29 #include <vector>
30 
31 namespace Opm {
32  class ActiveGridCells;
33  class DeckRecord;
34  class EclipseGrid;
35  class ErrorGuard;
36  class FieldPropsManager;
37  class KeywordLocation;
38  class ParseContext;
39  class ScheduleGrid;
40  class WDFAC;
41  struct WellTrajInfo;
42 } // namespace Opm
43 
44 namespace Opm {
45 
47  {
48  public:
49  using const_iterator = std::vector<Connection>::const_iterator;
50 
51  WellConnections() = default;
52  WellConnections(const Connection::Order ordering, const int headI, const int headJ);
53  WellConnections(const Connection::Order ordering, const int headI, const int headJ,
54  const std::vector<Connection>& connections);
55 
56  static WellConnections serializationTestObject();
57 
58  // cppcheck-suppress noExplicitConstructor
59  template <class Grid>
60  WellConnections(const WellConnections& src, const Grid& grid)
61  : m_ordering(src.ordering())
62  , headI (src.headI)
63  , headJ (src.headJ)
64  {
65  for (const auto& c : src) {
66  if (grid.isCellActive(c.getI(), c.getJ(), c.getK())) {
67  this->add(c);
68  }
69  }
70  }
71 
72  void add(const Connection& conn)
73  {
74  this->m_connections.push_back(conn);
75  }
76 
77  void addConnection(const int i, const int j, const int k,
78  const std::size_t global_index,
79  const Connection::State state,
80  const double depth,
81  const Connection::CTFProperties& ctf_props,
82  const int satTableId,
83  const Connection::Direction direction = Connection::Direction::Z,
84  const Connection::CTFKind ctf_kind = Connection::CTFKind::DeckValue,
85  const std::size_t seqIndex = 0,
86  int lgr_grid_number = 0,
87  const bool defaultSatTabId = true);
88 
89  // Out-parameter 'requested_open_complnums' is cleared and then set to
90  // the complnum of every existing connection this record opens (assigns
91  // OPEN), for raising REQUEST_OPEN_COMPLETION events. Likewise,
92  // 'requested_shut_complnums' is cleared and then set to the complnum of
93  // every existing connection this record shuts (assigns a non-OPEN
94  // state), for clearing any pending REQUEST_OPEN_COMPLETION events.
95  void loadCOMPDAT(const DeckRecord& record,
96  const std::string& wname,
97  const WDFAC& wdfac,
98  const ScheduleGrid& grid,
99  const KeywordLocation& location,
100  const ParseContext& parseContext,
101  ErrorGuard& errors,
102  std::vector<int>& requested_open_complnums,
103  std::vector<int>& requested_shut_complnums);
104 
105  void loadCOMPDATL(const DeckRecord& record,
106  const std::string& wname,
107  const WDFAC& wdfac,
108  const ScheduleGrid& grid,
109  const KeywordLocation& location,
110  const ParseContext& parseContext,
111  ErrorGuard& errors,
112  std::vector<int>& requested_open_complnums,
113  std::vector<int>& requested_shut_complnums);
114 
115  void loadCOMPTRAJ(const DeckRecord& record,
116  const std::string& wname,
117  const ScheduleGrid& grid,
118  const KeywordLocation& location,
119  WellTrajInfo& wellTraj);
120 
121  void loadWELTRAJ(const DeckRecord& record,
122  const std::string& wname,
123  const ScheduleGrid& grid,
124  const KeywordLocation& location);
125 
126  void applyDFactorCorrelation(const ScheduleGrid& grid,
127  const WDFAC& wdfac);
128 
129  int getHeadI() const;
130  int getHeadJ() const;
131  const std::vector<double>& getMD() const;
132  std::size_t size() const;
133  bool empty() const;
134  std::size_t num_open() const;
135  const Connection& operator[](std::size_t index) const;
136  const Connection& get(std::size_t index) const;
137  const Connection& getFromIJK(const int i, const int j, const int k) const;
138  const Connection& getFromGlobalIndex(std::size_t global_index) const;
139  const Connection& lowest() const;
140  Connection& getFromIJK(const int i, const int j, const int k);
141  Connection* maybeGetFromGlobalIndex(const std::size_t global_index);
142  bool hasGlobalIndex(std::size_t global_index) const;
143  double segment_perf_length(int segment) const;
144 
145  const_iterator begin() const { return this->m_connections.begin(); }
146  const_iterator end() const { return this->m_connections.end(); }
147  auto begin() { return this->m_connections.begin(); }
148  auto end() { return this->m_connections.end(); }
149  bool allConnectionsShut() const;
150 
167  void order();
168 
169  bool operator==( const WellConnections& ) const;
170  bool operator!=( const WellConnections& ) const;
171 
172  Connection::Order ordering() const { return this->m_ordering; }
173  std::vector<const Connection *> output(const EclipseGrid& grid) const;
174 
183  bool prepareWellPIScaling();
184 
192  void applyWellPIScaling(const double scaleFactor,
193  std::vector<bool>& scalingApplicable);
194 
195  template <class Serializer>
196  void serializeOp(Serializer& serializer)
197  {
198  serializer(this->m_ordering);
199  serializer(this->headI);
200  serializer(this->headJ);
201  serializer(this->m_connections);
202  serializer(this->coord);
203  serializer(this->md);
204  }
205 
206  private:
207  Connection::Order m_ordering { Connection::Order::TRACK };
208  int headI{0};
209  int headJ{0};
210  std::vector<Connection> m_connections{};
211 
212  std::array<std::vector<double>, 3> coord{};
213  std::vector<double> md{};
214 
215  void addConnection(const int i, const int j, const int k,
216  const std::size_t global_index,
217  const int complnum,
218  const Connection::State state,
219  const double depth,
220  const Connection::CTFProperties& ctf_props,
221  const int satTableId,
222  const Connection::Direction direction,
223  const Connection::CTFKind ctf_kind,
224  const std::size_t seqIndex,
225  int lgr_grid_number,
226  const bool defaultSatTabId);
227 
228  void orderTRACK();
229  void orderMSW();
230  void orderDEPTH();
231 
232  void loadCOMPDATX(const DeckRecord& record,
233  const std::string& wname,
234  const WDFAC& wdfac,
235  const ScheduleGrid& grid,
236  const KeywordLocation& location,
237  const std::optional<std::string>& lgr_label,
238  const ParseContext& parseContext,
239  ErrorGuard& errors,
240  std::vector<int>& requested_open_complnums,
241  std::vector<int>& requested_shut_complnums);
242  };
243 
244  std::optional<int>
245  getCompletionNumberFromGlobalConnectionIndex(const WellConnections& connections,
246  const std::size_t global_index);
247 } // namespace Opm
248 
249 #endif // CONNECTIONSET_HPP_
Definition: Connection.hpp:55
Quantities that go into calculating the connection transmissibility factor.
Definition: Connection.hpp:93
Definition: KeywordLocation.hpp:27
Definition: WDFAC.hpp:39
About cell information and dimension: The actual grid information is held in a pointer to an ERT ecl_...
Definition: EclipseGrid.hpp:63
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
Definition: WellTrajInfo.hpp:29
void applyWellPIScaling(const double scaleFactor, std::vector< bool > &scalingApplicable)
Scale pertinent connections&#39; CF value by supplied value.
Definition: WellConnections.cpp:367
bool prepareWellPIScaling()
Activate or reactivate WELPI scaling for this connection set.
Definition: WellConnections.cpp:357
Control parser behaviour in failure conditions.
Definition: ParseContext.hpp:114
Definition: WellConnections.hpp:46
void order()
Order connections along well bore.
Definition: WellConnections.cpp:1075
Definition: DeckRecord.hpp:33
Class for (de-)serializing.
Definition: Serializer.hpp:95
Definition: ErrorGuard.hpp:30