opm-common
UDQSet.hpp
1 /*
2  Copyright 2019 Equinor 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 UDQSET_HPP
21 #define UDQSET_HPP
22 
23 #include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
24 
25 #include <cstddef>
26 #include <optional>
27 #include <stdexcept>
28 #include <string>
29 #include <unordered_map>
30 #include <vector>
31 
32 namespace Opm {
33  class RegionSetMatchResult;
34  class SegmentSet;
35 } // namespace Opm
36 
37 namespace Opm {
38 
39 class UDQScalar
40 {
41 public:
42  UDQScalar() = default;
43 
51  explicit UDQScalar(const double value, const std::size_t num = 0);
52 
62  explicit UDQScalar(const std::string& wgname, const std::size_t num = 0);
63 
70  void operator+=(const UDQScalar& rhs);
71 
78  void operator+=(double rhs);
79 
86  void operator*=(const UDQScalar& rhs);
87 
94  void operator*=(double rhs);
95 
102  void operator/=(const UDQScalar& rhs);
103 
110  void operator/=(double rhs);
111 
118  void operator-=(const UDQScalar& rhs);
119 
126  void operator-=(double rhs);
127 
131  operator bool() const;
132 
137  void assign(const std::optional<double>& value);
138 
143  void assign(double value);
144 
146  bool defined() const;
147 
151  double get() const;
152 
156  const std::optional<double>& value() const { return this->m_value; }
157 
159  const std::string& wgname() const { return this->m_wgname; }
160 
165  std::size_t number() const { return this->m_num; }
166 
171  bool operator==(const UDQScalar& other) const;
172 
173 public:
175  std::optional<double> m_value{};
176 
178  std::string m_wgname{};
179 
182  std::size_t m_num = 0;
183 };
184 
185 
186 class UDQSet
187 {
188 public:
189  // Connections and segments.
191  {
192  std::string name{};
193  std::vector<std::size_t> numbers{};
194 
195  bool operator==(const EnumeratedItems& rhs) const;
196  static EnumeratedItems serializationTestObject();
197 
198  template <class Serializer>
199  void serializeOp(Serializer& serializer)
200  {
201  serializer(this->name);
202  serializer(this->numbers);
203  }
204  };
205 
206  static std::vector<EnumeratedItems>
207  enumerateItems(const RegionSetMatchResult& regionSet);
208 
209  static std::vector<EnumeratedItems>
210  enumerateItems(const SegmentSet& segmentSet);
211 
217  UDQSet(const std::string& name, UDQVarType var_type);
218 
227  UDQSet(const std::string& name, UDQVarType var_type,
228  const std::vector<std::string>& wgnames);
229 
240  UDQSet(const std::string& name, UDQVarType var_type,
241  const std::vector<EnumeratedItems>& items);
242 
248  UDQSet(const std::string& name, UDQVarType var_type, std::size_t size);
249 
254  UDQSet(const std::string& name, std::size_t size);
255 
263  static UDQSet scalar(const std::string& name,
264  const std::optional<double>& scalar_value);
265 
272  static UDQSet scalar(const std::string& name, double value);
273 
277  static UDQSet empty(const std::string& name);
278 
284  static UDQSet wells(const std::string& name,
285  const std::vector<std::string>& wells);
286 
296  static UDQSet wells(const std::string& name,
297  const std::vector<std::string>& wells,
298  double scalar_value);
299 
305  static UDQSet groups(const std::string& name,
306  const std::vector<std::string>& groups);
307 
317  static UDQSet groups(const std::string& name,
318  const std::vector<std::string>& groups,
319  double scalar_value);
320 
328  static UDQSet field(const std::string& name, double scalar_value);
329 
330  static UDQSet segments(const std::string& name,
331  const std::vector<EnumeratedItems>& segments);
332  static UDQSet segments(const std::string& name,
333  const std::vector<EnumeratedItems>& segments,
334  const double scalar_value);
335 
336  static UDQSet regions(const std::string& name,
337  const std::vector<EnumeratedItems>& regSetColl);
338  static UDQSet regions(const std::string& name,
339  const std::vector<EnumeratedItems>& regSetColl,
340  const double scalar_value);
341 
346  void assign(const std::optional<double>& value);
347 
355  void assign(std::size_t index, const std::optional<double>& value);
356 
363  void assign(const std::string& wgname, const std::optional<double>& value);
364 
374  void assign(const std::string& wgname, std::size_t number, const std::optional<double>& value);
375 
380  void assign(double value);
381 
389  void assign(std::size_t index, double value);
390 
397  void assign(const std::string& wgname, double value);
398 
400  bool has(const std::string& name) const;
401 
404  std::size_t size() const;
405 
412  void operator+=(const UDQSet& rhs);
413 
417  void operator+=(double rhs);
418 
425  void operator-=(const UDQSet& rhs);
426 
430  void operator-=(double rhs);
431 
438  void operator*=(const UDQSet& rhs);
439 
443  void operator*=(double rhs);
444 
451  void operator/=(const UDQSet& rhs);
452 
456  void operator/=(double rhs);
457 
463  const UDQScalar& operator[](std::size_t index) const;
464 
470  const UDQScalar& operator[](const std::string& wgname) const;
471 
482  const UDQScalar& operator()(const std::string& well, const std::size_t item) const;
483 
485  std::vector<UDQScalar>::const_iterator begin() const;
486 
488  std::vector<UDQScalar>::const_iterator end() const;
489 
491  std::vector<std::string> wgnames() const;
492 
494  std::vector<double> defined_values() const;
495 
497  std::size_t defined_size() const;
498 
500  const std::string& name() const;
501 
503  void name(const std::string& name);
504 
507  UDQVarType var_type() const;
508 
512  bool operator==(const UDQSet& other) const;
513 
514 private:
516  std::string m_name;
517 
519  UDQVarType m_var_type = UDQVarType::NONE;
520 
522  std::vector<UDQScalar> values;
523 
525  UDQSet() = default;
526 };
527 
528 
529 UDQScalar operator+(const UDQScalar& lhs, const UDQScalar& rhs);
530 UDQScalar operator+(const UDQScalar& lhs, double rhs);
531 UDQScalar operator+(double lhs, const UDQScalar& rhs);
532 
533 UDQScalar operator-(const UDQScalar& lhs, const UDQScalar& rhs);
534 UDQScalar operator-(const UDQScalar& lhs, double rhs);
535 UDQScalar operator-(double lhs, const UDQScalar& rhs);
536 
537 UDQScalar operator*(const UDQScalar& lhs, const UDQScalar& rhs);
538 UDQScalar operator*(const UDQScalar& lhs, double rhs);
539 UDQScalar operator*(double lhs, const UDQScalar& rhs);
540 
541 UDQScalar operator/(const UDQScalar& lhs, const UDQScalar& rhs);
542 UDQScalar operator/(const UDQScalar& lhs, double rhs);
543 UDQScalar operator/(double lhs, const UDQScalar& rhs);
544 
545 UDQSet operator+(const UDQSet& lhs, const UDQSet& rhs);
546 UDQSet operator+(const UDQSet& lhs, double rhs);
547 UDQSet operator+(double lhs, const UDQSet& rhs);
548 
549 UDQSet operator-(const UDQSet& lhs, const UDQSet& rhs);
550 UDQSet operator-(const UDQSet& lhs, double rhs);
551 UDQSet operator-(double lhs, const UDQSet& rhs);
552 
553 UDQSet operator*(const UDQSet& lhs, const UDQSet& rhs);
554 UDQSet operator*(const UDQSet& lhs, double rhs);
555 UDQSet operator*(double lhs, const UDQSet& rhs);
556 
557 UDQSet operator/(const UDQSet& lhs, const UDQSet& rhs);
558 UDQSet operator/(const UDQSet& lhs, double rhs);
559 UDQSet operator/(double lhs, const UDQSet&rhs);
560 
561 } // namespace Opm
562 
563 #endif // UDQSET_HPP
bool operator==(const UDQSet &other) const
Equality comparison operator.
Definition: UDQSet.cpp:778
const std::string & wgname() const
Retrive named well/group to which this scalar is associated.
Definition: UDQSet.hpp:159
std::optional< double > m_value
Scalar value.
Definition: UDQSet.hpp:175
std::vector< std::string > wgnames() const
Retrive names of entities associate to this UDQ set.
Definition: UDQSet.cpp:400
void operator+=(const UDQSet &rhs)
Add other UDQ set into this.
Definition: UDQSet.cpp:413
bool operator==(const UDQScalar &other) const
Equality predicate.
Definition: UDQSet.cpp:141
Definition: UDQSet.hpp:39
std::vector< UDQScalar >::const_iterator end() const
Range-for traversal support (one past end of range)
Definition: UDQSet.cpp:538
std::string m_wgname
Associated well/group name.
Definition: UDQSet.hpp:178
void operator-=(const UDQSet &rhs)
Subtract UDQ set from this.
Definition: UDQSet.cpp:431
const UDQScalar & operator[](std::size_t index) const
Access individual UDQ scalar at particular index in UDQ set.
Definition: UDQSet.cpp:491
std::size_t size() const
Number of elements in UDQ set.
Definition: UDQSet.cpp:313
const UDQScalar & operator()(const std::string &well, const std::size_t item) const
Access individual UDQ scalar assiociated to particular named well and numbered sub-entity of that nam...
Definition: UDQSet.cpp:514
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
const std::optional< double > & value() const
Retrive contained numeric value.
Definition: UDQSet.hpp:156
std::size_t number() const
Retrive numbered item, typically segment or connection, to which this scalar is associated.
Definition: UDQSet.hpp:165
std::vector< UDQScalar >::const_iterator begin() const
Range-for traversal support (beginning of range)
Definition: UDQSet.cpp:533
Result Set From SegmentMatcher&#39;s Matching Process.
Definition: SegmentMatcher.hpp:42
Result Set From RegionSetMatcher&#39;s Matching Process.
Definition: RegionSetMatcher.hpp:43
Definition: UDQSet.hpp:186
void operator/=(const UDQScalar &rhs)
Divide this UDQ scalar by other.
Definition: UDQSet.cpp:100
std::vector< double > defined_values() const
Retrive the UDQ set&#39;s defined values only.
Definition: UDQSet.cpp:471
bool has(const std::string &name) const
Predicate for whether or not named UDQ element exists.
Definition: UDQSet.cpp:306
static UDQSet empty(const std::string &name)
Form an empty UDQ set.
Definition: UDQSet.cpp:234
std::size_t m_num
Numbered item.
Definition: UDQSet.hpp:182
void assign(const std::optional< double > &value)
Assign numeric value to this UDQ scalar.
Definition: UDQSet.cpp:68
UDQVarType var_type() const
Retrive the variable type of this UDQ set (e.g., well, group, field, segment &c). ...
Definition: UDQSet.cpp:395
void assign(const std::optional< double > &value)
Assign value to every element of the UDQ set.
Definition: UDQSet.cpp:384
void operator/=(const UDQSet &rhs)
Divide this UDQ set by other UDQ set.
Definition: UDQSet.cpp:453
static UDQSet scalar(const std::string &name, const std::optional< double > &scalar_value)
Form a UDQ set pertaining to a single scalar value.
Definition: UDQSet.cpp:226
static UDQSet groups(const std::string &name, const std::vector< std::string > &groups)
Form a UDQ set pertaining to a set of named groups.
Definition: UDQSet.cpp:261
std::size_t defined_size() const
Retrive the UDQ set&#39;s number of defined values.
Definition: UDQSet.cpp:484
static UDQSet wells(const std::string &name, const std::vector< std::string > &wells)
Form a UDQ set pertaining to a set of named wells.
Definition: UDQSet.cpp:246
bool defined() const
Predicate for whether or not this UDQ scalar has a defined value.
Definition: UDQSet.cpp:51
static UDQSet field(const std::string &name, double scalar_value)
Form a UDQ set at the field level.
Definition: UDQSet.cpp:239
const std::string & name() const
Retrive the name of this UDQ set.
Definition: UDQSet.cpp:164
void operator-=(const UDQScalar &rhs)
Subtract other UDQ scalar from this.
Definition: UDQSet.cpp:88
void operator*=(const UDQSet &rhs)
Multiply other UDQ set into this.
Definition: UDQSet.cpp:435
Class for (de-)serializing.
Definition: Serializer.hpp:94
void operator*=(const UDQScalar &rhs)
Multiply UDQ scalar into this.
Definition: UDQSet.cpp:124
Definition: UDQSet.hpp:190
void operator+=(const UDQScalar &rhs)
Add other UDQ scalar to this.
Definition: UDQSet.cpp:112