My Project
State.hpp
1 /*
2  Copyright 2020 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 ACTION_STATE_HPP
21 #define ACTION_STATE_HPP
22 
23 #include <ctime>
24 #include <map>
25 
26 #include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionResult.hpp>
27 
28 namespace Opm {
29 
30 namespace RestartIO {
31 struct RstState;
32 }
33 
34 namespace Action {
35 
36 class ActionX;
37 class Actions;
38 class State {
39 
40 struct RunState {
41  RunState() = default;
42 
43  RunState(std::time_t sim_time)
44  : run_count(1)
45  , last_run(sim_time)
46  {}
47 
48  void add_run(std::time_t sim_time) {
49  this->last_run = sim_time;
50  this->run_count += 1;
51  }
52 
53  static RunState serializeObject()
54  {
55  RunState rs;
56  rs.run_count = 100;
57  rs.last_run = 123456;
58  return rs;
59  }
60 
61 
62  bool operator==(const RunState& other) const {
63  return this->run_count == other.run_count &&
64  this->last_run == other.last_run;
65  }
66 
67  template<class Serializer>
68  void serializeOp(Serializer& serializer)
69  {
70  serializer(this->run_count);
71  serializer(this->last_run);
72  }
73 
74  std::size_t run_count;
75  std::time_t last_run;
76 };
77 
78 
79 
80 public:
81  void add_run(const ActionX& action, std::time_t sim_time, Result result);
82  std::size_t run_count(const ActionX& action) const;
83  std::time_t run_time(const ActionX& action) const;
84  std::optional<Result> result(const std::string& action) const;
85  void load_rst(const Actions& action_config, const RestartIO::RstState& rst_state);
86 
87  template<class Serializer>
88  void serializeOp(Serializer& serializer)
89  {
90  serializer.map(this->run_state);
91  serializer.map(this->last_result);
92  }
93 
94 
95  static State serializeObject();
96  bool operator==(const State& other) const;
97 
98 private:
99  using action_id = std::pair<std::string, std::size_t>;
100  static action_id make_id(const ActionX& action);
101  std::map<action_id, RunState> run_state;
102  std::map<std::string, Result> last_result;
103 };
104 
105 
106 }
107 }
108 #endif
Definition: ActionX.hpp:74
Definition: Actions.hpp:41
Definition: ActionResult.hpp:99
Definition: State.hpp:38
Definition: Serializer.hpp:38
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: state.hpp:50