My Project
Loading...
Searching...
No Matches
TranCalculator.hpp
1/*
2 Copyright 2020 Equinor AS.
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#ifndef TRAN_CALCULATOR_HPP
20#define TRAN_CALCULATOR_HPP
21
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26namespace Opm
27{
28
29namespace Fieldprops
30{
31
32namespace keywords { template<class T> struct keyword_info; }
33
34enum class ScalarOperation {
35 ADD = 1,
36 EQUAL = 2,
37 MUL = 3,
38 MIN = 4,
39 MAX = 5
40};
41
42
44public:
45
46 struct TranAction {
47 ScalarOperation op;
48 std::string field;
49
50 bool operator==(const TranAction& other) const {
51 return this->op == other.op &&
52 this->field == other.field;
53 }
54
55 template<class Serializer>
56 void serializeOp(Serializer& serializer)
57 {
58 serializer(op);
59 serializer(field);
60 }
61 };
62
63
64 explicit TranCalculator(const std::string& name_arg) :
65 m_name(name_arg)
66 {}
67
68 TranCalculator() = default;
69
70 std::string next_name() const {
71 return this->m_name + std::to_string( this->actions.size() );
72 }
73
74 std::vector<TranAction>::const_iterator begin() const {
75 return this->actions.begin();
76 }
77
78 std::vector<TranAction>::const_iterator end() const {
79 return this->actions.end();
80 }
81
82 void add_action(ScalarOperation op, const std::string& field) {
83 this->actions.push_back(TranAction{op, field});
84 }
85
86 std::size_t size() const {
87 return this->actions.size();
88 }
89
90 const std::string& name() const {
91 return this->m_name;
92 }
93
94 keywords::keyword_info<double> make_kw_info(ScalarOperation op);
95
96 bool operator==(const TranCalculator& other) const {
97 return this->m_name == other.m_name &&
98 this->actions == other.actions;
99 }
100
101 template<class Serializer>
102 void serializeOp(Serializer& serializer)
103 {
104 serializer(m_name);
105 serializer(actions);
106 }
107
108 static TranCalculator serializationTestObject()
109 {
110 TranCalculator tran("test");
111 tran.add_action(ScalarOperation::MIN, "FGOP");
112 return tran;
113 }
114
115private:
116 std::string m_name;
117 std::vector<TranAction> actions;
118};
119
120} // namespace Fieldprops
121} // end namespace Opm
122#endif // TRAN_CALCULATOR_HPP
Definition TranCalculator.hpp:43
Class for (de-)serializing.
Definition Serializer.hpp:84
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition TranCalculator.hpp:46