Add well convergence metric

This commit is contained in:
jakobtorben 2024-09-09 17:25:45 +02:00
parent 861cfeec49
commit 56da84517b
2 changed files with 58 additions and 0 deletions

View File

@ -191,6 +191,43 @@ namespace Opm
std::string well_name_ {};
};
class WellConvergenceMetric
{
public:
// Default constructor needed for object serialisation. Don't
// use this for anything else.
WellConvergenceMetric() = default;
WellConvergenceMetric(WellFailure::Type t, Severity s, int phase, double value, const std::string& well_name)
: type_(t), severity_(s), phase_(phase), value_(value), well_name_(well_name)
{}
WellFailure::Type type() const { return type_; }
Severity severity() const { return severity_; }
int phase() const { return phase_; }
double value() const { return value_; }
const std::string& wellName() const { return well_name_; }
template <typename Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->type_);
serializer(this->severity_);
serializer(this->phase_);
serializer(this->value_);
serializer(this->well_name_);
}
private:
// Note to maintainers: If you change this list of data members,
// then please update serializeOp() accordingly.
WellFailure::Type type_ { WellFailure::Type::Invalid };
Severity severity_ { Severity::None };
int phase_ { -1 };
double value_ { 0.0 };
std::string well_name_ {};
};
// ----------- Mutating member functions -----------
ConvergenceReport()
@ -231,6 +268,12 @@ namespace Opm
this->res_convergence_.emplace_back(std::forward<Args>(args)...);
}
template <typename... Args>
void setWellConvergenceMetric(Args&&... args)
{
this->well_convergence_.emplace_back(std::forward<Args>(args)...);
}
void setWellGroupTargetsViolated(const bool wellGroupTargetsViolated)
{
wellGroupTargetsViolated_ = wellGroupTargetsViolated;
@ -250,6 +293,7 @@ namespace Opm
res_failures_.insert(res_failures_.end(), other.res_failures_.begin(), other.res_failures_.end());
well_failures_.insert(well_failures_.end(), other.well_failures_.begin(), other.well_failures_.end());
res_convergence_.insert(res_convergence_.end(), other.res_convergence_.begin(), other.res_convergence_.end());
well_convergence_.insert(well_convergence_.end(), other.well_convergence_.begin(), other.well_convergence_.end());
assert(reservoirFailed() != res_failures_.empty());
assert(wellFailed() != well_failures_.empty());
wellGroupTargetsViolated_ = (wellGroupTargetsViolated_ || other.wellGroupTargetsViolated_);
@ -316,6 +360,11 @@ namespace Opm
return well_failures_;
}
const std::vector<WellConvergenceMetric>& wellConvergence() const
{
return well_convergence_;
}
const PenaltyCard& getPenaltyCard() const
{
return penaltyCard_;
@ -360,6 +409,7 @@ namespace Opm
serializer(this->res_failures_);
serializer(this->well_failures_);
serializer(this->res_convergence_);
serializer(this->well_convergence_);
serializer(this->wellGroupTargetsViolated_);
serializer(this->cnvPvSplit_);
serializer(this->eligiblePoreVolume_);
@ -375,6 +425,7 @@ namespace Opm
std::vector<ReservoirFailure> res_failures_;
std::vector<WellFailure> well_failures_;
std::vector<ReservoirConvergenceMetric> res_convergence_;
std::vector<WellConvergenceMetric> well_convergence_;
bool wellGroupTargetsViolated_;
CnvPvSplit cnvPvSplit_{};
double eligiblePoreVolume_{};

View File

@ -134,13 +134,20 @@ getWellConvergence(const WellState<Scalar>& well_state,
if (std::isnan(well_flux_residual[compIdx])) {
report.setWellFailed({type, CR::Severity::NotANumber, compIdx, baseif_.name()});
report.setWellConvergenceMetric(type, CR::Severity::NotANumber, compIdx, well_flux_residual[compIdx], baseif_.name());
} else if (well_flux_residual[compIdx] > maxResidualAllowed) {
report.setWellFailed({type, CR::Severity::TooLarge, compIdx, baseif_.name()});
report.setWellConvergenceMetric(type, CR::Severity::TooLarge, compIdx, well_flux_residual[compIdx], baseif_.name());
} else if (!relax_tolerance && well_flux_residual[compIdx] > tol_wells) {
report.setWellFailed({type, CR::Severity::Normal, compIdx, baseif_.name()});
report.setWellConvergenceMetric(type, CR::Severity::Normal, compIdx, well_flux_residual[compIdx], baseif_.name());
} else if (well_flux_residual[compIdx] > relaxed_tolerance_flow) {
report.setWellFailed({type, CR::Severity::Normal, compIdx, baseif_.name()});
report.setWellConvergenceMetric(type, CR::Severity::Normal, compIdx, well_flux_residual[compIdx], baseif_.name());
} else {
report.setWellConvergenceMetric(CR::WellFailure::Type::Invalid, CR::Severity::None, compIdx, well_flux_residual[compIdx], baseif_.name());
}
}
WellConvergence(baseif_).