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 #include <stddef.h>
32 
33 namespace Opm {
34  class ActiveGridCells;
35  class DeckRecord;
36  class EclipseGrid;
37  class ErrorGuard;
38  class FieldPropsManager;
39  class KeywordLocation;
40  class ParseContext;
41  class ScheduleGrid;
42  class WDFAC;
43  struct WellTrajInfo;
44 } // namespace Opm
45 
46 namespace Opm {
47 
49  {
50  public:
51  using const_iterator = std::vector<Connection>::const_iterator;
52 
53  WellConnections() = default;
54  WellConnections(const Connection::Order ordering, const int headI, const int headJ);
55  WellConnections(const Connection::Order ordering, const int headI, const int headJ,
56  const std::vector<Connection>& connections);
57 
58  static WellConnections serializationTestObject();
59 
60  // cppcheck-suppress noExplicitConstructor
61  template <class Grid>
62  WellConnections(const WellConnections& src, const Grid& grid)
63  : m_ordering(src.ordering())
64  , headI (src.headI)
65  , headJ (src.headJ)
66  {
67  for (const auto& c : src) {
68  if (grid.isCellActive(c.getI(), c.getJ(), c.getK())) {
69  this->add(c);
70  }
71  }
72  }
73 
74  void add(const Connection& conn)
75  {
76  this->m_connections.push_back(conn);
77  }
78 
79  void addConnection(const int i, const int j, const int k,
80  const std::size_t global_index,
81  const Connection::State state,
82  const double depth,
83  const Connection::CTFProperties& ctf_props,
84  const int satTableId,
85  const Connection::Direction direction = Connection::Direction::Z,
86  const Connection::CTFKind ctf_kind = Connection::CTFKind::DeckValue,
87  const std::size_t seqIndex = 0,
88  int lgr_grid_number = 0,
89  const bool defaultSatTabId = true);
90 
91  void loadCOMPDAT(const DeckRecord& record,
92  const std::string& wname,
93  const WDFAC& wdfac,
94  const ScheduleGrid& grid,
95  const KeywordLocation& location,
96  const ParseContext& parseContext,
97  ErrorGuard& errors);
98 
99  void loadCOMPDATL(const DeckRecord& record,
100  const std::string& wname,
101  const WDFAC& wdfac,
102  const ScheduleGrid& grid,
103  const KeywordLocation& location,
104  const ParseContext& parseContext,
105  ErrorGuard& errors);
106 
107  void loadCOMPTRAJ(const DeckRecord& record,
108  const std::string& wname,
109  const ScheduleGrid& grid,
110  const KeywordLocation& location,
111  WellTrajInfo& wellTraj);
112 
113  void loadWELTRAJ(const DeckRecord& record,
114  const std::string& wname,
115  const ScheduleGrid& grid,
116  const KeywordLocation& location);
117 
118  void applyDFactorCorrelation(const ScheduleGrid& grid,
119  const WDFAC& wdfac);
120 
121  int getHeadI() const;
122  int getHeadJ() const;
123  const std::vector<double>& getMD() const;
124  std::size_t size() const;
125  bool empty() const;
126  std::size_t num_open() const;
127  const Connection& operator[](size_t index) const;
128  const Connection& get(size_t index) const;
129  const Connection& getFromIJK(const int i, const int j, const int k) const;
130  const Connection& getFromGlobalIndex(std::size_t global_index) const;
131  const Connection& lowest() const;
132  Connection& getFromIJK(const int i, const int j, const int k);
133  Connection* maybeGetFromGlobalIndex(const std::size_t global_index);
134  bool hasGlobalIndex(std::size_t global_index) const;
135  double segment_perf_length(int segment) const;
136 
137  const_iterator begin() const { return this->m_connections.begin(); }
138  const_iterator end() const { return this->m_connections.end(); }
139  auto begin() { return this->m_connections.begin(); }
140  auto end() { return this->m_connections.end(); }
141  bool allConnectionsShut() const;
154  void order();
155 
156  bool operator==( const WellConnections& ) const;
157  bool operator!=( const WellConnections& ) const;
158 
159  Connection::Order ordering() const { return this->m_ordering; }
160  std::vector<const Connection *> output(const EclipseGrid& grid) const;
161 
170  bool prepareWellPIScaling();
171 
179  void applyWellPIScaling(const double scaleFactor,
180  std::vector<bool>& scalingApplicable);
181 
182  template <class Serializer>
183  void serializeOp(Serializer& serializer)
184  {
185  serializer(this->m_ordering);
186  serializer(this->headI);
187  serializer(this->headJ);
188  serializer(this->m_connections);
189  serializer(this->coord);
190  serializer(this->md);
191  }
192 
193  private:
194  Connection::Order m_ordering { Connection::Order::TRACK };
195  int headI{0};
196  int headJ{0};
197  std::vector<Connection> m_connections{};
198 
199  std::array<std::vector<double>, 3> coord{};
200  std::vector<double> md{};
201 
202  void addConnection(const int i, const int j, const int k,
203  const std::size_t global_index,
204  const int complnum,
205  const Connection::State state,
206  const double depth,
207  const Connection::CTFProperties& ctf_props,
208  const int satTableId,
209  const Connection::Direction direction,
210  const Connection::CTFKind ctf_kind,
211  const std::size_t seqIndex,
212  int lgr_grid_number,
213  const bool defaultSatTabId);
214 
215  size_t findClosestConnection(int oi, int oj, double oz, size_t start_pos);
216  void orderTRACK();
217  void orderMSW();
218  void orderDEPTH();
219 
220  void loadCOMPDATX(const DeckRecord& record,
221  const std::string& wname,
222  const WDFAC& wdfac,
223  const ScheduleGrid& grid,
224  const KeywordLocation& location,
225  const std::optional<std::string>& lgr_label,
226  const ParseContext& parseContext,
227  ErrorGuard& errors);
228  };
229 
230  std::optional<int>
231  getCompletionNumberFromGlobalConnectionIndex(const WellConnections& connections,
232  const std::size_t global_index);
233 } // namespace Opm
234 
235 #endif // CONNECTIONSET_HPP_
Definition: Connection.hpp:52
Quantities that go into calculating the connection transmissibility factor.
Definition: Connection.hpp:90
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:62
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:370
bool prepareWellPIScaling()
Activate or reactivate WELPI scaling for this connection set.
Definition: WellConnections.cpp:360
Control parser behaviour in failure conditions.
Definition: ParseContext.hpp:114
Definition: WellConnections.hpp:48
void order()
Order connections irrespective of input order.
Definition: WellConnections.cpp:1048
Definition: DeckRecord.hpp:32
Class for (de-)serializing.
Definition: Serializer.hpp:94
Definition: ErrorGuard.hpp:30