45 ReservoirFailed = 1 << 0,
49 enum struct Severity {
52 ConvergenceMonitorFailure = 2,
60 int largeWellResiduals{0};
63 return nonConverged + distanceDecay + largeWellResiduals;
70 largeWellResiduals = 0;
74 nonConverged += other.nonConverged;
75 distanceDecay += other.distanceDecay;
76 largeWellResiduals += other.largeWellResiduals;
80 template <
typename Serializer>
89 using CnvPvSplit = std::pair<
96 enum struct Type { Invalid, MassBalance, Cnv, ConvergenceMonitorFailure };
103 : type_(
t), severity_(s), phase_(phase)
106 Type type()
const {
return type_; }
107 Severity severity()
const {
return severity_; }
108 int phase()
const {
return phase_; }
110 template <
typename Serializer>
121 Type type_ { Type::Invalid };
122 Severity severity_ { Severity::None };
134 : type_(
t), phase_(phase), value_(value), tolerance_(tolerance)
137 ReservoirFailure::Type type()
const {
return type_; }
138 int phase()
const {
return phase_; }
139 double value()
const {
return value_; }
140 double tolerance()
const {
return tolerance_; }
142 template <
typename Serializer>
154 ReservoirFailure::Type type_ { ReservoirFailure::Type::Invalid };
156 double value_ { 0.0 };
157 double tolerance_ { 0.0 };
178 WellFailure(Type
t, Severity s,
int phase,
const std::string& well_name)
179 : type_(
t), severity_(s), phase_(phase), well_name_(well_name)
182 Type type()
const {
return type_; }
183 Severity severity()
const {
return severity_; }
184 int phase()
const {
return phase_; }
185 const std::string& wellName()
const {
return well_name_; }
187 template <
typename Serializer>
199 Type type_ { Type::Invalid };
200 Severity severity_ { Severity::None };
202 std::string well_name_ {};
212 WellConvergenceMetric(WellFailure::Type
t, Severity s,
int phase,
double value,
const std::string& well_name)
213 : type_(
t), severity_(s), phase_(phase), value_(value), well_name_(well_name)
216 WellFailure::Type type()
const {
return type_; }
217 Severity severity()
const {
return severity_; }
218 int phase()
const {
return phase_; }
219 double value()
const {
return value_; }
220 const std::string& wellName()
const {
return well_name_; }
222 template <
typename Serializer>
235 WellFailure::Type type_ { WellFailure::Type::Invalid };
236 Severity severity_ { Severity::None };
238 double value_ { 0.0 };
239 std::string well_name_ {};
249 : reportTime_{reportTime}
253 , wellGroupTargetsViolated_(
false)
259 res_failures_.clear();
260 well_failures_.clear();
261 wellGroupTargetsViolated_ =
false;
264 void setReservoirFailed(
const ReservoirFailure&
rf)
266 status_ =
static_cast<Status
>(status_ | ReservoirFailed);
267 res_failures_.push_back(
rf);
270 void setWellFailed(
const WellFailure&
wf)
272 status_ =
static_cast<Status
>(status_ | WellFailed);
273 well_failures_.push_back(
wf);
276 template <
typename...
Args>
277 void setReservoirConvergenceMetric(
Args&&... args)
279 this->res_convergence_.emplace_back(std::forward<Args>(args)...);
282 template <
typename...
Args>
283 void setWellConvergenceMetric(
Args&&... args)
285 this->well_convergence_.emplace_back(std::forward<Args>(args)...);
293 void setCnvPoreVolSplit(
const CnvPvSplit& cnvPvSplit,
294 const double eligiblePoreVolume)
296 this->cnvPvSplit_ = cnvPvSplit;
297 this->eligiblePoreVolume_ = eligiblePoreVolume;
300 ConvergenceReport& operator+=(
const ConvergenceReport& other)
302 reportTime_ = std::max(reportTime_, other.reportTime_);
303 status_ =
static_cast<Status
>(status_ | other.status_);
304 res_failures_.insert(res_failures_.end(), other.res_failures_.begin(), other.res_failures_.end());
305 well_failures_.insert(well_failures_.end(), other.well_failures_.begin(), other.well_failures_.end());
306 res_convergence_.insert(res_convergence_.end(), other.res_convergence_.begin(), other.res_convergence_.end());
307 well_convergence_.insert(well_convergence_.end(), other.well_convergence_.begin(), other.well_convergence_.end());
308 assert(reservoirFailed() != res_failures_.empty());
309 assert(wellFailed() != well_failures_.empty());
310 wellGroupTargetsViolated_ = (wellGroupTargetsViolated_ || other.wellGroupTargetsViolated_);
319 if (! other.cnvPvSplit_.first.empty()) {
320 this->cnvPvSplit_ = other.cnvPvSplit_;
321 this->eligiblePoreVolume_ = other.eligiblePoreVolume_;
329 double reportTime()
const
334 double eligiblePoreVolume()
const
336 return this->eligiblePoreVolume_;
339 const CnvPvSplit& cnvPvSplit()
const
341 return this->cnvPvSplit_;
344 bool converged()
const
346 return (status_ == AllGood) && !wellGroupTargetsViolated_;
349 bool reservoirFailed()
const
351 return status_ & ReservoirFailed;
354 bool wellFailed()
const
356 return status_ & WellFailed;
359 const std::vector<ReservoirFailure>& reservoirFailures()
const
361 return res_failures_;
364 const std::vector<ReservoirConvergenceMetric>& reservoirConvergence()
const
366 return res_convergence_;
369 const std::vector<WellFailure>& wellFailures()
const
371 return well_failures_;
374 const std::vector<WellConvergenceMetric>& wellConvergence()
const
376 return well_convergence_;
379 const PenaltyCard& getPenaltyCard()
const
384 void addNonConvergedPenalty()
386 penaltyCard_.nonConverged++;
389 void addDistanceDecayPenalty()
391 penaltyCard_.distanceDecay++;
394 void addLargeWellResidualsPenalty()
396 penaltyCard_.largeWellResiduals++;
399 Severity severityOfWorstFailure()
const
402 auto smax = [](Severity
s1, Severity
s2) {
405 auto s = Severity::None;
406 for (
const auto&
f : res_failures_) {
407 s =
smax(s,
f.severity());
409 for (
const auto&
f : well_failures_) {
410 s =
smax(s,
f.severity());
415 template <
typename Serializer>
436 std::vector<ReservoirFailure> res_failures_;
437 std::vector<WellFailure> well_failures_;
438 std::vector<ReservoirConvergenceMetric> res_convergence_;
439 std::vector<WellConvergenceMetric> well_convergence_;
440 bool wellGroupTargetsViolated_;
441 CnvPvSplit cnvPvSplit_{};
442 double eligiblePoreVolume_{};
443 PenaltyCard penaltyCard_;