My Project
UDQConfig.hpp
1 /*
2  Copyright 2019 Equinor 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 UDQINPUT_HPP_
21 #define UDQINPUT_HPP_
22 
23 #include <string>
24 #include <unordered_map>
25 #include <map>
26 #include <unordered_set>
27 
28 #include <opm/input/eclipse/Schedule/UDQ/UDQInput.hpp>
29 #include <opm/input/eclipse/Schedule/UDQ/UDQDefine.hpp>
30 #include <opm/input/eclipse/Schedule/UDQ/UDQAssign.hpp>
31 #include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
32 #include <opm/input/eclipse/Schedule/UDQ/UDQParams.hpp>
33 #include <opm/input/eclipse/Schedule/UDQ/UDQFunctionTable.hpp>
34 #include <opm/input/eclipse/EclipseState/Util/OrderedMap.hpp>
35 #include <opm/input/eclipse/EclipseState/Util/IOrderSet.hpp>
36 
37 
38 namespace Opm {
39 
40  class DeckRecord;
41  class SummaryState;
42  class UDQState;
43  class KeywordLocation;
44  class WellMatcher;
45 
46  namespace RestartIO {
47  struct RstState;
48  }
49 
50 
51  class UDQConfig {
52  public:
53  UDQConfig() = default;
54  explicit UDQConfig(const UDQParams& params);
55  UDQConfig(const UDQParams& params, const RestartIO::RstState& rst_state);
56 
57  static UDQConfig serializeObject();
58 
59  const std::string& unit(const std::string& key) const;
60  bool has_unit(const std::string& keyword) const;
61  bool has_keyword(const std::string& keyword) const;
62  void add_record(const DeckRecord& record, const KeywordLocation& location, std::size_t report_step);
63 
64  void add_unit(const std::string& keyword, const std::string& unit);
65  void add_update(const std::string& keyword, std::size_t report_step, const KeywordLocation& location, const std::vector<std::string>& data);
66  void add_assign(const std::string& quantity, const std::vector<std::string>& selector, double value, std::size_t report_step);
67  void add_assign(const std::string& quantity, const std::unordered_set<std::string>& selector, double value, std::size_t report_step);
68  void add_define(const std::string& quantity, const KeywordLocation& location, const std::vector<std::string>& expression, std::size_t report_step);
69 
70  void eval_assign(std::size_t report_step, const WellMatcher& wm, SummaryState& st, UDQState& udq_state) const;
71  void eval(std::size_t report_step, const WellMatcher& wm, SummaryState& st, UDQState& udq_state) const;
72  const UDQDefine& define(const std::string& key) const;
73  const UDQAssign& assign(const std::string& key) const;
74  std::vector<UDQDefine> definitions() const;
75  std::vector<UDQDefine> definitions(UDQVarType var_type) const;
76  std::vector<UDQInput> input() const;
77 
78  // The size() method will return the number of active DEFINE and ASSIGN
79  // statements; this will correspond to the length of the vector returned
80  // from input().
81  size_t size() const;
82 
83  UDQInput operator[](const std::string& keyword) const;
84  UDQInput operator[](std::size_t insert_index) const;
85 
86  std::vector<UDQAssign> assignments() const;
87  std::vector<UDQAssign> assignments(UDQVarType var_type) const;
88  const UDQParams& params() const;
89  const UDQFunctionTable& function_table() const;
90 
91  bool operator==(const UDQConfig& config) const;
92  void required_summary(std::unordered_set<std::string>& summary_keys) const;
93 
94 
95  template<class Serializer>
96  void serializeOp(Serializer& serializer)
97  {
98  udq_params.serializeOp(serializer);
99  serializer.map(m_definitions);
100  serializer.map(m_assignments);
101  serializer(units);
102  input_index.serializeOp(serializer);
103  serializer.template map<decltype(type_count),false>(type_count);
104  // The UDQFunction table is constant up to udq_params.
105  // So we can just construct a new instance here.
106  if (!serializer.isSerializing())
107  udqft = UDQFunctionTable(udq_params);
108  }
109 
110  private:
111  void add_node(const std::string& quantity, UDQAction action);
112  UDQAction action_type(const std::string& udq_key) const;
113  void eval_assign(std::size_t report_step, SummaryState& st, UDQState& udq_state, UDQContext& context) const;
114  void eval_define(std::size_t report_step, UDQState& udq_state, UDQContext& context) const;
115 
116 
117  UDQParams udq_params;
118  UDQFunctionTable udqft;
119 
120 
121  /*
122  The choices of datastructures are strongly motivated by the
123  constraints imposed by the Eclipse formatted restart files; for
124  writing restart files it is essential to keep meticolous control over
125  the ordering of the keywords. In this class the ordering is mainly
126  maintained by the input_index map which keeps track of the insert
127  order of each keyword, and whether the keyword is currently DEFINE'ed
128  or ASSIGN'ed.
129  */
130  std::unordered_map<std::string, UDQDefine> m_definitions;
131  std::unordered_map<std::string, UDQAssign> m_assignments;
132  std::unordered_map<std::string, std::string> units;
133 
134  IOrderSet<std::string> define_order;
136  std::map<UDQVarType, std::size_t> type_count;
137  };
138 }
139 
140 
141 
142 #endif
Definition: DeckRecord.hpp:32
Definition: KeywordLocation.hpp:27
Definition: OrderedMap.hpp:32
Definition: Serializer.hpp:38
Definition: SummaryState.hpp:69
Definition: UDQAssign.hpp:34
Definition: UDQConfig.hpp:51
Definition: UDQContext.hpp:39
Definition: UDQDefine.hpp:43
Definition: UDQFunctionTable.hpp:31
Definition: UDQInput.hpp:81
Definition: UDQParams.hpp:31
Definition: UDQState.hpp:36
Definition: WellMatcher.hpp:32
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: state.hpp:51