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{
44 RunState() = default;
45
46 explicit RunState(std::time_t sim_time)
47 : run_count(1)
48 , last_run(sim_time)
49 {}
50
51 void add_run(std::time_t sim_time)
52 {
53 this->last_run = sim_time;
54 this->run_count += 1;
55 }
56
57 static RunState serializationTestObject()
58 {
59 RunState rs;
60 rs.run_count = 100;
61 rs.last_run = 123456;
62 return rs;
63 }
64
65 bool operator==(const RunState& other) const
66 {
67 return this->run_count == other.run_count &&
68 this->last_run == other.last_run;
69 }
70
71 template<class Serializer>
72 void serializeOp(Serializer& serializer)
73 {
74 serializer(this->run_count);
75 serializer(this->last_run);
76 }
77
78 std::size_t run_count{};
79 std::time_t last_run{};
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:40
Definition ActionResult.hpp:99
Definition State.hpp:40
Class for (de-)serializing.
Definition Serializer.hpp:91
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition state.hpp:55