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