opm-common
UDQDefine.hpp
1 /*
2  Copyright 2018 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 UDQ_DEFINE_HPP
21 #define UDQ_DEFINE_HPP
22 
23 #include <opm/input/eclipse/Schedule/UDQ/UDQContext.hpp>
24 #include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
25 #include <opm/input/eclipse/Schedule/UDQ/UDQFunctionTable.hpp>
26 #include <opm/input/eclipse/Schedule/UDQ/UDQSet.hpp>
27 #include <opm/input/eclipse/Schedule/UDQ/UDQToken.hpp>
28 
29 #include <opm/common/OpmLog/KeywordLocation.hpp>
30 
31 #include <cstddef>
32 #include <memory>
33 #include <optional>
34 #include <set>
35 #include <string>
36 #include <unordered_set>
37 #include <utility>
38 #include <vector>
39 
40 namespace Opm {
41 
42 class UDQASTNode;
43 class ParseContext;
44 class ErrorGuard;
45 
46 } // Namespace Opm
47 
48 namespace Opm {
49 
50 class UDQDefine
51 {
52 public:
53  UDQDefine();
54 
55  UDQDefine(const UDQParams& udq_params,
56  const std::string& keyword,
57  std::size_t report_step,
58  const KeywordLocation& location,
59  const std::vector<std::string>& deck_data);
60 
61  UDQDefine(const UDQParams& udq_params,
62  const std::string& keyword,
63  std::size_t report_step,
64  const KeywordLocation& location,
65  const std::vector<std::string>& deck_data,
66  const ParseContext& parseContext,
67  ErrorGuard& errors);
68 
69  template <typename T>
70  UDQDefine(const UDQParams& udq_params,
71  const std::string& keyword,
72  std::size_t report_step,
73  const KeywordLocation& location,
74  const std::vector<std::string>& deck_data,
75  const ParseContext& parseContext,
76  T&& errors);
77 
78  static UDQDefine serializationTestObject();
79 
86 
87  UDQSet eval(const UDQContext& context) const;
88  const std::string& keyword() const;
89  const std::string& input_string() const { return this->input_string_; }
90  const KeywordLocation& location() const;
91  UDQVarType var_type() const;
92  std::set<UDQTokenType> func_tokens() const;
93  void required_summary(std::unordered_set<std::string>& summary_keys) const;
94  void update_status(UDQUpdate update_status, std::size_t report_step);
95  std::pair<UDQUpdate, std::size_t> status() const;
96  const std::vector<Opm::UDQToken>& tokens() const;
97  void clear_next() const
98  {
99  if (this->m_update_status == UDQUpdate::NEXT) {
100  this->m_update_status = UDQUpdate::OFF;
101  }
102  }
103 
120  {
121  if (this->m_update_status == UDQUpdate::NEXT) {
122  this->m_update_status = UDQUpdate::OFF;
123 
124  return true;
125  }
126 
127  return false;
128  }
129 
130  bool operator==(const UDQDefine& data) const;
131 
132  template <class Serializer>
133  void serializeOp(Serializer& serializer)
134  {
135  serializer(m_keyword);
136  serializer(input_string_);
137  serializer(m_tokens);
138  serializer(ast);
139  serializer(m_var_type);
140  serializer(m_location);
141  serializer(m_update_status);
142  serializer(m_report_step);
143  }
144 
145 private:
146  std::string m_keyword{};
147  std::string input_string_{};
148  std::vector<Opm::UDQToken> m_tokens{};
149  std::shared_ptr<UDQASTNode> ast{};
150  UDQVarType m_var_type{UDQVarType::NONE};
151  KeywordLocation m_location{};
152  std::size_t m_report_step{};
153  mutable UDQUpdate m_update_status{UDQUpdate::NEXT};
154 
155  UDQSet scatter_scalar_value(UDQSet&& res, const UDQContext& context) const;
156  UDQSet scatter_scalar_well_value(const UDQContext& context, const std::optional<double>& value) const;
157  UDQSet scatter_scalar_group_value(const UDQContext& context, const std::optional<double>& value) const;
158  UDQSet scatter_scalar_segment_value(const UDQContext& context, const std::optional<double>& value) const;
159 };
160 
161 } // Namespace Opm
162 
163 #endif // UDQ_DEFINE_HPP
Definition: UDQDefine.hpp:50
Definition: KeywordLocation.hpp:27
Definition: UDQContext.hpp:49
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: UDQSet.hpp:186
UDQ::RequisiteEvaluationObjects requiredObjects() const
All specific objects required for the defining expression.
Definition: UDQDefine.cpp:317
Definition: UDQParams.hpp:30
Collection of specific Schedule objects named in a UDQ definition.
Definition: UDQEnums.hpp:205
Control parser behaviour in failure conditions.
Definition: ParseContext.hpp:114
bool clear_update_next_for_new_report_step()
Clear "UPDATE NEXT" flag.
Definition: UDQDefine.hpp:119
Class for (de-)serializing.
Definition: Serializer.hpp:94
Definition: ErrorGuard.hpp:30