Skip to content

Commit

Permalink
Add energy balance tolerances + use standard tolerances as defaults f…
Browse files Browse the repository at this point in the history
…or now
  • Loading branch information
vkip committed Sep 16, 2024
1 parent 33b72a9 commit 18a8b5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion opm/simulators/flow/BlackoilModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ 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 @@ -1033,8 +1034,10 @@ namespace Opm {
};

Scalar tol[2] = { tol_mb, tol_cnv, };
if (has_energy_ && compIdx == contiEnergyEqIdx)
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
7 changes: 7 additions & 0 deletions opm/simulators/flow/BlackoilModelParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ 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>>();
Expand Down Expand Up @@ -112,6 +114,11 @@ 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>>
Expand Down
14 changes: 12 additions & 2 deletions opm/simulators/flow/BlackoilModelParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,23 @@ 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-4; };
struct ToleranceCnvEnergy { static constexpr Scalar value = 1e-2; };

template<class Scalar>
struct ToleranceCnvEnergyRelaxed { static constexpr Scalar value = 2.0e-4; };
struct ToleranceCnvEnergyRelaxed { static constexpr Scalar value = 1.0; };

template<class Scalar>
struct ToleranceWells { static constexpr Scalar value = 1e-4; };
Expand Down Expand Up @@ -153,6 +159,10 @@ 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_).
Expand Down

0 comments on commit 18a8b5b

Please sign in to comment.