My Project
UDQActive.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 
21 #ifndef UDQ_USAGE_HPP
22 #define UDQ_USAGE_HPP
23 
24 #include <cstdlib>
25 #include <optional>
26 #include <string>
27 #include <vector>
28 
29 #include <opm/input/eclipse/Deck/UDAValue.hpp>
30 #include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
31 #include <opm/input/eclipse/EclipseState/Runspec.hpp>
32 
33 namespace Opm {
34 
35 class UDAValue;
36 class UDQConfig;
37 class UnitSystem;
38 
39 namespace RestartIO {
40  struct RstState;
41 }
42 
43 class UDQActive {
44 public:
45 
46  struct RstRecord {
47 
48  RstRecord(UDAControl control_arg, UDAValue value_arg, std::string wgname_arg)
49  : control(control_arg)
50  , value(value_arg)
51  , wgname(wgname_arg)
52  {};
53 
54  RstRecord(UDAControl control_arg, UDAValue value_arg, std::string wgname_arg, Phase phase)
55  : RstRecord(control_arg, value_arg, wgname_arg)
56  {
57  this->ig_phase = phase;
58  };
59 
60  UDAControl control;
61  UDAValue value;
62  std::string wgname;
63  std::optional<Phase> ig_phase;
64  };
65 
66 
67 
68  class OutputRecord{
69  public:
70  OutputRecord() :
71  input_index(0),
72  control(UDAControl::WCONPROD_ORAT),
73  uda_code(0),
74  use_count(1)
75  {}
76 
77  OutputRecord(const std::string& udq_arg, std::size_t input_index_arg, std::size_t use_index_arg, const std::string& wgname_arg, UDAControl control_arg) :
78  udq(udq_arg),
79  input_index(input_index_arg),
80  use_index(use_index_arg),
81  control(control_arg),
82  uda_code(UDQ::udaCode(control_arg)),
83  use_count(1),
84  wgname(wgname_arg)
85  {}
86 
87  bool operator==(const OutputRecord& other) const {
88  if ((this->udq == other.udq) &&
89  (this->input_index == other.input_index) &&
90  (this->use_index == other.use_index) &&
91  (this->wgname == other.wgname) &&
92  (this->control == other.control) &&
93  (this->uda_code == other.uda_code) &&
94  (this->use_count == other.use_count))
95  return true;
96  return false;
97  }
98 
99  bool operator!=(const OutputRecord& other) const {
100  return !(*this == other);
101  }
102 
103  template<class Serializer>
104  void serializeOp(Serializer& serializer)
105  {
106  serializer(udq);
107  serializer(input_index);
108  serializer(use_index);
109  serializer(wgname);
110  serializer(control);
111  serializer(uda_code);
112  serializer(use_count);
113  }
114 
115  std::string udq;
116  std::size_t input_index;
117  std::size_t use_index = 0;
118  UDAControl control;
119  int uda_code;
120  std::string wg_name() const;
121  std::size_t use_count;
122  private:
123  // The wgname is need in the update process, but it should
124  // not be exported out.
125  std::string wgname;
126  };
127 
128  class InputRecord {
129  public:
130  InputRecord() :
131  input_index(0),
132  control(UDAControl::WCONPROD_ORAT)
133  {}
134 
135  InputRecord(std::size_t input_index_arg, const std::string& udq_arg, const std::string& wgname_arg, UDAControl control_arg) :
136  input_index(input_index_arg),
137  udq(udq_arg),
138  wgname(wgname_arg),
139  control(control_arg)
140  {}
141 
142  bool operator==(const InputRecord& other) const {
143  return this->input_index == other.input_index &&
144  this->udq == other.udq &&
145  this->wgname == other.wgname &&
146  this->control == other.control;
147  }
148 
149  template<class Serializer>
150  void serializeOp(Serializer& serializer)
151  {
152  serializer(input_index);
153  serializer(udq);
154  serializer(wgname);
155  serializer(control);
156  }
157 
158  std::size_t input_index;
159  std::string udq;
160  std::string wgname;
161  UDAControl control;
162  };
163 
164  static UDQActive serializationTestObject();
165  UDQActive() = default;
166  static std::vector<RstRecord> load_rst(const UnitSystem& units,
167  const UDQConfig& udq_config,
168  const RestartIO::RstState& rst_state,
169  const std::vector<std::string>& well_names,
170  const std::vector<std::string>& group_names);
171  int update(const UDQConfig& udq_config, const UDAValue& uda, const std::string& wgname, UDAControl control);
172  explicit operator bool() const;
173  const std::vector<OutputRecord>& iuad() const;
174  std::vector<InputRecord> iuap() const;
175 
176  bool operator==(const UDQActive& data) const;
177 
178  template<class Serializer>
179  void serializeOp(Serializer& serializer)
180  {
181  serializer(input_data);
182  serializer(output_data);
183  }
184 
185 private:
186  std::string udq_hash(const std::string& udq, UDAControl control);
187  std::string wg_hash(const std::string& wgname, UDAControl control);
188  int add(const UDQConfig& udq_config, const std::string& udq, const std::string& wgname, UDAControl control);
189  int update_input(const UDQConfig& udq_config, const UDAValue& uda, const std::string& wgname, UDAControl control);
190  int drop(const std::string& wgname, UDAControl control);
191 
192  std::vector<InputRecord> input_data;
193  std::vector<OutputRecord> mutable output_data;
194 };
195 
196 }
197 
198 #endif
Class for (de-)serializing.
Definition: Serializer.hpp:75
Definition: UDAValue.hpp:32
Definition: UDQActive.hpp:128
Definition: UDQActive.hpp:68
Definition: UDQActive.hpp:43
Definition: UDQConfig.hpp:51
Definition: UnitSystem.hpp:33
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: state.hpp:54
Definition: UDQActive.hpp:46