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
79 // The canonical way to update the SummaryState is through the
80 // update_xxx() methods which will inspect the variable and either
81 // accumulate or just assign, depending on whether it represents a total
82 // or not. The set() method is low level and unconditionally do an
83 // assignment.
84 void set(const std::string& key, double value);
85
86 bool erase(const std::string& key);
87 bool erase_well_var(const std::string& well, const std::string& var);
88 bool erase_group_var(const std::string& group, const std::string& var);
89
90 bool has(const std::string& key) const;
91 bool has_well_var(const std::string& well, const std::string& var) const;
92 bool has_well_var(const std::string& var) const;
93 bool has_group_var(const std::string& group, const std::string& var) const;
94 bool has_group_var(const std::string& var) const;
95 bool has_conn_var(const std::string& well, const std::string& var, std::size_t global_index) const;
96 bool has_segment_var(const std::string& well, const std::string& var, std::size_t segment) const;
97
98 void update(const std::string& key, double value);
99 void update_well_var(const std::string& well, const std::string& var, double value);
100 void update_group_var(const std::string& group, const std::string& var, double value);
101 void update_elapsed(double delta);
102 void update_udq(const UDQSet& udq_set, double undefined_value);
103 void update_conn_var(const std::string& well, const std::string& var, std::size_t global_index, double value);
104 void update_segment_var(const std::string& well, const std::string& var, std::size_t segment, double value);
105
106 double get(const std::string&) const;
107 double get(const std::string&, double) const;
108 double get_elapsed() const;
109 double get_well_var(const std::string& well, const std::string& var) const;
110 double get_group_var(const std::string& group, const std::string& var) const;
111 double get_conn_var(const std::string& conn, const std::string& var, std::size_t global_index) const;
112 double get_segment_var(const std::string& well, const std::string& var, std::size_t segment) const;
113 double get_well_var(const std::string& well, const std::string& var, double) const;
114 double get_group_var(const std::string& group, const std::string& var, double) const;
115 double get_conn_var(const std::string& conn, const std::string& var, std::size_t global_index, double) const;
116 double get_segment_var(const std::string& well, const std::string& var, std::size_t segment, double) const;
117
118 const std::vector<std::string>& wells() const;
119 std::vector<std::string> wells(const std::string& var) const;
120 const std::vector<std::string>& groups() const;
121 std::vector<std::string> groups(const std::string& var) const;
122 void append(const SummaryState& buffer);
123 const_iterator begin() const;
124 const_iterator end() const;
125 std::size_t num_wells() const;
126 std::size_t size() const;
127 bool operator==(const SummaryState& other) const;
128
129 template<class Serializer>
130 void serializeOp(Serializer& serializer)
131 {
132 serializer(sim_start);
133 serializer(elapsed);
134 serializer(values);
135 serializer(well_values);
136 serializer(m_wells);
137 serializer(well_names);
138 serializer(group_values);
139 serializer(m_groups);
140 serializer(group_names);
141 serializer(conn_values);
142 serializer(segment_values);
143 }
144
145 static SummaryState serializationTestObject();
146
147private:
148 time_point sim_start;
149 double elapsed = 0;
150 std::unordered_map<std::string,double> values;
151
152 // The first key is the variable and the second key is the well.
153 std::unordered_map<std::string, std::unordered_map<std::string, double>> well_values;
154 std::set<std::string> m_wells;
155 mutable std::optional<std::vector<std::string>> well_names;
156
157 // The first key is the variable and the second key is the group.
158 std::unordered_map<std::string, std::unordered_map<std::string, double>> group_values;
159 std::set<std::string> m_groups;
160 mutable std::optional<std::vector<std::string>> group_names;
161
162 // The first key is the variable and the second key is the well and the
163 // third is the global index. NB: The global_index has offset 1!
164 std::unordered_map<std::string, std::unordered_map<std::string, std::unordered_map<std::size_t, double>>> conn_values;
165
166 // The first key is the variable and the second key is the well and the
167 // third is the one-based segment number.
168 std::unordered_map<std::string, std::unordered_map<std::string, std::unordered_map<std::size_t, double>>> segment_values;
169};
170
171std::ostream& operator<<(std::ostream& stream, const SummaryState& st);
172
173} // namespace Opm
174
175#endif // SUMMARY_STATE_H
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition SummaryState.hpp:68
Definition UDQSet.hpp:186
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30