My Project
RestartValue.hpp
1 /*
2  Copyright (c) 2017 Statoil ASA
3  This file is part of the Open Porous Media project (OPM).
4 
5  OPM is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  OPM is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with OPM. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef RESTART_VALUE_HPP
19 #define RESTART_VALUE_HPP
20 
21 #include <map>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 #include <opm/input/eclipse/Units/UnitSystem.hpp>
27 
28 #include <opm/output/data/Aquifer.hpp>
29 #include <opm/output/data/Solution.hpp>
30 #include <opm/output/data/Wells.hpp>
31 #include <opm/output/data/Groups.hpp>
32 
33 namespace Opm {
34 
35  class RestartKey {
36  public:
37 
38  std::string key;
39  UnitSystem::measure dim;
40  bool required = false;
41 
42  RestartKey() = default;
43 
44  RestartKey( const std::string& _key, UnitSystem::measure _dim)
45  : key(_key),
46  dim(_dim),
47  required(true)
48  {}
49 
50 
51  RestartKey( const std::string& _key, UnitSystem::measure _dim, bool _required)
52  : key(_key),
53  dim(_dim),
54  required(_required)
55  {}
56 
57  bool operator==(const RestartKey& key2) const
58  {
59  return key == key2.key &&
60  dim == key2.dim &&
61  required == key2.required;
62  }
63 
64  template<class Serializer>
65  void serializeOp(Serializer& serializer)
66  {
67  serializer(key);
68  serializer(dim);
69  serializer(required);
70  }
71 
72  static RestartKey serializationTestObject()
73  {
74  return RestartKey{"test_key", UnitSystem::measure::effective_Kh, true};
75  }
76  };
77 
78  /*
79  A simple class used to communicate values between the simulator and
80  the RestartIO functions.
81  */
82  class RestartValue {
83  public:
84  using ExtraVector = std::vector<std::pair<RestartKey, std::vector<double>>>;
85 
86  data::Solution solution{};
87  data::Wells wells{};
88  data::GroupAndNetworkValues grp_nwrk{};
89  data::Aquifers aquifer{};
90  ExtraVector extra{};
91 
93  data::Wells wells_arg,
94  data::GroupAndNetworkValues grpn_nwrk_arg,
95  data::Aquifers aquifer_arg);
96 
97  RestartValue() = default;
98 
99  bool hasExtra(const std::string& key) const;
100  void addExtra(const std::string& key, UnitSystem::measure dimension, std::vector<double> data);
101  void addExtra(const std::string& key, std::vector<double> data);
102  const std::vector<double>& getExtra(const std::string& key) const;
103 
104  void convertFromSI(const UnitSystem& units);
105  void convertToSI(const UnitSystem& units);
106 
107  bool operator==(const RestartValue& val2) const
108  {
109  return (this->solution == val2.solution)
110  && (this->wells == val2.wells)
111  && (this->grp_nwrk == val2.grp_nwrk)
112  && (this->aquifer == val2.aquifer)
113  && (this->extra == val2.extra);
114  }
115 
116  template<class Serializer>
117  void serializeOp(Serializer& serializer)
118  {
119  serializer(solution);
120  serializer(wells);
121  serializer(grp_nwrk);
122  serializer(aquifer);
123  serializer(extra);
124  }
125 
126  static RestartValue serializationTestObject()
127  {
128  auto res = RestartValue {
129  data::Solution::serializationTestObject(),
130  data::Wells::serializationTestObject(),
131  data::GroupAndNetworkValues::serializationTestObject(),
132  {{1, data::AquiferData::serializationTestObjectF()},
133  {2, data::AquiferData::serializationTestObjectC()},
134  {3, data::AquiferData::serializationTestObjectN()}}
135  };
136  res.extra = {{RestartKey::serializationTestObject(), {1.0, 2.0}}};
137 
138  return res;
139  }
140  };
141 
142 }
143 
144 #endif // RESTART_VALUE_HPP
Definition: RestartValue.hpp:35
Definition: RestartValue.hpp:82
Class for (de-)serializing.
Definition: Serializer.hpp:75
Definition: UnitSystem.hpp:33
Definition: Groups.hpp:209
Definition: Solution.hpp:32
Definition: Wells.hpp:500
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29