My Project
PyAction.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 PYACTION_HPP_
22 #define PYACTION_HPP_
23 
24 
25 #include <functional>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 namespace Opm {
31 
32 class Python;
33 class EclipseState;
34 class Schedule;
35 class SummaryState;
36 class PyRunModule;
37 
38 namespace Action {
39 class State;
40 
41 class PyAction {
42 public:
43  enum class RunCount {
44  single,
45  unlimited,
46  first_true
47  };
48 
49 
50  static RunCount from_string(std::string run_count);
51  static PyAction serializationTestObject();
52  PyAction() = default;
53  PyAction(std::shared_ptr<const Python> python, const std::string& name, RunCount run_count, const std::string& module_file);
54  bool run(EclipseState& ecl_state, Schedule& schedule, std::size_t report_step, SummaryState& st,
55  const std::function<void(const std::string&, const std::vector<std::string>&)>& actionx_callback) const;
56  const std::string& name() const;
57  bool ready(const State& state) const;
58  bool operator==(const PyAction& other) const;
59 
60  template<class Serializer>
61  void serializeOp(Serializer& serializer)
62  {
63  serializer(m_name);
64  serializer(m_run_count);
65  serializer(module_file);
66  serializer(m_active);
67  }
68 
69 private:
70  void update(bool result) const;
71 
72  mutable std::shared_ptr< PyRunModule > run_module;
73  std::string m_name;
74  RunCount m_run_count;
75  std::string module_file;
76  mutable bool m_active = true;
77 };
78 }
79 
80 }
81 
82 #endif
Definition: PyAction.hpp:41
Definition: State.hpp:40
Definition: EclipseState.hpp:55
Definition: Schedule.hpp:138
Class for (de-)serializing.
Definition: Serializer.hpp:75
Definition: SummaryState.hpp:69
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29