My Project
ActionResult.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  but eliminates the memory saving DynamicState is intended to enable. 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_RESULT_HPP
21 #define ACTION_RESULT_HPP
22 
23 #include <optional>
24 #include <string>
25 #include <unordered_set>
26 #include <vector>
27 
28 namespace Opm {
29 namespace Action {
30 
31 /*
32  The Action::Result class is used to hold the boolean result of a ACTIONX
33  condition like:
34 
35  WWCT > 0.75
36 
37  and also the final evaluation of an ACTIONX condition comes as a
38  Action::Result instance.
39 
40 
41  In addition to the overall truthness of the expression an Action::Result
42  instance can optionally have a set of matching wells. For instance the
43  the result of:
44 
45  FWCT > 0.75
46 
47  Will not contain any wells, whereas the result of:
48 
49  WWCT > 0.75
50 
51  will contain a set of all the wells matching the condition. The set of
52  matching wells can be queries with the wells() method. When a result with
53  wells and a result without wells are combined as:
54 
55  WWCT > 0.50 AND FPR > 1000
56 
57  The result will have all the wells corresponding to the first condition, when
58  several results with wells are combined with logical operators AND and OR the
59  set of matching wells are combined correspondingly. It is actually possible
60  to have a result which evaluates to true and still have and zero matching
61  wells - e.g.
62 
63  WWCT > 1.25 OR FOPT > 1
64 
65  If the condition evaluates to true the set of matching wells will be passed
66  to the Schedule::applyAction() method, and will be used in place of '?' in
67  keywords like WELOPEN.
68 */
69 
70 
71 class WellSet {
72 public:
73  WellSet() = default;
74  explicit WellSet(const std::vector<std::string>& wells);
75  void add(const std::string& well);
76 
77  std::size_t size() const;
78  std::vector<std::string> wells() const;
79  bool contains(const std::string& well) const;
80 
81  WellSet& intersect(const WellSet& other);
82  WellSet& add(const WellSet& other);
83  bool operator==(const WellSet& other) const;
84 
85  template<class Serializer>
86  void serializeOp(Serializer& serializer)
87  {
88  serializer.template set<std::unordered_set<std::string>, false>(this->well_set);
89  }
90 
91  static WellSet serializeObject();
92 
93 private:
94  std::unordered_set<std::string> well_set;
95 };
96 
97 
98 
99 class Result {
100 public:
101  Result() = default;
102  explicit Result(bool result_arg);
103  Result(bool result_arg, const std::vector<std::string>& wells);
104  Result(bool result_arg, const WellSet& wells);
105 
106  explicit operator bool() const;
107  std::vector<std::string> wells() const;
108 
109  bool has_well(const std::string& well) const;
110 
111  void add_well(const std::string& well);
112 
113  Result& operator|=(const Result& other);
114  Result& operator&=(const Result& other);
115  bool operator==(const Result& other) const;
116 
117  template<class Serializer>
118  void serializeOp(Serializer& serializer)
119  {
120  serializer(this->result);
121  serializer(this->matching_wells);
122  }
123 
124  static Result serializeObject();
125 
126 private:
127  void assign(bool value);
128  bool result;
129  std::optional<WellSet> matching_wells;
130 };
131 
132 }
133 }
134 #endif
Definition: ActionResult.hpp:99
Definition: ActionResult.hpp:71
Definition: Serializer.hpp:38
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29