My Project
Loading...
Searching...
No Matches
SummaryState.hpp
1/*
2 Copyright 2016 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 SUMMARY_STATE_H
21#define SUMMARY_STATE_H
22
23#include <opm/common/utility/TimeService.hpp>
24
25#include <cstddef>
26#include <ctime>
27#include <iosfwd>
28#include <optional>
29#include <set>
30#include <string>
31#include <unordered_map>
32#include <vector>
33
34namespace Opm {
35
36class UDQSet;
37
38} // namespace Opm
39
40// The purpose of the SummaryState class is to serve as a small container
41// object for computed, ready to use summary values. The values will
42// typically be used by the UDQ, WTEST and ACTIONX calculations. Observe
43// that all values are stored in the run's output unit conventions.
44//
45// The main key used to access the content of this container is the eclipse
46// style colon separated string - i.e. 'WWCT:OPX' to get the watercut in
47// well 'OPX'. The main usage of the SummaryState class is a temporary
48// holding ground while assembling data for the summary output, but it is
49// also used as a context object when evaulating the condition in ACTIONX
50// keywords. For that reason some of the data is duplicated both in the
51// general structure and a specialized structure:
52//
53// SummaryState st { start, udqUndefined };
54//
55// st.add_well_var("OPX", "WWCT", 0.75);
56// st.add("WGOR:OPY", 120);
57//
58// // The WWCT:OPX key has been added with the specialized add_well_var()
59// // method and this data is available both with the general
60// // st.has("WWCT:OPX") and the specialized st.has_well_var("OPX", "WWCT");
61// st.has("WWCT:OPX") => True
62// st.has_well_var("OPX", "WWCT") => True
63//
64// // The WGOR:OPY key is added with the general add("WGOR:OPY") and is *not*
65// // accessible through the specialized st.has_well_var("OPY", "WGOR").
66// st.has("WGOR:OPY") => True
67// st.has_well_var("OPY", "WGOR") => False
68
69namespace Opm {
70
72{
73public:
74 using const_iterator = std::unordered_map<std::string, double>::const_iterator;
75
76 explicit SummaryState(time_point sim_start_arg, double udqUndefined);
77
78 // The std::time_t constructor is only for export to Python
79 explicit SummaryState(std::time_t sim_start_arg);
80
81 // Only used for testing purposes.
82 SummaryState() : SummaryState(std::time_t{0}) {}
83 ~SummaryState() = default;
84
85 // The canonical way to update the SummaryState is through the
86 // update_xxx() methods which will inspect the variable and either
87 // accumulate or just assign, depending on whether it represents a total
88 // or not. The set() method is low level and unconditionally do an
89 // assignment.
90 void set(const std::string& key, double value);
91
92 bool erase(const std::string& key);
93 bool erase_well_var(const std::string& well, const std::string& var);
94 bool erase_group_var(const std::string& group, const std::string& var);
95
96 bool has(const std::string& key) const;
97 bool has_well_var(const std::string& well, const std::string& var) const;
98 bool has_well_var(const std::string& var) const;
99 bool has_group_var(const std::string& group, const std::string& var) const;
100 bool has_group_var(const std::string& var) const;
101 bool has_conn_var(const std::string& well, const std::string& var, std::size_t global_index) const;
102 bool has_segment_var(const std::string& well, const std::string& var, std::size_t segment) const;
103 bool has_region_var(const std::string& regSet, const std::string& var, std::size_t region) const;
104
105 void update(const std::string& key, double value);
106 void update_well_var(const std::string& well, const std::string& var, double value);
107 void update_group_var(const std::string& group, const std::string& var, double value);
108 void update_elapsed(double delta);
109 void update_udq(const UDQSet& udq_set);
110 void update_conn_var(const std::string& well, const std::string& var, std::size_t global_index, double value);
111 void update_segment_var(const std::string& well, const std::string& var, std::size_t segment, double value);
112 void update_region_var(const std::string& regSet, const std::string& var, std::size_t region, double value);
113
114 double get(const std::string&) const;
115 double get(const std::string&, double) const;
116 double get_elapsed() const;
117 double get_well_var(const std::string& well, const std::string& var) const;
118 double get_group_var(const std::string& group, const std::string& var) const;
119 double get_conn_var(const std::string& conn, const std::string& var, std::size_t global_index) const;
120 double get_segment_var(const std::string& well, const std::string& var, std::size_t segment) const;
121 double get_region_var(const std::string& regSet, const std::string& var, std::size_t region) const;
122 double get_well_var(const std::string& well, const std::string& var, double) const;
123 double get_group_var(const std::string& group, const std::string& var, double) const;
124 double get_conn_var(const std::string& conn, const std::string& var, std::size_t global_index, double) const;
125 double get_segment_var(const std::string& well, const std::string& var, std::size_t segment, double) const;
126 double get_region_var(const std::string& regSet, const std::string& var, std::size_t region, double) const;
127
128 bool is_undefined_value(const double val) const { return val == udq_undefined; }
129
130 const std::vector<std::string>& wells() const;
131 std::vector<std::string> wells(const std::string& var) const;
132 const std::vector<std::string>& groups() const;
133 std::vector<std::string> groups(const std::string& var) const;
134 void append(const SummaryState& buffer);
135 const_iterator begin() const;
136 const_iterator end() const;
137 std::size_t num_wells() const;
138 std::size_t size() const;
139 bool operator==(const SummaryState& other) const;
140
141 template<class Serializer>
142 void serializeOp(Serializer& serializer)
143 {
144 serializer(sim_start);
145 serializer(this->udq_undefined);
146 serializer(elapsed);
147 serializer(values);
148 serializer(well_values);
149 serializer(m_wells);
150 serializer(well_names);
151 serializer(group_values);
152 serializer(m_groups);
153 serializer(group_names);
154 serializer(conn_values);
155 serializer(segment_values);
156 serializer(this->region_values);
157 }
158
159 static SummaryState serializationTestObject();
160
161private:
162 time_point sim_start;
163 double udq_undefined{};
164 double elapsed = 0;
165 std::unordered_map<std::string,double> values;
166
167 // The first key is the variable and the second key is the well.
168 std::unordered_map<std::string, std::unordered_map<std::string, double>> well_values;
169 std::set<std::string> m_wells;
170 mutable std::optional<std::vector<std::string>> well_names;
171
172 // The first key is the variable and the second key is the group.
173 std::unordered_map<std::string, std::unordered_map<std::string, double>> group_values;
174 std::set<std::string> m_groups;
175 mutable std::optional<std::vector<std::string>> group_names;
176
177 // The first key is the variable and the second key is the well and the
178 // third is the global index. NB: The global_index has offset 1!
179 std::unordered_map<std::string, std::unordered_map<std::string, std::unordered_map<std::size_t, double>>> conn_values;
180
181 // The first key is the variable and the second key is the well and the
182 // third is the one-based segment number.
183 std::unordered_map<std::string, std::unordered_map<std::string, std::unordered_map<std::size_t, double>>> segment_values;
184
185 // First key is variable (e.g., ROIP), second key is region set (e.g.,
186 // FIPNUM, FIPABC), and the third key is the one-based region number.
187 std::unordered_map<std::string, std::unordered_map<std::string, std::unordered_map<std::size_t, double>>> region_values;
188};
189
190std::ostream& operator<<(std::ostream& stream, const SummaryState& st);
191
192} // namespace Opm
193
194#endif // SUMMARY_STATE_H
Class for (de-)serializing.
Definition Serializer.hpp:94
Definition SummaryState.hpp:72
Definition UDQSet.hpp:187
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30