From dc82ab6c29082cb2a91ab91feae8f30544d7fb3c Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 16 May 2025 09:23:46 +0200 Subject: [PATCH] richardsnewtonmethod: cosmetics --- opm/models/richards/richardsnewtonmethod.hh | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/opm/models/richards/richardsnewtonmethod.hh b/opm/models/richards/richardsnewtonmethod.hh index be7998ca74..1d644c1e40 100644 --- a/opm/models/richards/richardsnewtonmethod.hh +++ b/opm/models/richards/richardsnewtonmethod.hh @@ -68,7 +68,8 @@ class RichardsNewtonMethod : public GetPropType; public: - explicit RichardsNewtonMethod(Simulator& simulator) : ParentType(simulator) + explicit RichardsNewtonMethod(Simulator& simulator) + : ParentType(simulator) {} protected: @@ -89,8 +90,9 @@ protected: nextValue -= update; // do not clamp anything after 4 iterations - if (this->numIterations_ > 4) + if (this->numIterations_ > 4) { return; + } const auto& problem = this->simulator_.problem(); @@ -98,10 +100,10 @@ protected: const MaterialLawParams& matParams = problem.materialLawParams(globalDofIdx, /*timeIdx=*/0); - Opm::ImmiscibleFluidState fs; + ImmiscibleFluidState fs; // set the temperature - Scalar T = problem.temperature(globalDofIdx, /*timeIdx=*/0); + const Scalar T = problem.temperature(globalDofIdx, /*timeIdx=*/0); fs.setTemperature(T); ///////// @@ -118,8 +120,8 @@ protected: // non-wetting pressure can be larger than the // reference pressure if the medium is fully // saturated by the wetting phase - Scalar pWOld = currentValue[pressureWIdx]; - Scalar pNOld = + const Scalar pWOld = currentValue[pressureWIdx]; + const Scalar pNOld = std::max(problem.referencePressure(globalDofIdx, /*timeIdx=*/0), pWOld + (pC[gasPhaseIdx] - pC[liquidPhaseIdx])); @@ -131,7 +133,7 @@ protected: PhaseVector satOld; MaterialLaw::saturations(satOld, matParams, fs); - satOld[liquidPhaseIdx] = std::max(0.0, satOld[liquidPhaseIdx]); + satOld[liquidPhaseIdx] = std::max(Scalar{0.0}, satOld[liquidPhaseIdx]); ///////// // find the wetting phase pressures which @@ -141,22 +143,22 @@ protected: fs.setSaturation(liquidPhaseIdx, satOld[liquidPhaseIdx] - 0.2); fs.setSaturation(gasPhaseIdx, 1.0 - (satOld[liquidPhaseIdx] - 0.2)); MaterialLaw::capillaryPressures(pC, matParams, fs); - Scalar pwMin = pNOld - (pC[gasPhaseIdx] - pC[liquidPhaseIdx]); + const Scalar pwMin = pNOld - (pC[gasPhaseIdx] - pC[liquidPhaseIdx]); fs.setSaturation(liquidPhaseIdx, satOld[liquidPhaseIdx] + 0.2); fs.setSaturation(gasPhaseIdx, 1.0 - (satOld[liquidPhaseIdx] + 0.2)); MaterialLaw::capillaryPressures(pC, matParams, fs); - Scalar pwMax = pNOld - (pC[gasPhaseIdx] - pC[liquidPhaseIdx]); + const Scalar pwMax = pNOld - (pC[gasPhaseIdx] - pC[liquidPhaseIdx]); ///////// // clamp the result to the minimum and the maximum // pressures we just calculated ///////// - Scalar pW = nextValue[pressureWIdx]; - pW = std::max(pwMin, std::min(pW, pwMax)); + const Scalar pW = std::clamp(nextValue[pressureWIdx], pwMin, pwMax); nextValue[pressureWIdx] = pW; } }; + } // namespace Opm #endif