opm-common
Segment.hpp
1 /*
2  Copyright 2015 SINTEF ICT, Applied Mathematics.
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 SEGMENT_HPP_HEADER_INCLUDED
21 #define SEGMENT_HPP_HEADER_INCLUDED
22 
23 #include <opm/input/eclipse/Schedule/MSW/AICD.hpp>
24 #include <opm/input/eclipse/Schedule/MSW/SICD.hpp>
25 #include <opm/input/eclipse/Schedule/MSW/Valve.hpp>
26 
27 #include <optional>
28 #include <variant>
29 #include <vector>
30 
31 #include <cmath>
32 
33 namespace Opm { namespace RestartIO {
34  struct RstSegment;
35 }} // namespace Opm::RestartIO
36 
37 namespace Opm {
38 
39  class Segment {
40  public:
41  // Maximum relative roughness to guarantee non-singularity for Re>=4000 in Haaland friction
42  // factor calculations (see MSWellHelpers in opm-simulators).
43  // cannot be constexpr due to clang not having constexpr std::pow
44  static const double MAX_REL_ROUGHNESS; // = 3.7 * std::pow((1.0 - 1.0e-3) - 6.9/4000.0, 9. / 10.);
45 
46 
47  enum class SegmentType {
48  REGULAR,
49  SICD,
50  AICD, // Not really supported - just included to complete the enum
51  VALVE,
52  };
53 
54  Segment();
55 
56  Segment(const Segment& src, double new_depth, double new_length, double new_volume, double new_x, double new_y);
57  Segment(const Segment& src, double new_depth, double new_length, double new_x, double new_y);
58  Segment(const Segment& src, double new_depth, double new_length, double new_volume);
59  Segment(const Segment& src, double new_depth, double new_length);
60  Segment(const Segment& src, double new_volume);
61  Segment(const int segment_number_in,
62  const int branch_in,
63  const int outlet_segment_in,
64  const double depth_in,
65  const double length_in,
66  const double internal_diameter_in,
67  const double roughness_in,
68  const double cross_area_in,
69  const double volume_in,
70  const bool data_ready_in,
71  const double x_in,
72  const double y_in);
73 
74  explicit Segment(const RestartIO::RstSegment& rst_segment, const std::string& wname);
75 
76  static Segment serializationTestObject();
77 
78  int segmentNumber() const;
79  int branchNumber() const;
80  int outletSegment() const;
81  double totalLength() const;
82  double node_X() const;
83  double node_Y() const;
84  double depth() const;
85  double internalDiameter() const;
86  double roughness() const;
87  double crossArea() const;
88  double volume() const;
89  bool dataReady() const;
90 
91  SegmentType segmentType() const;
92  int ecl_type_id() const;
93 
94  const std::vector<int>& inletSegments() const;
95 
96  static double invalidValue();
97 
98  bool operator==( const Segment& ) const;
99  bool operator!=( const Segment& ) const;
100 
101  const SICD& spiralICD() const;
102  const AutoICD& autoICD() const;
103  const Valve& valve() const;
104 
105  void updateSpiralICD(const SICD& spiral_icd);
106  void updateAutoICD(const AutoICD& aicd);
107  void updateValve(const Valve& valve, const double segment_length);
108  void updateValve(const Valve& valve);
109  bool updateICDScalingFactor(const double outlet_segment_length, const double completion_length);
110  void addInletSegment(const int segment_number);
111 
112  bool isRegular() const
113  {
114  return std::holds_alternative<RegularSegment>(this->m_icd);
115  }
116 
117  inline bool isSpiralICD() const
118  {
119  return std::holds_alternative<SICD>(this->m_icd);
120  }
121 
122  inline bool isAICD() const
123  {
124  return std::holds_alternative<AutoICD>(this->m_icd);
125  }
126 
127  inline bool isValve() const
128  {
129  return std::holds_alternative<Valve>(this->m_icd);
130  }
131 
132  template<class Serializer>
133  void serializeOp(Serializer& serializer)
134  {
135  serializer(m_segment_number);
136  serializer(m_branch);
137  serializer(m_outlet_segment);
138  serializer(m_inlet_segments);
139  serializer(m_depth);
140  serializer(m_total_length);
141  serializer(m_internal_diameter);
142  serializer(m_roughness);
143  serializer(m_cross_area);
144  serializer(m_volume);
145  serializer(m_data_ready);
146  serializer(m_x);
147  serializer(m_y);
148  serializer(m_icd);
149  }
150 
151  private:
152  // The current serialization of std::variant<> requires that all the
153  // types in the variant have a serializeOp() method. We introduce
154  // this RegularSegment to meet this requirement. Ideally, the ICD
155  // variant<> would use std::monostate to represent non-ICD segments.
156  struct RegularSegment
157  {
158  template <class Serializer>
159  void serializeOp(Serializer&) {}
160 
161  static RegularSegment serializationTestObject() { return {}; }
162 
163  bool operator==(const RegularSegment&) const { return true; }
164  };
165 
166  // segment number
167  // it should work as a ID.
168  int m_segment_number;
169 
170  // branch number
171  // for top segment, it should always be 1
172  int m_branch;
173 
174  // the outlet junction segment
175  // for top segment, it should be -1
176  int m_outlet_segment;
177 
178  // the segments whose outlet segments are the current segment
179  std::vector<int> m_inlet_segments;
180 
181  // depth of the nodes to the bhp reference point
182  // when reading in from deck, with 'INC',
183  // it will be the incremental depth before processing.
184  // in the class Well, it always stores the 'ABS' value.
185  // TODO: to check if it is good to use 'ABS' always.
186  double m_depth;
187 
188  // length of the segment node to the bhp reference point.
189  // when reading in from deck, with 'INC',
190  // it will be incremental length before processing.
191  // After processing and in the class Well, it always stores the 'ABS' value.
192  // which means the total_length
193  double m_total_length;
194 
195  // tubing internal diameter
196  // or the equivalent diameter for annular cross-sections
197  // for top segment, it is UNDEFINED
198  // we use invalid_value for the top segment
199  double m_internal_diameter;
200 
201  // effective roughness of the tubing
202  // used to calculate the Fanning friction factor
203  // for top segment, it is UNDEFINED
204  // we use invalid_value for the top segment
205  double m_roughness;
206 
207  // cross-sectional area for fluid flow
208  // not defined for the top segment,
209  // we use invalid_value for the top segment.
210  double m_cross_area;
211 
212  // valume of the segment;
213  // it is defined for top segment.
214  // TODO: to check if the definition is the same with other segments.
215  double m_volume;
216 
217  // indicate if the data related to 'INC' or 'ABS' is ready
218  // the volume will be updated at a final step.
219  bool m_data_ready;
220 
221  // Length of segment projected onto the X axis. Not used in
222  // simulations, but needed for the SEG option in WRFTPLT.
223  double m_x{};
224 
225  // Length of segment projected onto the Y axis. Not used in
226  // simulations, but needed for the SEG option in WRFTPLT.
227  double m_y{};
228 
229  std::variant<RegularSegment, SICD, AutoICD, Valve> m_icd;
230 
231  // There are three other properties for the segment pertaining to
232  // thermal conduction. These are not currently supported.
233 
234  void updateValve__(Valve& valve, const double segment_length);
235  };
236 
237 }
238 
239 #endif
Definition: SICD.hpp:45
Definition: Valve.hpp:62
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: AICD.hpp:43
Definition: segment.hpp:33
Definition: Segment.hpp:39
Class for (de-)serializing.
Definition: Serializer.hpp:94