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