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 
29 namespace 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 };
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  , groupConverged_(true)
90  {
91  }
92 
93  void clear()
94  {
95  status_ = AllGood;
96  res_failures_.clear();
97  well_failures_.clear();
98  groupConverged_ = true;
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 setGroupConverged(const bool groupConverged)
114  {
115  groupConverged_ = groupConverged;
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  return *this;
126  }
127 
128  // ----------- Const member functions (queries) -----------
129 
130  bool converged() const
131  {
132  return status_ == AllGood && groupConverged_;
133  }
134 
135  bool reservoirFailed() const
136  {
137  return status_ & ReservoirFailed;
138  }
139 
140  bool wellFailed() const
141  {
142  return status_ & WellFailed;
143  }
144 
145  const std::vector<ReservoirFailure>& reservoirFailures() const
146  {
147  return res_failures_;
148  }
149 
150  const std::vector<WellFailure>& wellFailures() const
151  {
152  return well_failures_;
153  }
154 
155  Severity severityOfWorstFailure() const
156  {
157  // A function to get the worst of two severities.
158  auto smax = [](Severity s1, Severity s2) {
159  return s1 < s2 ? s2 : s1;
160  };
161  auto s = Severity::None;
162  for (const auto& f : res_failures_) {
163  s = smax(s, f.severity());
164  }
165  for (const auto& f : well_failures_) {
166  s = smax(s, f.severity());
167  }
168  return s;
169  }
170 
171  private:
172 
173  // ----------- Member variables -----------
174  Status status_;
175  std::vector<ReservoirFailure> res_failures_;
176  std::vector<WellFailure> well_failures_;
177  bool groupConverged_;
178  };
179 
180 } // namespace Opm
181 
182 #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:26