Skip to content

Commit

Permalink
Merge pull request OPM#5321 from vkip/energy_cnv
Browse files Browse the repository at this point in the history
Adding a separate CNV tolerance for energy (default 1.0e-4)
  • Loading branch information
totto82 authored Sep 16, 2024
2 parents 3a5d527 + 18a8b5b commit 2f47f41
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion opm/simulators/flow/BlackoilModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ namespace Opm {

const auto tol_cnv = use_relaxed_cnv ? param_.tolerance_cnv_relaxed_ : param_.tolerance_cnv_;
const auto tol_mb = use_relaxed_mb ? param_.tolerance_mb_relaxed_ : param_.tolerance_mb_;
const auto tol_cnv_energy = use_relaxed_cnv ? param_.tolerance_cnv_energy_relaxed_ : param_.tolerance_cnv_energy_;
const auto tol_eb = use_relaxed_mb ? param_.tolerance_energy_balance_relaxed_ : param_.tolerance_energy_balance_;

// Finish computation
std::vector<Scalar> CNV(numComp);
Expand All @@ -1031,7 +1033,11 @@ namespace Opm {
CR::ReservoirFailure::Type::Cnv,
};

const Scalar tol[2] = { tol_mb, tol_cnv, };
Scalar tol[2] = { tol_mb, tol_cnv, };
if (has_energy_ && compIdx == contiEnergyEqIdx) {
tol[0] = tol_eb;
tol[1] = tol_cnv_energy;
}

for (int ii : {0, 1}) {
if (std::isnan(res[ii])) {
Expand Down
14 changes: 14 additions & 0 deletions opm/simulators/flow/BlackoilModelParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ BlackoilModelParameters<Scalar>::BlackoilModelParameters()
relaxed_max_pv_fraction_ = Parameters::Get<Parameters::RelaxedMaxPvFraction<Scalar>>();
tolerance_mb_ = Parameters::Get<Parameters::ToleranceMb<Scalar>>();
tolerance_mb_relaxed_ = std::max(tolerance_mb_, Parameters::Get<Parameters::ToleranceMbRelaxed<Scalar>>());
tolerance_energy_balance_ = Parameters::Get<Parameters::ToleranceEnergyBalance<Scalar>>();
tolerance_energy_balance_relaxed_ = std::max(tolerance_energy_balance_, Parameters::Get<Parameters::ToleranceEnergyBalanceRelaxed<Scalar>>());
tolerance_cnv_ = Parameters::Get<Parameters::ToleranceCnv<Scalar>>();
tolerance_cnv_relaxed_ = std::max(tolerance_cnv_, Parameters::Get<Parameters::ToleranceCnvRelaxed<Scalar>>());
tolerance_cnv_energy_ = Parameters::Get<Parameters::ToleranceCnvEnergy<Scalar>>();
tolerance_cnv_energy_relaxed_ = std::max(tolerance_cnv_energy_, Parameters::Get<Parameters::ToleranceCnvEnergyRelaxed<Scalar>>());
tolerance_wells_ = Parameters::Get<Parameters::ToleranceWells<Scalar>>();
tolerance_well_control_ = Parameters::Get<Parameters::ToleranceWellControl<Scalar>>();
max_welleq_iter_ = Parameters::Get<Parameters::MaxWelleqIter>();
Expand Down Expand Up @@ -110,11 +114,21 @@ void BlackoilModelParameters<Scalar>::registerParameters()
Parameters::Register<Parameters::ToleranceMbRelaxed<Scalar>>
("Relaxed tolerated mass balance error that applies for iterations "
"after the iterations with the strict tolerance");
Parameters::Register<Parameters::ToleranceEnergyBalance<Scalar>>
("Tolerated energy balance error relative to (scaled) total energy present");
Parameters::Register<Parameters::ToleranceEnergyBalanceRelaxed<Scalar>>
("Relaxed tolerated energy balance error that applies for iterations "
"after the iterations with the strict tolerance");
Parameters::Register<Parameters::ToleranceCnv<Scalar>>
("Local convergence tolerance (Maximum of local saturation errors)");
Parameters::Register<Parameters::ToleranceCnvRelaxed<Scalar>>
("Relaxed local convergence tolerance that applies for iterations "
"after the iterations with the strict tolerance");
Parameters::Register<Parameters::ToleranceCnvEnergy<Scalar>>
("Local energy convergence tolerance (Maximum of local energy errors)");
Parameters::Register<Parameters::ToleranceCnvEnergyRelaxed<Scalar>>
("Relaxed local energy convergence tolerance that applies for iterations "
"after the iterations with the strict tolerance");
Parameters::Register<Parameters::ToleranceWells<Scalar>>
("Well convergence tolerance");
Parameters::Register<Parameters::ToleranceWellControl<Scalar>>
Expand Down
20 changes: 20 additions & 0 deletions opm/simulators/flow/BlackoilModelParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ struct ToleranceMb { static constexpr Scalar value = 1e-7; };
template<class Scalar>
struct ToleranceMbRelaxed { static constexpr Scalar value = 1e-6; };

template<class Scalar>
struct ToleranceEnergyBalance { static constexpr Scalar value = 1e-7; };

template<class Scalar>
struct ToleranceEnergyBalanceRelaxed { static constexpr Scalar value = 1e-6; };

template<class Scalar>
struct ToleranceCnv { static constexpr Scalar value = 1e-2; };

template<class Scalar>
struct ToleranceCnvRelaxed { static constexpr Scalar value = 1.0; };

template<class Scalar>
struct ToleranceCnvEnergy { static constexpr Scalar value = 1e-2; };

template<class Scalar>
struct ToleranceCnvEnergyRelaxed { static constexpr Scalar value = 1.0; };

template<class Scalar>
struct ToleranceWells { static constexpr Scalar value = 1e-4; };

Expand Down Expand Up @@ -147,10 +159,18 @@ struct BlackoilModelParameters
Scalar tolerance_mb_;
/// Relaxed mass balance tolerance (can be used when iter >= min_strict_mb_iter_).
Scalar tolerance_mb_relaxed_;
/// Relative energy balance tolerance (total energy balance error).
Scalar tolerance_energy_balance_;
/// Relaxed energy balance tolerance (can be used when iter >= min_strict_mb_iter_).
Scalar tolerance_energy_balance_relaxed_;
/// Local convergence tolerance (max of local saturation errors).
Scalar tolerance_cnv_;
/// Relaxed local convergence tolerance (can be used when iter >= min_strict_cnv_iter_ && cnvViolatedPV < relaxed_max_pv_fraction_).
Scalar tolerance_cnv_relaxed_;
/// Local energy convergence tolerance (max of local energy errors).
Scalar tolerance_cnv_energy_;
/// Relaxed local energy convergence tolerance (can be used when iter >= min_strict_cnv_iter_ && cnvViolatedPV < relaxed_max_pv_fraction_).
Scalar tolerance_cnv_energy_relaxed_;
/// Well convergence tolerance.
Scalar tolerance_wells_;
/// Tolerance for the well control equations
Expand Down

0 comments on commit 2f47f41

Please sign in to comment.