My Project
Loading...
Searching...
No Matches
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 <algorithm>
25#include <cassert>
26#include <numeric>
27#include <string>
28#include <utility>
29#include <vector>
30
31namespace Opm
32{
33
38 {
39 public:
40
41 // ----------- Types -----------
42
43 enum Status { AllGood = 0,
44 ReservoirFailed = 1 << 0,
45 WellFailed = 1 << 1 };
46 enum struct Severity { None = 0,
47 Normal = 1,
48 TooLarge = 2,
49 NotANumber = 3 };
51 {
52 public:
53 enum struct Type { Invalid, MassBalance, Cnv };
54 ReservoirFailure(Type t, Severity s, int phase)
55 : type_(t), severity_(s), phase_(phase)
56 {
57 }
58 Type type() const { return type_; }
59 Severity severity() const { return severity_; }
60 int phase() const { return phase_; }
61 private:
62 Type type_;
63 Severity severity_;
64 int phase_;
65 };
67 {
68 public:
69 ReservoirConvergenceMetric(ReservoirFailure::Type t, int phase, double value)
70 : type_(t), phase_(phase), value_(value)
71 {
72 }
73 ReservoirFailure::Type type() const { return type_; }
74 int phase() const { return phase_; }
75 double value() const { return value_; }
76 private:
77 ReservoirFailure::Type type_;
78 int phase_;
79 double value_;
80 };
82 {
83 public:
84 enum struct Type { Invalid, MassBalance, Pressure, ControlBHP, ControlTHP, ControlRate, Unsolvable, WrongFlowDirection };
85 WellFailure(Type t, Severity s, int phase, const std::string& well_name)
86 : type_(t), severity_(s), phase_(phase), well_name_(well_name)
87 {
88 }
89 Type type() const { return type_; }
90 Severity severity() const { return severity_; }
91 int phase() const { return phase_; }
92 const std::string& wellName() const { return well_name_; }
93 private:
94 Type type_;
95 Severity severity_;
96 int phase_;
97 std::string well_name_;
98 };
99
100 // ----------- Mutating member functions -----------
101
103 : ConvergenceReport{0.0}
104 {
105 }
106
107 explicit ConvergenceReport(const double reportTime)
108 : reportTime_{reportTime}
109 , status_{AllGood}
110 , res_failures_{}
111 , well_failures_{}
112 , wellGroupTargetsViolated_(false)
113 {
114 }
115
116 void clear()
117 {
118 status_ = AllGood;
119 res_failures_.clear();
120 well_failures_.clear();
121 wellGroupTargetsViolated_ = false;
122 }
123
124 void setReservoirFailed(const ReservoirFailure& rf)
125 {
126 status_ = static_cast<Status>(status_ | ReservoirFailed);
127 res_failures_.push_back(rf);
128 }
129
130 void setWellFailed(const WellFailure& wf)
131 {
132 status_ = static_cast<Status>(status_ | WellFailed);
133 well_failures_.push_back(wf);
134 }
135
136 template <typename... Args>
137 void setReservoirConvergenceMetric(Args&&... args)
138 {
139 this->res_convergence_.emplace_back(std::forward<Args>(args)...);
140 }
141
142 void setWellGroupTargetsViolated(const bool wellGroupTargetsViolated)
143 {
144 wellGroupTargetsViolated_ = wellGroupTargetsViolated;
145 }
146
147 ConvergenceReport& operator+=(const ConvergenceReport& other)
148 {
149 reportTime_ = std::max(reportTime_, other.reportTime_);
150 status_ = static_cast<Status>(status_ | other.status_);
151 res_failures_.insert(res_failures_.end(), other.res_failures_.begin(), other.res_failures_.end());
152 well_failures_.insert(well_failures_.end(), other.well_failures_.begin(), other.well_failures_.end());
153 res_convergence_.insert(res_convergence_.end(), other.res_convergence_.begin(), other.res_convergence_.end());
154 assert(reservoirFailed() != res_failures_.empty());
155 assert(wellFailed() != well_failures_.empty());
156 wellGroupTargetsViolated_ = (wellGroupTargetsViolated_ || other.wellGroupTargetsViolated_);
157 return *this;
158 }
159
160 // ----------- Const member functions (queries) -----------
161
162 double reportTime() const
163 {
164 return reportTime_;
165 }
166
167 bool converged() const
168 {
169 return (status_ == AllGood) && !wellGroupTargetsViolated_;
170 }
171
172 bool reservoirFailed() const
173 {
174 return status_ & ReservoirFailed;
175 }
176
177 bool wellFailed() const
178 {
179 return status_ & WellFailed;
180 }
181
182 const std::vector<ReservoirFailure>& reservoirFailures() const
183 {
184 return res_failures_;
185 }
186
187 const std::vector<ReservoirConvergenceMetric>& reservoirConvergence() const
188 {
189 return res_convergence_;
190 }
191
192 const std::vector<WellFailure>& wellFailures() const
193 {
194 return well_failures_;
195 }
196
197 Severity severityOfWorstFailure() const
198 {
199 // A function to get the worst of two severities.
200 auto smax = [](Severity s1, Severity s2) {
201 return s1 < s2 ? s2 : s1;
202 };
203 auto s = Severity::None;
204 for (const auto& f : res_failures_) {
205 s = smax(s, f.severity());
206 }
207 for (const auto& f : well_failures_) {
208 s = smax(s, f.severity());
209 }
210 return s;
211 }
212
213 private:
214
215 // ----------- Member variables -----------
216 double reportTime_;
217 Status status_;
218 std::vector<ReservoirFailure> res_failures_;
219 std::vector<WellFailure> well_failures_;
220 std::vector<ReservoirConvergenceMetric> res_convergence_;
221 bool wellGroupTargetsViolated_;
222 };
223
225 {
226 int report_step;
227 int current_step;
228 std::vector<ConvergenceReport> report;
229 };
230
231
232} // namespace Opm
233
234#endif // OPM_CONVERGENCEREPORT_HEADER_INCLUDED
Definition AquiferInterface.hpp:35
Definition ConvergenceReport.hpp:67
Definition ConvergenceReport.hpp:51
Definition ConvergenceReport.hpp:82
Represents the convergence status of the whole simulator, to make it possible to query and store the ...
Definition ConvergenceReport.hpp:38
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition BlackoilPhases.hpp:27
Definition ConvergenceReport.hpp:225