ActionResult.hpp
Go to the documentation of this file.
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 <string>
24#include <unordered_set>
25#include <vector>
26#include <memory>
27
28namespace Opm {
29namespace 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
71class WellSet {
72public:
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);
83private:
84 std::unordered_set<std::string> well_set;
85};
86
87
88
89class Result {
90public:
91 explicit Result(bool result_arg);
92 Result(bool result_arg, const std::vector<std::string>& wells);
93 Result(bool result_arg, const WellSet& wells);
94 Result(const Result& src);
95
96 explicit operator bool() const;
97 std::vector<std::string> wells() const;
98
99 bool has_well(const std::string& well) const;
100
101 void add_well(const std::string& well);
102
103 Result& operator|=(const Result& other);
104 Result& operator=(const Result& src);
105 Result& operator&=(const Result& other);
106
107private:
108 void assign(bool value);
109 bool result;
110 /*
111 The set of matching wells is implemented with pointer semantics to be able
112 to differentiate between an empty set of wells - like all the wells with
113 WWCT > 1, and a result set which does not have well information at all -
114 e.g. FOPR > 0.
115 */
116 std::unique_ptr<WellSet> matching_wells;
117};
118
119}
120}
121#endif
const char *const string
Definition: cJSON.h:170
Definition: ActionResult.hpp:89
Result & operator|=(const Result &other)
Result(bool result_arg, const WellSet &wells)
std::vector< std::string > wells() const
Result(bool result_arg)
Result(const Result &src)
Result(bool result_arg, const std::vector< std::string > &wells)
Result & operator&=(const Result &other)
Result & operator=(const Result &src)
bool has_well(const std::string &well) const
void add_well(const std::string &well)
Definition: ActionResult.hpp:71
std::size_t size() const
std::vector< std::string > wells() const
void add(const std::string &well)
bool contains(const std::string &well) const
WellSet(const std::vector< std::string > &wells)
WellSet & add(const WellSet &other)
WellSet & intersect(const WellSet &other)
char bool
Definition: msvc_stdbool.h:17
Action
Definition: InputErrorAction.hpp:36
Definition: A.hpp:4
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955