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)
254 , network_needs_more_balancing_force_another_newton_iteration_(
false)
260 res_failures_.clear();
261 well_failures_.clear();
262 wellGroupTargetsViolated_ =
false;
263 network_needs_more_balancing_force_another_newton_iteration_ =
false;
266 void setReservoirFailed(
const ReservoirFailure&
rf)
268 status_ =
static_cast<Status
>(status_ | ReservoirFailed);
269 res_failures_.push_back(
rf);
272 void setWellFailed(
const WellFailure&
wf)
274 status_ =
static_cast<Status
>(status_ | WellFailed);
275 well_failures_.push_back(
wf);
278 template <
typename...
Args>
279 void setReservoirConvergenceMetric(
Args&&... args)
281 this->res_convergence_.emplace_back(std::forward<Args>(args)...);
284 template <
typename...
Args>
285 void setWellConvergenceMetric(
Args&&... args)
287 this->well_convergence_.emplace_back(std::forward<Args>(args)...);
300 void setCnvPoreVolSplit(
const CnvPvSplit& cnvPvSplit,
301 const double eligiblePoreVolume)
303 this->cnvPvSplit_ = cnvPvSplit;
304 this->eligiblePoreVolume_ = eligiblePoreVolume;
307 ConvergenceReport& operator+=(
const ConvergenceReport& other)
309 reportTime_ = std::max(reportTime_, other.reportTime_);
310 status_ =
static_cast<Status
>(status_ | other.status_);
311 res_failures_.insert(res_failures_.end(), other.res_failures_.begin(), other.res_failures_.end());
312 well_failures_.insert(well_failures_.end(), other.well_failures_.begin(), other.well_failures_.end());
313 res_convergence_.insert(res_convergence_.end(), other.res_convergence_.begin(), other.res_convergence_.end());
314 well_convergence_.insert(well_convergence_.end(), other.well_convergence_.begin(), other.well_convergence_.end());
315 assert(reservoirFailed() != res_failures_.empty());
316 assert(wellFailed() != well_failures_.empty());
317 wellGroupTargetsViolated_ = (wellGroupTargetsViolated_ || other.wellGroupTargetsViolated_);
318 network_needs_more_balancing_force_another_newton_iteration_ = (network_needs_more_balancing_force_another_newton_iteration_
319 || other.network_needs_more_balancing_force_another_newton_iteration_);
328 if (! other.cnvPvSplit_.first.empty()) {
329 this->cnvPvSplit_ = other.cnvPvSplit_;
330 this->eligiblePoreVolume_ = other.eligiblePoreVolume_;
338 double reportTime()
const
343 double eligiblePoreVolume()
const
345 return this->eligiblePoreVolume_;
348 const CnvPvSplit& cnvPvSplit()
const
350 return this->cnvPvSplit_;
353 bool converged()
const
355 return (status_ == AllGood)
356 && !wellGroupTargetsViolated_
357 && !network_needs_more_balancing_force_another_newton_iteration_;
360 bool reservoirFailed()
const
362 return status_ & ReservoirFailed;
365 bool wellFailed()
const
367 return status_ & WellFailed;
370 const std::vector<ReservoirFailure>& reservoirFailures()
const
372 return res_failures_;
375 const std::vector<ReservoirConvergenceMetric>& reservoirConvergence()
const
377 return res_convergence_;
380 const std::vector<WellFailure>& wellFailures()
const
382 return well_failures_;
385 const std::vector<WellConvergenceMetric>& wellConvergence()
const
387 return well_convergence_;
390 const PenaltyCard& getPenaltyCard()
const
395 void addNonConvergedPenalty()
397 penaltyCard_.nonConverged++;
400 void addDistanceDecayPenalty()
402 penaltyCard_.distanceDecay++;
405 void addLargeWellResidualsPenalty()
407 penaltyCard_.largeWellResiduals++;
410 Severity severityOfWorstFailure()
const
413 auto smax = [](Severity
s1, Severity
s2) {
416 auto s = Severity::None;
417 for (
const auto&
f : res_failures_) {
418 s =
smax(s,
f.severity());
420 for (
const auto&
f : well_failures_) {
421 s =
smax(s,
f.severity());
426 template <
typename Serializer>
436 serializer(this->network_needs_more_balancing_force_another_newton_iteration_);
448 std::vector<ReservoirFailure> res_failures_;
449 std::vector<WellFailure> well_failures_;
450 std::vector<ReservoirConvergenceMetric> res_convergence_;
451 std::vector<WellConvergenceMetric> well_convergence_;
452 bool wellGroupTargetsViolated_;
453 bool network_needs_more_balancing_force_another_newton_iteration_;
454 CnvPvSplit cnvPvSplit_{};
455 double eligiblePoreVolume_{};
456 PenaltyCard penaltyCard_;