diff --git a/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H b/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H index ed799ae4b4..51f3eecd20 100644 --- a/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H +++ b/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H @@ -1,14 +1,5 @@ { - alphav = - max - ( - min - ( - (rho - rholSat)/(rhovSat - rholSat), - scalar(1) - ), - scalar(0) - ); + alphav = clamp((rho - rholSat)/(rhovSat - rholSat), zero_one{}); alphal = 1.0 - alphav; Info<< "max-min alphav: " << max(alphav).value() diff --git a/applications/utilities/preProcessing/setAlphaField/setAlphaField.C b/applications/utilities/preProcessing/setAlphaField/setAlphaField.C index 44a67715ab..1db1a547f4 100644 --- a/applications/utilities/preProcessing/setAlphaField/setAlphaField.C +++ b/applications/utilities/preProcessing/setAlphaField/setAlphaField.C @@ -108,7 +108,7 @@ void setAlpha { cutCell.calcSubCell(cellI, 0.0); - alpha1[cellI] = max(min(cutCell.VolumeOfFluid(), 1), 0); + alpha1[cellI] = clamp(cutCell.VolumeOfFluid(), 0, 1); if (writeOBJ && (mag(cutCell.faceArea()) >= 1e-14)) { diff --git a/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C b/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C index 24cae2e413..fa121c73f1 100644 --- a/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C +++ b/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C @@ -149,7 +149,7 @@ Type Foam::uniformInterpolationTable::interpolate(scalar x) const { if (bound_) { - x = max(min(xMax() - SMALL*dx_, x), x0_); + x = clamp(x, x0_, (xMax() - SMALL*dx_)); } else { diff --git a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H index cda3b71016..2dc4e26c17 100644 --- a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H +++ b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H @@ -100,7 +100,7 @@ protected: //- that forms the basis of many more complex ramp functions inline scalar linearRamp(const scalar t) const { - return max(min((t - start_)/duration_, 1), 0); + return clamp((t - start_)/duration_, 0, 1); } diff --git a/src/TurbulenceModels/turbulenceModels/RAS/kOmegaSSTLM/kOmegaSSTLM.C b/src/TurbulenceModels/turbulenceModels/RAS/kOmegaSSTLM/kOmegaSSTLM.C index 8c30e1a403..c4a6af700a 100644 --- a/src/TurbulenceModels/turbulenceModels/RAS/kOmegaSSTLM/kOmegaSSTLM.C +++ b/src/TurbulenceModels/turbulenceModels/RAS/kOmegaSSTLM/kOmegaSSTLM.C @@ -310,7 +310,7 @@ tmp kOmegaSSTLM::ReThetat0 } lambda = sqr(thetat)/nu[celli]*dUsds[celli]; - lambda = max(min(lambda, 0.1), -0.1); + lambda = clamp(lambda, -0.1, 0.1); lambdaErr = mag(lambda - lambda0); diff --git a/src/combustionModels/EDC/EDC.C b/src/combustionModels/EDC/EDC.C index 879ac19628..66ac5e9780 100644 --- a/src/combustionModels/EDC/EDC.C +++ b/src/combustionModels/EDC/EDC.C @@ -109,13 +109,13 @@ void Foam::combustionModels::EDC::correct() const scalar nu = mu[i]/(rho[i] + SMALL); const scalar Da = - max(min(sqrt(nu/(epsilon[i] + SMALL))/tc[i], 10), 1e-10); + clamp(sqrt(nu/(epsilon[i] + SMALL))/tc[i], 1e-10, 10); const scalar ReT = sqr(k[i])/(nu*epsilon[i] + SMALL); const scalar CtauI = min(C1_/(Da*sqrt(ReT + 1)), 2.1377); const scalar CgammaI = - max(min(C2_*sqrt(Da*(ReT + 1)), 5), 0.4082); + clamp(C2_*sqrt(Da*(ReT + 1)), 0.4082, 5); const scalar gammaL = CgammaI*pow025(nu*epsilon[i]/(sqr(k[i]) + SMALL)); diff --git a/src/engine/include/StCorr.H b/src/engine/include/StCorr.H index 735bd090f2..b91e79ba41 100644 --- a/src/engine/include/StCorr.H +++ b/src/engine/include/StCorr.H @@ -80,7 +80,7 @@ ); dimensionedScalar AkEst = gSum(mgb*mesh.V().field()); - StCorr.value() = max(min((Ak/AkEst).value(), 10.0), 1.0); + StCorr.value() = clamp((Ak/AkEst).value(), 1, 10); Info<< "StCorr = " << StCorr.value() << endl; } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C index c894f8d5af..7de63c424d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C @@ -249,22 +249,18 @@ void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs() } openFraction_ = - max ( - min + openFraction_ + + min ( - openFraction_ - + min - ( - this->db().time().deltaTValue()/openingTime_, - maxOpenFractionDelta_ - ) - *(orientation_*sign(forceDiff)), - 1 - 1e-6 - ), - 1e-6 + this->db().time().deltaTValue()/openingTime_, + maxOpenFractionDelta_ + ) + *(orientation_*sign(forceDiff)) ); + openFraction_ = clamp(openFraction_, 1e-6, 1 - 1e-6); + Info<< "openFraction = " << openFraction_ << endl; vectorField::subField Sfw = this->patch().patch().faceAreas(); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C index 275cd38151..c69104703d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C @@ -299,27 +299,18 @@ void Foam::activePressureForceBaffleVelocityFvPatchVectorField::updateCoeffs() if (mag(valueDiff) > mag(minThresholdValue_) || baffleActivated_) { openFraction_ = - max + ( + openFraction_ + + min ( - min - ( - openFraction_ - + min - ( - this->db().time().deltaT().value()/openingTime_, - maxOpenFractionDelta_ - ), - 1 - 1e-6 - ), - 1e-6 - ); + this->db().time().deltaT().value()/openingTime_, + maxOpenFractionDelta_ + ) + ); - baffleActivated_ = true; - } - else - { - openFraction_ = max(min(1 - 1e-6, openFraction_), 1e-6); + baffleActivated_ = true; } + openFraction_ = clamp(openFraction_, 1e-6, 1 - 1e-6); if (Pstream::master()) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C index a234a37342..d3ddb15c90 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C @@ -148,9 +148,9 @@ void Foam::phaseHydrostaticPressureFvPatchScalarField::updateCoeffs() meshObjects::gravity::New(db().time()); // scalar rhor = 1000; - // scalarField alphap1 = max(min(alphap, scalar(1)), scalar(0)); + // scalarField alphap1 = clamp(alphap, zero_one{}); // valueFraction() = alphap1/(alphap1 + rhor*(1.0 - alphap1)); - valueFraction() = max(min(alphap, scalar(1)), scalar(0)); + valueFraction() = clamp(alphap, zero_one{}); refValue() = pRefValue_ diff --git a/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C b/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C index a33c5b99a2..8476a24df4 100644 --- a/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C +++ b/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C @@ -512,22 +512,11 @@ void Foam::averageNeighbourFvGeometryScheme::makeNonOrthoWeights scalarField& faceWeights ) const { - cosAngles = - max - ( - scalar(0), - min - ( - scalar(1), - polyMeshTools::faceOrthogonality - ( - mesh_, - faceNormals, - cellCentres - ) - ) - ); - + cosAngles = clamp + ( + polyMeshTools::faceOrthogonality(mesh_, faceNormals, cellCentres), + zero_one{} + ); // Make weight: 0 for ortho faces, 1 for 90degrees non-ortho //const scalarField faceWeights(scalar(1)-cosAngles); diff --git a/src/finiteVolume/fvMesh/fvGeometryScheme/highAspectRatio/highAspectRatioFvGeometryScheme.C b/src/finiteVolume/fvMesh/fvGeometryScheme/highAspectRatio/highAspectRatioFvGeometryScheme.C index 1202b80880..84c3eb064a 100644 --- a/src/finiteVolume/fvMesh/fvGeometryScheme/highAspectRatio/highAspectRatioFvGeometryScheme.C +++ b/src/finiteVolume/fvMesh/fvGeometryScheme/highAspectRatio/highAspectRatioFvGeometryScheme.C @@ -192,16 +192,7 @@ void Foam::highAspectRatioFvGeometryScheme::calcAspectRatioWeights delta = SMALL; } - cellWeight = - max - ( - scalar(0), - min - ( - scalar(1), - (aratio-minAspect_)/delta - ) - ); + cellWeight = clamp((aratio-minAspect_)/delta, zero_one{}); faceWeight.setSize(mesh_.nFaces()); diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MUSCL/MUSCL.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MUSCL/MUSCL.H index 9e0d97b83a..55d13e373b 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MUSCL/MUSCL.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MUSCL/MUSCL.H @@ -81,7 +81,7 @@ public: faceFlux, phiP, phiN, gradcP, gradcN, d ); - return max(min(min(2*r, 0.5*r + 0.5), 2), 0); + return clamp(min(2*r, 0.5*r + 0.5), 0, 2); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Minmod/Minmod.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Minmod/Minmod.H index 6c34e5928b..91d05ea146 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Minmod/Minmod.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Minmod/Minmod.H @@ -81,7 +81,7 @@ public: faceFlux, phiP, phiN, gradcP, gradcN, d ); - return max(min(r, 1), 0); + return clamp(r, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Phi/Phi.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Phi/Phi.H index 24c44f4d77..2b3ef8f7da 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Phi/Phi.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/Phi/Phi.H @@ -107,7 +107,7 @@ public: ((faceFlux - phiU)/stabilise(phiCD - phiU, SMALL) + k_); // Limit the limiter between upwind and central - return max(min(PLimiter, 1), 0); + return clamp(PLimiter, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICK.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICK.H index 8512576f2f..ae66624997 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICK.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICK.H @@ -100,7 +100,7 @@ public: scalar QLimiter = (phif - phiU)/stabilise(phiCD - phiU, SMALL); // Limit the limiter between upwind and downwind - return max(min(QLimiter, 2), 0); + return clamp(QLimiter, 0, 2); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICKV.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICKV.H index f71e54f197..fe6f9b011a 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICKV.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/QUICK/QUICKV.H @@ -99,7 +99,7 @@ public: scalar QLimiter = (phif - phiU)/stabilise(phiCD - phiU, SMALL); // Limit the limiter between upwind and downwind - return max(min(QLimiter, 2), 0); + return clamp(QLimiter, 0, 2); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear/filteredLinear.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear/filteredLinear.H index 6e563156ae..d7ee786056 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear/filteredLinear.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear/filteredLinear.H @@ -93,7 +93,7 @@ public: /(max(mag(dcP), mag(dcN)) + SMALL); // Limit the limiter between linear and 20% upwind - return max(min(limiter, 1), 0.8); + return clamp(limiter, 0.8, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2.H index a68fcbaf8e..9378fd1a01 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2.H @@ -141,7 +141,7 @@ public: } // Limit the limiter between linear and upwind - return max(min(limiter, 1), 0); + return clamp(limiter, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2V.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2V.H index 2a035c1e39..e8dcf7a6aa 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2V.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear2/filteredLinear2V.H @@ -143,7 +143,7 @@ public: } // Limit the limiter between linear and upwind - return max(min(limiter, 1), 0); + return clamp(limiter, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H index 48105a0b34..043a0e5630 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H @@ -108,7 +108,7 @@ public: scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), SMALL); // Limit the limiter between linear and upwind - return max(min(limiter, 1), 0); + return clamp(limiter, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H index 9c2f596b86..d69562b2e5 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H @@ -110,7 +110,7 @@ public: scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), SMALL); // Limit the limiter between linear and upwind - return max(min(limiter, 1), 0); + return clamp(limiter, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubic.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubic.H index 2a9408ce0e..5ca1cbb0c7 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubic.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubic.H @@ -124,11 +124,11 @@ public: cubicLimiter = twor; } - return max(min(cubicLimiter, 2), 0); + return clamp(cubicLimiter, 0, 2); */ // Limit the limiter to obey the TVD constraint - return max(min(min(twor, cubicLimiter), 2), 0); + return clamp(min(twor, cubicLimiter), 0, 2); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubicV.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubicV.H index 3efede0496..b67b474765 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubicV.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedCubic/limitedCubicV.H @@ -122,7 +122,7 @@ public: (fVphif - fVphiU)/stabilise(fVphiCD - fVphiU, SMALL); // Limit the limiter to obey the TVD constraint - return max(min(min(twor, cubicLimiter), 2), 0); + return clamp(min(twor, cubicLimiter), 0, 2); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedLinear/limitedLinear.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedLinear/limitedLinear.H index 819ddd8af8..159bcc695e 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedLinear/limitedLinear.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/limitedLinear/limitedLinear.H @@ -97,7 +97,7 @@ public: faceFlux, phiP, phiN, gradcP, gradcN, d ); - return max(min(twoByk_*r, 1), 0); + return clamp(twoByk_*r, 0, 1); } }; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/CoBlended/CoBlended.H b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/CoBlended/CoBlended.H index aa1f10e44d..80bd3add72 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/CoBlended/CoBlended.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/CoBlended/CoBlended.H @@ -36,7 +36,7 @@ Description face-based Courant number and the lower and upper Courant number limits supplied: \f[ - weight = 1 - max(min((Co - Co1)/(Co2 - Co1), 1), 0) + weight = 1 - clamp((Co - Co1)/(Co2 - Co1), 0, 1) \f] where \vartable @@ -222,18 +222,14 @@ public: ( vf.name() + "BlendingFactor", scalar(1) - - max + - clamp ( - min ( - ( - mesh.time().deltaT()*mesh.deltaCoeffs() - *mag(tUflux)/mesh.magSf() - - Co1_ - )/(Co2_ - Co1_), - scalar(1) - ), - scalar(0) + mesh.time().deltaT()*mesh.deltaCoeffs() + *mag(tUflux)/mesh.magSf() + - Co1_ + )/(Co2_ - Co1_), + zero_one{} ) ) ); diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/cellCoBlended/cellCoBlended.H b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/cellCoBlended/cellCoBlended.H index 488713445a..d9ca8e77a3 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/cellCoBlended/cellCoBlended.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/cellCoBlended/cellCoBlended.H @@ -253,14 +253,10 @@ public: ( vf.name() + "BlendingFactor", scalar(1) - - max + - clamp ( - min - ( - (fvc::interpolate(Co) - Co1_)/(Co2_ - Co1_), - scalar(1) - ), - scalar(0) + (fvc::interpolate(Co) - Co1_)/(Co2_ - Co1_), + zero_one{} ) ) ); diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/clippedLinear/clippedLinear.H b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/clippedLinear/clippedLinear.H index e2f10a660c..4ed0fd576d 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/clippedLinear/clippedLinear.H +++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/clippedLinear/clippedLinear.H @@ -58,25 +58,24 @@ class clippedLinear : public surfaceInterpolationScheme { - // Private data + // Private Data - const scalar cellSizeRatio_; scalar wfLimit_; // Private Member Functions - void calcWfLimit() + static scalar calcWfLimit(scalar cellSizeRatio) { - if (cellSizeRatio_ <= 0 || cellSizeRatio_ > 1) + if (cellSizeRatio <= 0 || cellSizeRatio > 1) { FatalErrorInFunction - << "Given cellSizeRatio of " << cellSizeRatio_ + << "Given cellSizeRatio of " << cellSizeRatio << " is not between 0 and 1" << exit(FatalError); } - wfLimit_ = cellSizeRatio_/(1.0 + cellSizeRatio_); + return cellSizeRatio/(1.0 + cellSizeRatio); } @@ -96,19 +95,15 @@ public: clippedLinear(const fvMesh& mesh, const scalar cellSizeRatio) : surfaceInterpolationScheme(mesh), - cellSizeRatio_(cellSizeRatio) - { - calcWfLimit(); - } + wfLimit_(calcWfLimit(cellSizeRatio)) + {} //- Construct from Istream clippedLinear(const fvMesh& mesh, Istream& is) : surfaceInterpolationScheme(mesh), - cellSizeRatio_(readScalar(is)) - { - calcWfLimit(); - } + wfLimit_(calcWfLimit(readScalar(is))) + {} //- Construct from faceFlux and Istream clippedLinear @@ -119,10 +114,8 @@ public: ) : surfaceInterpolationScheme(mesh), - cellSizeRatio_(readScalar(is)) - { - calcWfLimit(); - } + wfLimit_(calcWfLimit(readScalar(is))) + {} // Member Functions @@ -141,6 +134,8 @@ public: ); const surfaceScalarField& cdWeights = tcdWeights(); + const scalarMinMax bounds(wfLimit_, 1 - wfLimit_); + tmp tclippedLinearWeights ( new surfaceScalarField @@ -159,7 +154,7 @@ public: tclippedLinearWeights.ref(); clippedLinearWeights.primitiveFieldRef() = - max(min(cdWeights.primitiveField(), 1 - wfLimit_), wfLimit_); + clamp(cdWeights.primitiveField(), bounds); surfaceScalarField::Boundary& clwbf = clippedLinearWeights.boundaryFieldRef(); @@ -169,15 +164,7 @@ public: if (clwbf[patchi].coupled()) { clwbf[patchi] = - max - ( - min - ( - cdWeights.boundaryField()[patchi], - 1 - wfLimit_ - ), - wfLimit_ - ); + clamp(cdWeights.boundaryField()[patchi], bounds); } else { diff --git a/src/lagrangian/spray/submodels/BreakupModel/ETAB/ETAB.C b/src/lagrangian/spray/submodels/BreakupModel/ETAB/ETAB.C index 5d6bdb0172..c642019c79 100644 --- a/src/lagrangian/spray/submodels/BreakupModel/ETAB/ETAB.C +++ b/src/lagrangian/spray/submodels/BreakupModel/ETAB/ETAB.C @@ -131,7 +131,7 @@ bool Foam::ETAB::update scalar phic = y1/a; // constrain phic within -1 to 1 - phic = max(min(phic, 1), -1); + phic = clamp(phic, -1, 1); scalar phit = acos(phic); scalar phi = phit; diff --git a/src/lagrangian/spray/submodels/BreakupModel/TAB/TAB.C b/src/lagrangian/spray/submodels/BreakupModel/TAB/TAB.C index 97202f99c2..f7d552949a 100644 --- a/src/lagrangian/spray/submodels/BreakupModel/TAB/TAB.C +++ b/src/lagrangian/spray/submodels/BreakupModel/TAB/TAB.C @@ -143,7 +143,7 @@ bool Foam::TAB::update scalar phic = y1/a; // constrain phic within -1 to 1 - phic = max(min(phic, 1), -1); + phic = clamp(phic, -1, 1); scalar phit = acos(phic); scalar phi = phit; diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/lineSearch/lineSearch/lineSearch.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/lineSearch/lineSearch/lineSearch.C index 571adab467..ef4a26bfee 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/lineSearch/lineSearch/lineSearch.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/lineSearch/lineSearch/lineSearch.C @@ -167,7 +167,7 @@ void Foam::lineSearch::reset() // step_ = 2*(oldMeritValue_-prevMeritValue_)/directionalDeriv_; // Interpolate in order to get same improvement with the previous // optimisation cycle - step_ = max(min(step_*prevMeritDeriv_/directionalDeriv_, 1.), minStep_); + step_ = clamp(step_*prevMeritDeriv_/directionalDeriv_, minStep_, 1); Info<< "\n------- Computing initial step-------" << endl; Info<< "old dphi(0) " << prevMeritDeriv_ << endl; Info<< "dphi(0) " << directionalDeriv_ << endl; diff --git a/src/phaseSystemModels/multiphaseInter/phasesSystem/MassTransferPhaseSystem/MassTransferPhaseSystem.C b/src/phaseSystemModels/multiphaseInter/phasesSystem/MassTransferPhaseSystem/MassTransferPhaseSystem.C index 559fee3e63..e9039e3971 100644 --- a/src/phaseSystemModels/multiphaseInter/phasesSystem/MassTransferPhaseSystem/MassTransferPhaseSystem.C +++ b/src/phaseSystemModels/multiphaseInter/phasesSystem/MassTransferPhaseSystem/MassTransferPhaseSystem.C @@ -617,7 +617,7 @@ void Foam::MassTransferPhaseSystem::alphaTransfer scalar dmdt21 = dmdtNet[celli]; scalar coeffs12Cell = coeffs12[celli]; - scalar alpha1Limited = max(min(alpha1[celli], 1.0), 0.0); + scalar alpha1Limited = clamp(alpha1[celli], 0, 1); // exp. SuPhase1[celli] += coeffs1[celli]*dmdt21; @@ -660,7 +660,7 @@ void Foam::MassTransferPhaseSystem::alphaTransfer scalar dmdt12 = -dmdtNet[celli]; scalar coeffs21Cell = -coeffs12[celli]; - scalar alpha2Limited = max(min(alpha2[celli], 1.0), 0.0); + scalar alpha2Limited = clamp(alpha2[celli], 0, 1); // exp SuPhase2[celli] += coeffs2[celli]*dmdt12; diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/TDNBModels/Shirai/Shirai.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/TDNBModels/Shirai/Shirai.C index d8e1700687..d446b54588 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/TDNBModels/Shirai/Shirai.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/TDNBModels/Shirai/Shirai.C @@ -75,7 +75,7 @@ Foam::wallBoilingModels::TDNBModels::Shirai::TDNB { tmp tp = liquid.thermo().p().boundaryField()[patchi]; - const scalarField pRatio(max(min(tp/Pc_, scalar(1)), scalar(0))); + const scalarField pRatio(clamp(tp/Pc_, zero_one{})); return ( diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/departureDiameterModels/TolubinskiKostanchuk/TolubinskiKostanchuk.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/departureDiameterModels/TolubinskiKostanchuk/TolubinskiKostanchuk.C index 9ee761d938..f724b50bdb 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/departureDiameterModels/TolubinskiKostanchuk/TolubinskiKostanchuk.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/derivedFvPatchFields/wallBoilingSubModels/departureDiameterModels/TolubinskiKostanchuk/TolubinskiKostanchuk.C @@ -78,7 +78,11 @@ TolubinskiKostanchuk::dDeparture const scalarField& L ) const { - return max(min(dRef_*exp(-(Tsatw - Tl)/scalar(45)), dMax_), dMin_); + return clamp + ( + dRef_*exp(-(Tsatw - Tl)/scalar(45)), + scalarMinMax(dMin_, dMax_) + ); } diff --git a/src/regionFaModels/liquidFilm/subModels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C b/src/regionFaModels/liquidFilm/subModels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C index ee40e48424..77b628724c 100644 --- a/src/regionFaModels/liquidFilm/subModels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C +++ b/src/regionFaModels/liquidFilm/subModels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C @@ -148,7 +148,7 @@ tmp curvatureSeparation::calcCosAngle volCosAngle.write(); } - return max(min(cosAngle, scalar(1)), scalar(-1)); + return clamp(cosAngle, scalarMinMax(-1, 1)); } diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C index d46e00a9f9..a5474ef420 100644 --- a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C +++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/curvatureSeparation/curvatureSeparation.C @@ -215,7 +215,7 @@ tmp curvatureSeparation::calcCosAngle volCosAngle.write(); } - return max(min(cosAngle, scalar(1)), scalar(-1)); + return clamp(cosAngle, scalarMinMax(-1, 1)); } diff --git a/src/transportModels/geometricVoF/reconstructionSchemes/plicSchemes/plicRDF/plicRDF.C b/src/transportModels/geometricVoF/reconstructionSchemes/plicSchemes/plicRDF/plicRDF.C index 10fe2c055a..62db3416f8 100644 --- a/src/transportModels/geometricVoF/reconstructionSchemes/plicSchemes/plicRDF/plicRDF.C +++ b/src/transportModels/geometricVoF/reconstructionSchemes/plicSchemes/plicRDF/plicRDF.C @@ -279,7 +279,7 @@ void Foam::reconstruction::plicRDF::calcResidual if (mag(normal) != 0 && j != 0) { vector n = normal/mag(normal); - scalar cosAngle = max(min((cellNormal & n), 1), -1); + scalar cosAngle = clamp((cellNormal & n), -1, 1); avgDiffNormal += acos(cosAngle) * mag(normal); weight += mag(normal); if (cosAngle < maxDiffNormal) diff --git a/src/transportModels/interfaceProperties/alphaContactAngle/alphaContactAngleTwoPhaseFvPatchScalarField.C b/src/transportModels/interfaceProperties/alphaContactAngle/alphaContactAngleTwoPhaseFvPatchScalarField.C index 580b4e7310..401b53ab91 100644 --- a/src/transportModels/interfaceProperties/alphaContactAngle/alphaContactAngleTwoPhaseFvPatchScalarField.C +++ b/src/transportModels/interfaceProperties/alphaContactAngle/alphaContactAngleTwoPhaseFvPatchScalarField.C @@ -133,11 +133,8 @@ void Foam::alphaContactAngleTwoPhaseFvPatchScalarField::evaluate gradient() = patch().deltaCoeffs() *( - max(min - ( - *this + gradient()/patch().deltaCoeffs(), - scalar(1)), scalar(0) - ) - *this + clamp(*this + gradient()/patch().deltaCoeffs(), zero_one{}) + - *this ); } else if (limit_ == lcZeroGradient) @@ -149,7 +146,7 @@ void Foam::alphaContactAngleTwoPhaseFvPatchScalarField::evaluate if (limit_ == lcAlpha) { - scalarField::operator=(max(min(*this, scalar(1)), scalar(0))); + scalarField::operator=(clamp(*this, zero_one{})); } }