My Project
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
32namespace Opm {
33
35{
36public:
37 UDQScalar() = default;
38
46 explicit UDQScalar(const double value, const std::size_t num = 0);
47
57 explicit UDQScalar(const std::string& wgname, const std::size_t num = 0);
58
65 void operator+=(const UDQScalar& rhs);
66
73 void operator+=(double rhs);
74
81 void operator*=(const UDQScalar& rhs);
82
89 void operator*=(double rhs);
90
97 void operator/=(const UDQScalar& rhs);
98
105 void operator/=(double rhs);
106
113 void operator-=(const UDQScalar& rhs);
114
121 void operator-=(double rhs);
122
126 operator bool() const;
127
132 void assign(const std::optional<double>& value);
133
138 void assign(double value);
139
141 bool defined() const;
142
146 double get() const;
147
151 const std::optional<double>& value() const { return this->m_value; }
152
154 const std::string& wgname() const { return this->m_wgname; }
155
160 std::size_t number() const { return this->m_num; }
161
166 bool operator==(const UDQScalar& other) const;
167
168public:
170 std::optional<double> m_value{};
171
173 std::string m_wgname{};
174
177 std::size_t m_num = 0;
178};
179
180
182{
183public:
184 // Connections and segments.
186 std::string well{};
187 std::vector<std::size_t> numbers{};
188
189 bool operator==(const EnumeratedWellItems& rhs) const;
190 static EnumeratedWellItems serializationTestObject();
191
192 template <class Serializer>
193 void serializeOp(Serializer& serializer)
194 {
195 serializer(this->well);
196 serializer(this->numbers);
197 }
198 };
199
205 UDQSet(const std::string& name, UDQVarType var_type);
206
215 UDQSet(const std::string& name, UDQVarType var_type, const std::vector<std::string>& wgnames);
216
227 UDQSet(const std::string& name, UDQVarType var_type, const std::vector<EnumeratedWellItems>& items);
228
233 UDQSet(const std::string& name, UDQVarType var_type, std::size_t size);
234
239 UDQSet(const std::string& name, std::size_t size);
240
248 static UDQSet scalar(const std::string& name, const std::optional<double>& scalar_value);
249
256 static UDQSet scalar(const std::string& name, double value);
257
261 static UDQSet empty(const std::string& name);
262
268 static UDQSet wells(const std::string& name, const std::vector<std::string>& wells);
269
279 static UDQSet wells(const std::string& name, const std::vector<std::string>& wells, double scalar_value);
280
286 static UDQSet groups(const std::string& name, const std::vector<std::string>& groups);
287
297 static UDQSet groups(const std::string& name, const std::vector<std::string>& groups, double scalar_value);
298
306 static UDQSet field(const std::string& name, double scalar_value);
307
312 void assign(const std::optional<double>& value);
313
321 void assign(std::size_t index, const std::optional<double>& value);
322
329 void assign(const std::string& wgname, const std::optional<double>& value);
330
340 void assign(const std::string& wgname, std::size_t number, const std::optional<double>& value);
341
346 void assign(double value);
347
355 void assign(std::size_t index, double value);
356
363 void assign(const std::string& wgname, double value);
364
366 bool has(const std::string& name) const;
367
370 std::size_t size() const;
371
378 void operator+=(const UDQSet& rhs);
379
383 void operator+=(double rhs);
384
391 void operator-=(const UDQSet& rhs);
392
396 void operator-=(double rhs);
397
404 void operator*=(const UDQSet& rhs);
405
409 void operator*=(double rhs);
410
417 void operator/=(const UDQSet& rhs);
418
422 void operator/=(double rhs);
423
429 const UDQScalar& operator[](std::size_t index) const;
430
436 const UDQScalar& operator[](const std::string& wgname) const;
437
448 const UDQScalar& operator()(const std::string& well, const std::size_t item) const;
449
451 std::vector<UDQScalar>::const_iterator begin() const;
452
454 std::vector<UDQScalar>::const_iterator end() const;
455
457 std::vector<std::string> wgnames() const;
458
460 std::vector<double> defined_values() const;
461
463 std::size_t defined_size() const;
464
466 const std::string& name() const;
467
469 void name(const std::string& name);
470
473 UDQVarType var_type() const;
474
478 bool operator==(const UDQSet& other) const;
479
480private:
482 std::string m_name;
483
485 UDQVarType m_var_type = UDQVarType::NONE;
486
488 std::vector<UDQScalar> values;
489
491 UDQSet() = default;
492};
493
494
495UDQScalar operator+(const UDQScalar& lhs, const UDQScalar& rhs);
496UDQScalar operator+(const UDQScalar& lhs, double rhs);
497UDQScalar operator+(double lhs, const UDQScalar& rhs);
498
499UDQScalar operator-(const UDQScalar& lhs, const UDQScalar& rhs);
500UDQScalar operator-(const UDQScalar& lhs, double rhs);
501UDQScalar operator-(double lhs, const UDQScalar& rhs);
502
503UDQScalar operator*(const UDQScalar& lhs, const UDQScalar& rhs);
504UDQScalar operator*(const UDQScalar& lhs, double rhs);
505UDQScalar operator*(double lhs, const UDQScalar& rhs);
506
507UDQScalar operator/(const UDQScalar& lhs, const UDQScalar& rhs);
508UDQScalar operator/(const UDQScalar& lhs, double rhs);
509UDQScalar operator/(double lhs, const UDQScalar& rhs);
510
511UDQSet operator+(const UDQSet& lhs, const UDQSet& rhs);
512UDQSet operator+(const UDQSet& lhs, double rhs);
513UDQSet operator+(double lhs, const UDQSet& rhs);
514
515UDQSet operator-(const UDQSet& lhs, const UDQSet& rhs);
516UDQSet operator-(const UDQSet& lhs, double rhs);
517UDQSet operator-(double lhs, const UDQSet& rhs);
518
519UDQSet operator*(const UDQSet& lhs, const UDQSet& rhs);
520UDQSet operator*(const UDQSet& lhs, double rhs);
521UDQSet operator*(double lhs, const UDQSet& rhs);
522
523UDQSet operator/(const UDQSet& lhs, const UDQSet& rhs);
524UDQSet operator/(const UDQSet& lhs, double rhs);
525UDQSet operator/(double lhs, const UDQSet&rhs);
526
527} // namespace Opm
528
529#endif // UDQSET_HPP
Class for (de-)serializing.
Definition: Serializer.hpp:84
Definition: UDQSet.hpp:35
void operator/=(const UDQScalar &rhs)
Divide this UDQ scalar by other.
UDQScalar(const double value, const std::size_t num=0)
Constructor.
void operator-=(const UDQScalar &rhs)
Subtract other UDQ scalar from this.
void operator/=(double rhs)
Divide this UDQ scalar by numeric value.
const std::optional< double > & value() const
Retrive contained numeric value.
Definition: UDQSet.hpp:151
void assign(const std::optional< double > &value)
Assign numeric value to this UDQ scalar.
std::size_t number() const
Retrive numbered item, typically segment or connection, to which this scalar is associated.
Definition: UDQSet.hpp:160
void operator+=(const UDQScalar &rhs)
Add other UDQ scalar to this.
void assign(double value)
Assign numeric value to this UDQ scalar.
std::optional< double > m_value
Scalar value.
Definition: UDQSet.hpp:170
void operator+=(double rhs)
Add numeric value to this UDQ scalar.
void operator*=(double rhs)
Multiply numeric value into this.
const std::string & wgname() const
Retrive named well/group to which this scalar is associated.
Definition: UDQSet.hpp:154
void operator*=(const UDQScalar &rhs)
Multiply UDQ scalar into this.
bool operator==(const UDQScalar &other) const
Equality predicate.
std::string m_wgname
Associated well/group name.
Definition: UDQSet.hpp:173
bool defined() const
Predicate for whether or not this UDQ scalar has a defined value.
UDQScalar(const std::string &wgname, const std::size_t num=0)
Constructor.
std::size_t m_num
Numbered item.
Definition: UDQSet.hpp:177
double get() const
Retrive contained numeric value.
void operator-=(double rhs)
Add other UDQ scalar to this.
Definition: UDQSet.hpp:182
std::vector< UDQScalar >::const_iterator begin() const
Range-for traversal support (beginning of range)
void assign(const std::string &wgname, double value)
Assign value to specific element of the UDQ set.
void operator-=(double rhs)
Subtract numeric values from all defined elements of this UDQ set.
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...
void operator*=(double rhs)
Multiply every defined element with numeric element.
void operator-=(const UDQSet &rhs)
Subtract UDQ set from this.
static UDQSet groups(const std::string &name, const std::vector< std::string > &groups, double scalar_value)
Form a UDQ set pertaining to a set of named groups.
void operator+=(const UDQSet &rhs)
Add other UDQ set into this.
const UDQScalar & operator[](std::size_t index) const
Access individual UDQ scalar at particular index in UDQ set.
const std::string & name() const
Retrive the name of this UDQ set.
UDQSet(const std::string &name, std::size_t size)
Construct empty, named UDQ set of specific variable type.
void assign(double value)
Assign value to every element of the UDQ set.
UDQSet(const std::string &name, UDQVarType var_type, const std::vector< std::string > &wgnames)
Construct named UDQ set of specific variable type for particular set of well/group names.
void operator/=(double rhs)
Divide every defined element with numeric element.
std::vector< double > defined_values() const
Retrive the UDQ set's defined values only.
void operator+=(double rhs)
Add numeric value to all defined elements of this UDQ set.
std::vector< std::string > wgnames() const
Retrive names of entities associate to this UDQ set.
std::vector< UDQScalar >::const_iterator end() const
Range-for traversal support (one past end of range)
UDQSet(const std::string &name, UDQVarType var_type, const std::vector< EnumeratedWellItems > &items)
Construct named UDQ set of specific variable type for numbered well items-typically segments or conne...
static UDQSet empty(const std::string &name)
Form an empty UDQ set.
bool operator==(const UDQSet &other) const
Equality comparison operator.
UDQSet(const std::string &name, UDQVarType var_type, std::size_t size)
Construct empty, named UDQ set of specific variable type.
void operator*=(const UDQSet &rhs)
Multiply other UDQ set into this.
void name(const std::string &name)
Assign the name of this UDQ set.
static UDQSet scalar(const std::string &name, double value)
Form a UDQ set pertaining to a single scalar value.
UDQSet(const std::string &name, UDQVarType var_type)
Construct empty, named UDQ set of specific variable type.
static UDQSet scalar(const std::string &name, const std::optional< double > &scalar_value)
Form a UDQ set pertaining to a single scalar value.
void assign(const std::string &wgname, std::size_t number, const std::optional< double > &value)
Assign value to specific element of the UDQ set.
void assign(std::size_t index, const std::optional< double > &value)
Assign value to specific element of the UDQ set.
UDQVarType var_type() const
Retrive the variable type of this UDQ set (e.g., well, group, field, segment &c).
bool has(const std::string &name) const
Predicate for whether or not named UDQ element exists.
static UDQSet wells(const std::string &name, const std::vector< std::string > &wells)
Form a UDQ set pertaining to a set of named wells.
std::size_t defined_size() const
Retrive the UDQ set's number of defined values.
static UDQSet field(const std::string &name, double scalar_value)
Form a UDQ set at the field level.
std::size_t size() const
Number of elements in UDQ set.
void assign(const std::optional< double > &value)
Assign value to every element of the UDQ set.
void assign(std::size_t index, double value)
Assign value to specific element of the UDQ set.
static UDQSet groups(const std::string &name, const std::vector< std::string > &groups)
Form a UDQ set pertaining to a set of named groups.
void assign(const std::string &wgname, const std::optional< double > &value)
Assign value to specific element of the UDQ set.
void operator/=(const UDQSet &rhs)
Divide this UDQ set by other UDQ set.
const UDQScalar & operator[](const std::string &wgname) const
Access individual UDQ scalar assiociated to particular named entity (well or group).
static UDQSet wells(const std::string &name, const std::vector< std::string > &wells, double scalar_value)
Form a UDQ set pertaining to a set of named wells.
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: UDQSet.hpp:185