My Project
ConvergenceReport.hpp
1/*
2 Copyright 2018 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2018 Equinor.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef OPM_CONVERGENCEREPORT_HEADER_INCLUDED
22#define OPM_CONVERGENCEREPORT_HEADER_INCLUDED
23
24#include <cassert>
25#include <numeric>
26#include <string>
27#include <vector>
28
29namespace Opm
30{
31
36 {
37 public:
38
39 // ----------- Types -----------
40
41 enum Status { AllGood = 0,
42 ReservoirFailed = 1 << 0,
43 WellFailed = 1 << 1 };
44 enum struct Severity { None = 0,
45 Normal = 1,
46 TooLarge = 2,
47 NotANumber = 3 };
49 {
50 public:
51 enum struct Type { Invalid, MassBalance, Cnv };
52 ReservoirFailure(Type t, Severity s, int phase)
53 : type_(t), severity_(s), phase_(phase)
54 {
55 }
56 Type type() const { return type_; }
57 Severity severity() const { return severity_; }
58 int phase() const { return phase_; }
59 private:
60 Type type_;
61 Severity severity_;
62 int phase_;
63 };
65 {
66 public:
67 enum struct Type { Invalid, MassBalance, Pressure, ControlBHP, ControlTHP, ControlRate, Unsolvable };
68 WellFailure(Type t, Severity s, int phase, const std::string& well_name)
69 : type_(t), severity_(s), phase_(phase), well_name_(well_name)
70 {
71 }
72 Type type() const { return type_; }
73 Severity severity() const { return severity_; }
74 int phase() const { return phase_; }
75 const std::string& wellName() const { return well_name_; }
76 private:
77 Type type_;
78 Severity severity_;
79 int phase_;
80 std::string well_name_;
81 };
82
83 // ----------- Mutating member functions -----------
84
86 : status_{AllGood}
87 , res_failures_{}
88 , well_failures_{}
89 , wellGroupTargetsViolated_(false)
90 {
91 }
92
93 void clear()
94 {
95 status_ = AllGood;
96 res_failures_.clear();
97 well_failures_.clear();
98 wellGroupTargetsViolated_ = false;
99 }
100
101 void setReservoirFailed(const ReservoirFailure& rf)
102 {
103 status_ = static_cast<Status>(status_ | ReservoirFailed);
104 res_failures_.push_back(rf);
105 }
106
107 void setWellFailed(const WellFailure& wf)
108 {
109 status_ = static_cast<Status>(status_ | WellFailed);
110 well_failures_.push_back(wf);
111 }
112
113 void setWellGroupTargetsViolated(const bool wellGroupTargetsViolated)
114 {
115 wellGroupTargetsViolated_ = wellGroupTargetsViolated;
116 }
117
118 ConvergenceReport& operator+=(const ConvergenceReport& other)
119 {
120 status_ = static_cast<Status>(status_ | other.status_);
121 res_failures_.insert(res_failures_.end(), other.res_failures_.begin(), other.res_failures_.end());
122 well_failures_.insert(well_failures_.end(), other.well_failures_.begin(), other.well_failures_.end());
123 assert(reservoirFailed() != res_failures_.empty());
124 assert(wellFailed() != well_failures_.empty());
125 wellGroupTargetsViolated_ = (wellGroupTargetsViolated_ || other.wellGroupTargetsViolated_);
126 return *this;
127 }
128
129 // ----------- Const member functions (queries) -----------
130
131 bool converged() const
132 {
133 return (status_ == AllGood) && !wellGroupTargetsViolated_;
134 }
135
136 bool reservoirFailed() const
137 {
138 return status_ & ReservoirFailed;
139 }
140
141 bool wellFailed() const
142 {
143 return status_ & WellFailed;
144 }
145
146 const std::vector<ReservoirFailure>& reservoirFailures() const
147 {
148 return res_failures_;
149 }
150
151 const std::vector<WellFailure>& wellFailures() const
152 {
153 return well_failures_;
154 }
155
156 Severity severityOfWorstFailure() const
157 {
158 // A function to get the worst of two severities.
159 auto smax = [](Severity s1, Severity s2) {
160 return s1 < s2 ? s2 : s1;
161 };
162 auto s = Severity::None;
163 for (const auto& f : res_failures_) {
164 s = smax(s, f.severity());
165 }
166 for (const auto& f : well_failures_) {
167 s = smax(s, f.severity());
168 }
169 return s;
170 }
171
172 private:
173
174 // ----------- Member variables -----------
175 Status status_;
176 std::vector<ReservoirFailure> res_failures_;
177 std::vector<WellFailure> well_failures_;
178 bool wellGroupTargetsViolated_;
179 };
180
181} // namespace Opm
182
183#endif // OPM_CONVERGENCEREPORT_HEADER_INCLUDED
Definition: ConvergenceReport.hpp:49
Definition: ConvergenceReport.hpp:65
Represents the convergence status of the whole simulator, to make it possible to query and store the ...
Definition: ConvergenceReport.hpp:36
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27