My Project
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 <chrono>
24 #include <iosfwd>
25 #include <optional>
26 #include <string>
27 #include <unordered_map>
28 #include <set>
29 #include <vector>
30 
31 #include <opm/common/utility/TimeService.hpp>
32 
33 namespace Opm {
34 
35 class UDQSet;
36 
37 /*
38  The purpose of this class is to serve as a small container object for
39  computed, ready to use summary values. The values will typically be used by
40  the UDQ, WTEST and ACTIONX calculations. Observe that all value *have been
41  converted to the correct output units*.
42 
43  The main key used to access the content of this container is the eclipse style
44  colon separated string - i.e. 'WWCT:OPX' to get the watercut in well 'OPX'.
45  The main usage of the SummaryState class is a temporary holding ground while
46  assembling data for the summary output, but it is also used as a context
47  object when evaulating the condition in ACTIONX keywords. For that reason some
48  of the data is duplicated both in the general structure and a specialized
49  structure:
50 
51  SummaryState st;
52 
53  st.add_well_var("OPX", "WWCT", 0.75);
54  st.add("WGOR:OPY", 120);
55 
56  // The WWCT:OPX key has been added with the specialized add_well_var()
57  // method and this data is available both with the general
58  // st.has("WWCT:OPX") and the specialized st.has_well_var("OPX", "WWCT");
59  st.has("WWCT:OPX") => True
60  st.has_well_var("OPX", "WWCT") => True
61 
62 
63  // The WGOR:OPY key is added with the general add("WGOR:OPY") and is *not*
64  // accessible through the specialized st.has_well_var("OPY", "WGOR").
65  st.has("WGOR:OPY") => True
66  st.has_well_var("OPY", "WGOR") => False
67 */
68 
69 class SummaryState {
70 public:
71  typedef std::unordered_map<std::string, double>::const_iterator const_iterator;
72  explicit SummaryState(time_point sim_start_arg);
73 
74  // The std::time_t constructor is only for export to Python
75  explicit SummaryState(std::time_t sim_start_arg);
76 
77  /*
78  The set() function has to be retained temporarily to support updating of
79  cumulatives from restart files.
80  */
81  void set(const std::string& key, double value);
82 
83  bool erase(const std::string& key);
84  bool erase_well_var(const std::string& well, const std::string& var);
85  bool erase_group_var(const std::string& group, const std::string& var);
86 
87  bool has(const std::string& key) const;
88  bool has_well_var(const std::string& well, const std::string& var) const;
89  bool has_well_var(const std::string& var) const;
90  bool has_group_var(const std::string& group, const std::string& var) const;
91  bool has_group_var(const std::string& var) const;
92  bool has_conn_var(const std::string& well, const std::string& var, std::size_t global_index) const;
93 
94 
95  void update(const std::string& key, double value);
96  void update_well_var(const std::string& well, const std::string& var, double value);
97  void update_group_var(const std::string& group, const std::string& var, double value);
98  void update_elapsed(double delta);
99  void update_udq(const UDQSet& udq_set, double undefined_value);
100  void update_conn_var(const std::string& well, const std::string& var, std::size_t global_index, double value);
101 
102  double get(const std::string&) const;
103  double get(const std::string&, double) const;
104  double get_elapsed() const;
105  double get_well_var(const std::string& well, const std::string& var) const;
106  double get_group_var(const std::string& group, const std::string& var) const;
107  double get_conn_var(const std::string& conn, const std::string& var, std::size_t global_index) const;
108  double get_well_var(const std::string& well, const std::string& var, double) const;
109  double get_group_var(const std::string& group, const std::string& var, double) const;
110  double get_conn_var(const std::string& conn, const std::string& var, std::size_t global_index, double) const;
111 
112  const std::vector<std::string>& wells() const;
113  std::vector<std::string> wells(const std::string& var) const;
114  const std::vector<std::string>& groups() const;
115  std::vector<std::string> groups(const std::string& var) const;
116  std::vector<char> serialize() const;
117  void deserialize(const std::vector<char>& buffer);
118  const_iterator begin() const;
119  const_iterator end() const;
120  std::size_t num_wells() const;
121  std::size_t size() const;
122  bool operator==(const SummaryState& other) const;
123 private:
124  time_point sim_start;
125  double elapsed = 0;
126  std::unordered_map<std::string,double> values;
127 
128  // The first key is the variable and the second key is the well.
129  std::unordered_map<std::string, std::unordered_map<std::string, double>> well_values;
130  std::set<std::string> m_wells;
131  mutable std::optional<std::vector<std::string>> well_names;
132 
133  // The first key is the variable and the second key is the group.
134  std::unordered_map<std::string, std::unordered_map<std::string, double>> group_values;
135  std::set<std::string> m_groups;
136  mutable std::optional<std::vector<std::string>> group_names;
137 
138  // The first key is the variable and the second key is the well and the
139  // third is the global index. NB: The global_index has offset 1!
140  std::unordered_map<std::string, std::unordered_map<std::string, std::unordered_map<std::size_t, double>>> conn_values;
141 };
142 
143 
144 std::ostream& operator<<(std::ostream& stream, const SummaryState& st);
145 
146 }
147 #endif
Definition: SummaryState.hpp:69
Definition: UDQSet.hpp:66
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29