make relaxationFactorRate an anon helper in StandardWellPrimaryVariables

This commit is contained in:
Arne Morten Kvarving 2022-11-09 10:42:53 +01:00
parent 3f6c4922b0
commit 2fbc699007
3 changed files with 25 additions and 31 deletions

View File

@ -55,31 +55,6 @@ StandardWellGeneric(const WellInterfaceGeneric& baseif)
{
}
template<class Scalar>
double
StandardWellGeneric<Scalar>::
relaxationFactorRate(const std::vector<double>& primary_variables,
const double newton_update)
{
double relaxation_factor = 1.0;
static constexpr int WQTotal = 0;
// For injector, we only check the total rates to avoid sign change of rates
const double original_total_rate = primary_variables[WQTotal];
const double possible_update_total_rate = primary_variables[WQTotal] - newton_update;
// 0.8 here is a experimental value, which remains to be optimized
// if the original rate is zero or possible_update_total_rate is zero, relaxation_factor will
// always be 1.0, more thoughts might be needed.
if (original_total_rate * possible_update_total_rate < 0.) { // sign changed
relaxation_factor = std::abs(original_total_rate / newton_update) * 0.8;
}
assert(relaxation_factor >= 0.0 && relaxation_factor <= 1.0);
return relaxation_factor;
}
template<class Scalar>
void
StandardWellGeneric<Scalar>::

View File

@ -48,11 +48,6 @@ class WellState;
template<class Scalar>
class StandardWellGeneric
{
public:
// calculate a relaxation factor to avoid overshoot of total rates
static double relaxationFactorRate(const std::vector<double>& primary_variables,
const double newton_update);
protected:
StandardWellGeneric(const WellInterfaceGeneric& baseif);

View File

@ -68,6 +68,30 @@ Scalar relaxationFactorFraction(const Scalar old_value,
return relaxation_factor;
}
//! \brief Calculate a relaxation factor to avoid overshoot of total rates.
template<class Scalar>
Scalar relaxationFactorRate(const std::vector<Scalar>& primary_variables,
const Scalar newton_update)
{
Scalar relaxation_factor = 1.0;
static constexpr int WQTotal = 0;
// For injector, we only check the total rates to avoid sign change of rates
const Scalar original_total_rate = primary_variables[WQTotal];
const Scalar possible_update_total_rate = primary_variables[WQTotal] - newton_update;
// 0.8 here is a experimental value, which remains to be optimized
// if the original rate is zero or possible_update_total_rate is zero, relaxation_factor will
// always be 1.0, more thoughts might be needed.
if (original_total_rate * possible_update_total_rate < 0.) { // sign changed
relaxation_factor = std::abs(original_total_rate / newton_update) * 0.8;
}
assert(relaxation_factor >= 0.0 && relaxation_factor <= 1.0);
return relaxation_factor;
}
}
namespace Opm {
@ -253,7 +277,7 @@ updateNewton(const BVectorWell& dwells,
this->processFractions();
// updating the total rates Q_t
const double relaxation_factor_rate = StandardWellGeneric<Scalar>::relaxationFactorRate(old_primary_variables, dwells[0][WQTotal]);
const double relaxation_factor_rate = relaxationFactorRate(old_primary_variables, dwells[0][WQTotal]);
value_[WQTotal] = old_primary_variables[WQTotal] - dwells[0][WQTotal] * relaxation_factor_rate;
// updating the bottom hole pressure