From 0be19b7fae79259447ae9683e5e06645c1c6de17 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 2 Apr 2025 21:23:16 +0200
Subject: [PATCH] COMP: namespace qualify min/max functions (#3348)

FIX: missing patch face index writeFields (#3347)
---
 .../compressibleInterFoam/alphaSuSp.H         |  6 +-
 .../compressibleInterIsoFoam/alphaSuSp.H      |  6 +-
 .../overCompressibleInterDyMFoam/alphaSuSp.H  |  6 +-
 .../makeFaMesh/checkPatchTopology.H           |  4 +-
 .../utilities/mesh/advanced/PDRMesh/PDRMesh.C |  3 +-
 .../mesh/conversion/cfx4ToFoam/cfx4ToFoam.C   | 10 +--
 .../conversion/gambitToFoam/gambitToFoam.L    |  4 +-
 .../ideasUnvToFoam/ideasUnvToFoam.C           |  4 +-
 .../mesh/conversion/kivaToFoam/checkPatch.H   |  6 +-
 .../mesh/conversion/kivaToFoam/readKivaGrid.H |  6 +-
 .../netgenNeutralToFoam/netgenNeutralToFoam.C |  2 +-
 .../extrudeToRegionMesh/extrudeToRegionMesh.C | 14 ++--
 .../mesh/manipulation/checkMesh/writeFields.C | 68 +++++++++----------
 .../manipulation/renumberMesh/renumberMesh.C  |  8 ++-
 .../mesh/manipulation/setSet/setSet.C         |  6 +-
 .../mesh/manipulation/subsetMesh/subsetMesh.C |  3 +-
 .../reconstructParMesh/reconstructParMesh.C   |  2 +-
 .../redistributePar/redistributePar.C         |  6 +-
 .../particleTracks/particleTracks.C           |  4 +-
 .../PDR/pdrFields/PDRarraysCalc.C             | 14 ++--
 .../PDR/pdrFields/PDRutilsOverlap.C           | 18 ++---
 .../preProcessing/engineSwirl/engineSwirl.C   |  4 +-
 .../surface/surfaceCheck/surfaceCheck.C       |  4 +-
 .../surface/surfaceHookUp/surfaceHookUp.C     |  2 +-
 .../surface/surfaceInflate/surfaceInflate.C   | 12 ++--
 .../surfaceMeshExtract/surfaceMeshExtract.C   |  2 +-
 .../adiabaticFlameT/adiabaticFlameT.C         |  4 +-
 .../equilibriumFlameT/equilibriumFlameT.C     | 12 ++--
 .../faDecompose/faMeshDecomposition.C         |  9 ++-
 .../pyrolysisModel/pyrolysisModelCollection.C |  6 +-
 30 files changed, 127 insertions(+), 128 deletions(-)

diff --git a/applications/solvers/multiphase/compressibleInterFoam/alphaSuSp.H b/applications/solvers/multiphase/compressibleInterFoam/alphaSuSp.H
index ce2e5520015..cc698aefed8 100644
--- a/applications/solvers/multiphase/compressibleInterFoam/alphaSuSp.H
+++ b/applications/solvers/multiphase/compressibleInterFoam/alphaSuSp.H
@@ -26,12 +26,12 @@ forAll(dgdt, celli)
 {
     if (dgdt[celli] > 0.0)
     {
-        Sp[celli] -= dgdt[celli]/max(1.0 - alpha1[celli], 1e-4);
-        Su[celli] += dgdt[celli]/max(1.0 - alpha1[celli], 1e-4);
+        Sp[celli] -= dgdt[celli]/Foam::max(1.0 - alpha1[celli], 1e-4);
+        Su[celli] += dgdt[celli]/Foam::max(1.0 - alpha1[celli], 1e-4);
     }
     else if (dgdt[celli] < 0.0)
     {
-        Sp[celli] += dgdt[celli]/max(alpha1[celli], 1e-4);
+        Sp[celli] += dgdt[celli]/Foam::max(alpha1[celli], 1e-4);
     }
 }
 
diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterIsoFoam/alphaSuSp.H b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterIsoFoam/alphaSuSp.H
index 65c5750ff94..457f40891af 100644
--- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterIsoFoam/alphaSuSp.H
+++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterIsoFoam/alphaSuSp.H
@@ -26,12 +26,12 @@ forAll(dgdt, celli)
 {
     if (dgdt[celli] > 0.0)
     {
-        Sp[celli] -= dgdt[celli]/max(1.0 - alpha1[celli], 1e-4);
-        Su[celli] += dgdt[celli]/max(1.0 - alpha1[celli], 1e-4);
+        Sp[celli] -= dgdt[celli]/Foam::max(1.0 - alpha1[celli], 1e-4);
+        Su[celli] += dgdt[celli]/Foam::max(1.0 - alpha1[celli], 1e-4);
     }
     else if (dgdt[celli] < 0.0)
     {
-        Sp[celli] += dgdt[celli]/max(alpha1[celli], 1e-4);
+        Sp[celli] += dgdt[celli]/Foam::max(alpha1[celli], 1e-4);
     }
 }
 
diff --git a/applications/solvers/multiphase/compressibleInterFoam/overCompressibleInterDyMFoam/alphaSuSp.H b/applications/solvers/multiphase/compressibleInterFoam/overCompressibleInterDyMFoam/alphaSuSp.H
index 65c5750ff94..457f40891af 100644
--- a/applications/solvers/multiphase/compressibleInterFoam/overCompressibleInterDyMFoam/alphaSuSp.H
+++ b/applications/solvers/multiphase/compressibleInterFoam/overCompressibleInterDyMFoam/alphaSuSp.H
@@ -26,12 +26,12 @@ forAll(dgdt, celli)
 {
     if (dgdt[celli] > 0.0)
     {
-        Sp[celli] -= dgdt[celli]/max(1.0 - alpha1[celli], 1e-4);
-        Su[celli] += dgdt[celli]/max(1.0 - alpha1[celli], 1e-4);
+        Sp[celli] -= dgdt[celli]/Foam::max(1.0 - alpha1[celli], 1e-4);
+        Su[celli] += dgdt[celli]/Foam::max(1.0 - alpha1[celli], 1e-4);
     }
     else if (dgdt[celli] < 0.0)
     {
-        Sp[celli] += dgdt[celli]/max(alpha1[celli], 1e-4);
+        Sp[celli] += dgdt[celli]/Foam::max(alpha1[celli], 1e-4);
     }
 }
 
diff --git a/applications/utilities/finiteArea/makeFaMesh/checkPatchTopology.H b/applications/utilities/finiteArea/makeFaMesh/checkPatchTopology.H
index a38666a544f..6202b67cd86 100644
--- a/applications/utilities/finiteArea/makeFaMesh/checkPatchTopology.H
+++ b/applications/utilities/finiteArea/makeFaMesh/checkPatchTopology.H
@@ -108,13 +108,13 @@ Input
             if (numNbrs == 1)
             {
                 //if (pointSetPtr) pointSetPtr->insert(mesh.edges()[meshEdgei]);
-                labelTyp = max(labelTyp, TopoType::OPEN);
+                labelTyp = Foam::max(labelTyp, TopoType::OPEN);
             }
             else if (numNbrs == 0 || numNbrs > 2)
             {
                 if (pointSetPtr) pointSetPtr->insert(mesh.edges()[meshEdgei]);
                 if (badEdgesPtr) badEdgesPtr->insert(edgei);
-                labelTyp = max(labelTyp, TopoType::ILLEGAL);
+                labelTyp = Foam::max(labelTyp, TopoType::ILLEGAL);
             }
         }
         reduce(labelTyp, maxOp<label>());
diff --git a/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C b/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C
index 645a5073d18..f2e6a8be6d7 100644
--- a/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C
+++ b/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C
@@ -368,7 +368,8 @@ void subsetTopoSets
 
         Info<< "Subsetting " << set.type() << ' ' << set.name() << endl;
 
-        labelHashSet subset(2*min(set.size(), map.size()));
+        labelHashSet subset;
+        subset.reserve(Foam::min(set.size(), map.size()));
 
         // Map the data
         forAll(map, i)
diff --git a/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C b/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C
index c8294f55be9..c6388a0e5b9 100644
--- a/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C
+++ b/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
                     if (blockPFacePointi != blockPFacePointi2)
                     {
                         sqrMergeTol =
-                            min
+                            Foam::min
                             (
                                 sqrMergeTol,
                                 magSqr
@@ -338,16 +338,16 @@ int main(int argc, char *argv[])
                         blockNFacePoints[blockNFacePointi]
                       + blockOffsets[blockNlabel];
 
-                    label minPN = min(PpointLabel, NpointLabel);
+                    label minPN = Foam::min(PpointLabel, NpointLabel);
 
                     if (pointMergeList[PpointLabel] != -1)
                     {
-                        minPN = min(minPN, pointMergeList[PpointLabel]);
+                        minPN = Foam::min(minPN, pointMergeList[PpointLabel]);
                     }
 
                     if (pointMergeList[NpointLabel] != -1)
                     {
-                        minPN = min(minPN, pointMergeList[NpointLabel]);
+                        minPN = Foam::min(minPN, pointMergeList[NpointLabel]);
                     }
 
                     pointMergeList[PpointLabel]
@@ -411,7 +411,7 @@ int main(int argc, char *argv[])
 
                         pointMergeList[PpointLabel]
                       = pointMergeList[NpointLabel]
-                      = min
+                      = Foam::min
                         (
                             pointMergeList[PpointLabel],
                             pointMergeList[NpointLabel]
diff --git a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L
index c29bff53e58..23739c02ca2 100644
--- a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L
+++ b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L
@@ -350,7 +350,7 @@ mtype                 {space}"MTYPE:"{space}
         // Find out how many labels are expected. If less or equal to
         // seven, read them all and finish with it. If there is more,
         // set read of the next line
-        label labelsToRead = min(8, nVertices);
+        label labelsToRead = Foam::min(8, nVertices);
         label labelI = 0;
         for (; labelI < labelsToRead; labelI++)
         {
@@ -387,7 +387,7 @@ mtype                 {space}"MTYPE:"{space}
 
         labelList& curLabels = cellLabels[curNumberOfCells];
 
-        label labelsToRead = min
+        label labelsToRead = Foam::min
         (
             (nCellContinuationLines + 1)*7,
             curLabels.size()
diff --git a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C
index cfc923bcf30..36f89a1814e 100644
--- a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C
+++ b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C
@@ -269,7 +269,7 @@ void readCells
     label maxUnvPoint = 0;
     forAll(unvPointID, pointi)
     {
-        maxUnvPoint = max(maxUnvPoint, unvPointID[pointi]);
+        maxUnvPoint = Foam::max(maxUnvPoint, unvPointID[pointi]);
     }
     labelList unvToFoam(invert(maxUnvPoint+1, unvPointID));
 
@@ -784,7 +784,7 @@ int main(int argc, char *argv[])
     label maxUnvPoint = 0;
     forAll(unvPointID, pointi)
     {
-        maxUnvPoint = max(maxUnvPoint, unvPointID[pointi]);
+        maxUnvPoint = Foam::max(maxUnvPoint, unvPointID[pointi]);
     }
     labelList unvToFoam(invert(maxUnvPoint+1, unvPointID));
 
diff --git a/applications/utilities/mesh/conversion/kivaToFoam/checkPatch.H b/applications/utilities/mesh/conversion/kivaToFoam/checkPatch.H
index 6e9eaae3819..708b9664f53 100644
--- a/applications/utilities/mesh/conversion/kivaToFoam/checkPatch.H
+++ b/applications/utilities/mesh/conversion/kivaToFoam/checkPatch.H
@@ -8,10 +8,10 @@
         {
             if (kivaVersion == kiva3v)
             {
-                regionIndex = max
+                regionIndex = Foam::max
                 (
-                    max(idface[quadFace[0]], idface[quadFace[1]]),
-                    max(idface[quadFace[2]], idface[quadFace[3]])
+                    Foam::max(idface[quadFace[0]], idface[quadFace[1]]),
+                    Foam::max(idface[quadFace[2]], idface[quadFace[3]])
                 );
 
                 if (regionIndex > 0)
diff --git a/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H b/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H
index fa8c5548dd0..6c7c23137ab 100644
--- a/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H
+++ b/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H
@@ -148,9 +148,7 @@ for (label i=0; i<nPoints; i++)
                     end = pointMap[end];
                 }
 
-                label minLabel = min(start, end);
-
-                pointMap[start] = pointMap[end] = minLabel;
+                pointMap[start] = pointMap[end] = Foam::min(start, end);
             }
         }
 
@@ -331,7 +329,7 @@ if
     {
         forAll(pf, pfi)
         {
-            minz = min(minz, points[pf[pfi]].z());
+            minz = Foam::min(minz, points[pf[pfi]].z());
         }
     }
 
diff --git a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C
index c9cbabe10b5..7c719aa8536 100644
--- a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C
+++ b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C
@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
         }
 
 
-        maxPatch = max(maxPatch, patchi);
+        maxPatch = Foam::max(maxPatch, patchi);
 
         triFace tri(readLabel(str)-1, readLabel(str)-1, readLabel(str)-1);
 
diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C
index d1fb66a6056..c536d2c840d 100644
--- a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C
+++ b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C
@@ -556,8 +556,8 @@ void calcEdgeMinMaxZone
             forAll(eFaces, i)
             {
                 label zoneI = mappedZoneID[eFaces[i]];
-                minZoneID[edgeI] = min(minZoneID[edgeI], zoneI);
-                maxZoneID[edgeI] = max(maxZoneID[edgeI], zoneI);
+                minZoneID[edgeI] = Foam::min(minZoneID[edgeI], zoneI);
+                maxZoneID[edgeI] = Foam::max(maxZoneID[edgeI], zoneI);
             }
         }
     }
@@ -813,8 +813,8 @@ void addCoupledPatches
             forAll(eFaces, i)
             {
                 label proci = procID[eFaces[i]];
-                minProcID[edgeI] = min(minProcID[edgeI], proci);
-                maxProcID[edgeI] = max(maxProcID[edgeI], proci);
+                minProcID[edgeI] = Foam::min(minProcID[edgeI], proci);
+                maxProcID[edgeI] = Foam::max(maxProcID[edgeI], proci);
             }
         }
     }
@@ -1291,7 +1291,7 @@ void extrudeGeometricProperties
             label celli = regionMesh.faceOwner()[facei];
             if (regionMesh.isInternalFace(facei))
             {
-                celli = max(celli, regionMesh.faceNeighbour()[facei]);
+                celli = Foam::max(celli, regionMesh.faceNeighbour()[facei]);
             }
 
             // Calculate layer from cell numbering (see createShellMesh)
@@ -2210,8 +2210,8 @@ int main(int argc, char *argv[])
 
             if (addSidePatches && (zone0 != zone1)) // || (cos(angle) > blabla))
             {
-                label minZone = min(zone0,zone1);
-                label maxZone = max(zone0,zone1);
+                label minZone = Foam::min(zone0,zone1);
+                label maxZone = Foam::max(zone0,zone1);
                 label index = minZone*zoneNames.size()+maxZone;
 
                 ePatches.setSize(eFaces.size());
diff --git a/applications/utilities/mesh/manipulation/checkMesh/writeFields.C b/applications/utilities/mesh/manipulation/checkMesh/writeFields.C
index c16334b9e3f..8dd9c08459b 100644
--- a/applications/utilities/mesh/manipulation/checkMesh/writeFields.C
+++ b/applications/utilities/mesh/manipulation/checkMesh/writeFields.C
@@ -21,19 +21,16 @@ void maxFaceToCell
     scalarField& cellFld = cellData.ref();
 
     cellFld = -GREAT;
-    forAll(cells, cellI)
+    forAll(cells, celli)
     {
-        const cell& cFaces = cells[cellI];
-        forAll(cFaces, i)
+        for (const label facei : cells[celli])
         {
-            cellFld[cellI] = max(cellFld[cellI], faceData[cFaces[i]]);
+            cellFld[celli] = Foam::max(cellFld[celli], faceData[facei]);
         }
     }
 
-    forAll(cellData.boundaryField(), patchI)
+    for (fvPatchScalarField& fvp : cellData.boundaryFieldRef())
     {
-        fvPatchScalarField& fvp = cellData.boundaryFieldRef()[patchI];
-
         fvp = fvp.patch().patchSlice(faceData);
     }
     cellData.correctBoundaryConditions();
@@ -51,19 +48,16 @@ void minFaceToCell
     scalarField& cellFld = cellData.ref();
 
     cellFld = GREAT;
-    forAll(cells, cellI)
+    forAll(cells, celli)
     {
-        const cell& cFaces = cells[cellI];
-        forAll(cFaces, i)
+        for (const label facei : cells[celli])
         {
-            cellFld[cellI] = min(cellFld[cellI], faceData[cFaces[i]]);
+            cellFld[celli] = Foam::min(cellFld[celli], faceData[facei]);
         }
     }
 
-    forAll(cellData.boundaryField(), patchI)
+    for (fvPatchScalarField& fvp : cellData.boundaryFieldRef())
     {
-        fvPatchScalarField& fvp = cellData.boundaryFieldRef()[patchI];
-
         fvp = fvp.patch().patchSlice(faceData);
     }
     cellData.correctBoundaryConditions();
@@ -77,7 +71,7 @@ void minFaceToCell
     const bool correctBoundaryConditions
 )
 {
-    scalarField& cellFld = cellData.ref();
+    scalarField& cellFld = cellData.primitiveFieldRef();
 
     cellFld = GREAT;
 
@@ -87,19 +81,19 @@ void minFaceToCell
     // Internal faces
     forAll(own, facei)
     {
-        cellFld[own[facei]] = min(cellFld[own[facei]], faceData[facei]);
-        cellFld[nei[facei]] = min(cellFld[nei[facei]], faceData[facei]);
+        cellFld[own[facei]] = Foam::min(cellFld[own[facei]], faceData[facei]);
+        cellFld[nei[facei]] = Foam::min(cellFld[nei[facei]], faceData[facei]);
     }
 
     // Patch faces
-    forAll(faceData.boundaryField(), patchi)
+    for (const fvsPatchScalarField& fvp : faceData.boundaryField())
     {
-        const fvsPatchScalarField& fvp = faceData.boundaryField()[patchi];
-        const labelUList& fc = fvp.patch().faceCells();
+        label pfacei = 0;
 
-        forAll(fc, i)
+        for (const label celli : fvp.patch().faceCells())
         {
-            cellFld[fc[i]] = min(cellFld[fc[i]], fvp[i]);
+            cellFld[celli] = Foam::max(cellFld[celli], fvp[pfacei]);
+            ++pfacei;
         }
     }
 
@@ -163,7 +157,7 @@ void Foam::writeFields
     if (selectedFields.found("nonOrthoAngle"))
     {
         //- Face based orthogonality
-        const scalarField faceOrthogonality
+        scalarField faceOrthogonality
         (
             polyMeshTools::faceOrthogonality
             (
@@ -172,14 +166,12 @@ void Foam::writeFields
                 mesh.cellCentres()
             )
         );
+        faceOrthogonality.clamp_range(-1, 1);
 
         //- Face based angle
         const scalarField nonOrthoAngle
         (
-            radToDeg
-            (
-                Foam::acos(min(scalar(1), max(scalar(-1), faceOrthogonality)))
-            )
+            radToDeg(Foam::acos(faceOrthogonality))
         );
 
         //- Cell field - max of either face
@@ -534,7 +526,7 @@ void Foam::writeFields
                         ownCc,
                         fc
                     ).quality();
-                    ownVol = min(ownVol, tetQual);
+                    ownVol = Foam::min(ownVol, tetQual);
                 }
             }
             if (mesh.isInternalFace(facei))
@@ -550,7 +542,7 @@ void Foam::writeFields
                         fc,
                         neiCc
                     ).quality();
-                    neiVol = min(neiVol, tetQual);
+                    neiVol = Foam::min(neiVol, tetQual);
                 }
             }
         }
@@ -602,19 +594,23 @@ void Foam::writeFields
         // Internal faces
         forAll(own, facei)
         {
-            cellFld[own[facei]] = min(cellFld[own[facei]], ownPyrVol[facei]);
-            cellFld[nei[facei]] = min(cellFld[nei[facei]], neiPyrVol[facei]);
+            cellFld[own[facei]] =
+                Foam::min(cellFld[own[facei]], ownPyrVol[facei]);
+            cellFld[nei[facei]] =
+                Foam::min(cellFld[nei[facei]], neiPyrVol[facei]);
         }
 
         // Patch faces
         for (const auto& fvp : minPyrVolume.boundaryField())
         {
-            const labelUList& fc = fvp.patch().faceCells();
+            label meshFacei = fvp.patch().start();
 
-            forAll(fc, i)
+            for (const label celli : fvp.patch().faceCells())
             {
-                const label meshFacei = fvp.patch().start();
-                cellFld[fc[i]] = min(cellFld[fc[i]], ownPyrVol[meshFacei]);
+                cellFld[celli] =
+                    Foam::min(cellFld[celli], ownPyrVol[meshFacei]);
+
+                ++meshFacei;
             }
         }
 
@@ -625,7 +621,7 @@ void Foam::writeFields
         if (writeFaceFields)
         {
             scalarField minFacePyrVol(neiPyrVol);
-            minFacePyrVol = min
+            minFacePyrVol = Foam::min
             (
                 minFacePyrVol,
                 SubField<scalar>(ownPyrVol, mesh.nInternalFaces())
diff --git a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
index c5763634bd3..b0a30a0a787 100644
--- a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
+++ b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
@@ -465,7 +465,7 @@ labelList getRegionFaceOrder
 
     // Do region interfaces
     {
-        const label nRegions = max(cellToRegion)+1;
+        const label nRegions = Foam::max(cellToRegion)+1;
 
         // Sort in increasing region
         SortableList<label> sortKey(mesh.nInternalFaces(), labelMax);
@@ -478,8 +478,10 @@ labelList getRegionFaceOrder
             if (ownRegion != neiRegion)
             {
                 sortKey[facei] =
-                    min(ownRegion, neiRegion)*nRegions
-                   +max(ownRegion, neiRegion);
+                (
+                    Foam::min(ownRegion, neiRegion)*nRegions
+                  + Foam::max(ownRegion, neiRegion)
+                );
             }
         }
 
diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C
index af462ed6d94..3ca4aedf7b7 100644
--- a/applications/utilities/mesh/manipulation/setSet/setSet.C
+++ b/applications/utilities/mesh/manipulation/setSet/setSet.C
@@ -320,10 +320,10 @@ bool doCommand
     const globalMeshData& parData = mesh.globalData();
 
     label typSize =
-        max
+        Foam::max
         (
             parData.nTotalCells(),
-            max
+            Foam::max
             (
                 parData.nTotalFaces(),
                 parData.nTotalPoints()
@@ -375,7 +375,7 @@ bool doCommand
 
                 topoSet& currentSet = currentSetPtr();
                 // Presize it according to current mesh data.
-                currentSet.reserve(max(currentSet.size(), typSize));
+                currentSet.reserve(Foam::max(currentSet.size(), typSize));
             }
         }
 
diff --git a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C
index 1b195acc032..22c781a7ad2 100644
--- a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C
+++ b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C
@@ -295,7 +295,8 @@ void subsetTopoSets
 
         Info<< "Subsetting " << set.type() << " " << set.name() << endl;
 
-        labelHashSet subset(2*min(set.size(), map.size()));
+        labelHashSet subset;
+        subset.reserve(Foam::min(set.size(), map.size()));
 
         // Map the data
         forAll(map, i)
diff --git a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C
index d4611d3f25b..35add854354 100644
--- a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C
+++ b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C
@@ -1131,7 +1131,7 @@ int main(int argc, char *argv[])
                         for
                         (
                             label addedI=next;
-                            addedI<min(proci+step, nProcs);
+                            addedI < Foam::min(proci+step, nProcs);
                             addedI++
                         )
                         {
diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C
index 4ac8fd1acb6..f1461bac18d 100644
--- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C
+++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C
@@ -403,11 +403,11 @@ void printMeshData(const polyMesh& mesh)
                 << nBndFaces-nProcFaces << endl;
         }
 
-        maxProcCells = max(maxProcCells, nLocalCells);
+        maxProcCells = Foam::max(maxProcCells, nLocalCells);
         totProcFaces += nProcFaces;
         totProcPatches += nei.size();
-        maxProcFaces = max(maxProcFaces, nProcFaces);
-        maxProcPatches = max(maxProcPatches, nei.size());
+        maxProcFaces = Foam::max(maxProcFaces, nProcFaces);
+        maxProcPatches = Foam::max(maxProcPatches, nei.size());
     }
 
     // Summary stats
diff --git a/applications/utilities/postProcessing/lagrangian/particleTracks/particleTracks.C b/applications/utilities/postProcessing/lagrangian/particleTracks/particleTracks.C
index 2202574ad88..1e6af8563f9 100644
--- a/applications/utilities/postProcessing/lagrangian/particleTracks/particleTracks.C
+++ b/applications/utilities/postProcessing/lagrangian/particleTracks/particleTracks.C
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
     args.readIfPresent("format", setFormat);
 
     args.readIfPresent("stride", sampleFrequency);
-    sampleFrequency = max(1, sampleFrequency);  // sanity
+    sampleFrequency = Foam::max(1, sampleFrequency);  // sanity
 
     // Setup the writer
     auto writerPtr =
@@ -179,7 +179,7 @@ int main(int argc, char *argv[])
                     maxIds.resize(origProc+1, -1);
                 }
 
-                maxIds[origProc] = max(maxIds[origProc], origId);
+                maxIds[origProc] = Foam::max(maxIds[origProc], origId);
             }
         }
 
diff --git a/applications/utilities/preProcessing/PDR/pdrFields/PDRarraysCalc.C b/applications/utilities/preProcessing/PDR/pdrFields/PDRarraysCalc.C
index 382086b80b4..f25ede0b3e4 100644
--- a/applications/utilities/preProcessing/PDR/pdrFields/PDRarraysCalc.C
+++ b/applications/utilities/preProcessing/PDR/pdrFields/PDRarraysCalc.C
@@ -1056,7 +1056,7 @@ void calc_drag_etc
     const scalar expon =
     (
         br > 0.0
-      ? min(max((surr_br / br - 0.25) * 4.0 / 3.0, scalar(0)), scalar(1))
+      ? Foam::clamp((surr_br / br - 0.25) * 4.0 / 3.0, Foam::zero_one{})
       : 0.0
     );
 
@@ -1114,16 +1114,16 @@ void Foam::PDRarrays::blockageSummary() const
                 totVolBlock += v_block(ijk) * pdrBlock.V(ijk);
                 totArea += surf(ijk);
 
-                totCount += max(0, obs_count(ijk));
+                totCount += Foam::max(0, obs_count(ijk));
 
-                totDrag.x() += max(0, drag_s(ijk).xx());
-                totDrag.y() += max(0, drag_s(ijk).yy());
-                totDrag.z() += max(0, drag_s(ijk).zz());
+                totDrag.x() += Foam::max(0, drag_s(ijk).xx());
+                totDrag.y() += Foam::max(0, drag_s(ijk).yy());
+                totDrag.z() += Foam::max(0, drag_s(ijk).zz());
 
                 for (direction cmpt=0; cmpt < vector::nComponents; ++cmpt)
                 {
-                    totBlock[cmpt] += max(0, area_block_s(ijk)[cmpt]);
-                    totBlock[cmpt] += max(0, area_block_r(ijk)[cmpt]);
+                    totBlock[cmpt] += Foam::max(0, area_block_s(ijk)[cmpt]);
+                    totBlock[cmpt] += Foam::max(0, area_block_r(ijk)[cmpt]);
                 }
             }
         }
diff --git a/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C b/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C
index 1c27f536cfe..b79311b49ae 100644
--- a/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C
+++ b/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C
@@ -302,7 +302,7 @@ void Foam::PDRutils::circle_overlap
                     scalar da = ac - 0.5 * (a1 + a2);
                     scalar db = bc - 0.5 * (b1 + b2);
                     scalar dc = std::hypot(da, db);
-                    scalar rat1 = min(max((dc / sqrt(area) - 0.3) * 1.4, 0), 1);
+                    scalar rat1 = Foam::min(Foam::max((dc / sqrt(area) - 0.3) * 1.4, 0), 1);
                     scalar drg0 = c_drag(ia,ib).xx();
                     scalar drg1 = c_drag(ia,ib).yy();
                     scalar drg = std::hypot(drg0, drg1);
@@ -449,8 +449,8 @@ scalar block_overlap
             {
                 PDRobstacle over;
 
-                over.pt = max(blk1.pt, blk2.pt);
-                over.span = min(max1, max2) - over.pt;
+                over.pt = Foam::max(blk1.pt, blk2.pt);
+                over.span = Foam::min(max1, max2) - over.pt;
 
                 assert(cmptProduct(over.span) > 0.0);
 
@@ -603,11 +603,11 @@ scalar block_cylinder_overlap
 
                     over.x() = a_centre - 0.5 * a_lblk;
                     over.y() = b_centre - 0.5 * b_lblk;
-                    over.z() = max(blk1.z(), cyl2.z());
+                    over.z() = Foam::max(blk1.z(), cyl2.z());
 
                     over.span.x() = a_lblk;
                     over.span.y() = b_lblk;
-                    over.span.z() = min(max1.z(), cyl2.z() + cyl2.len()) - over.z();
+                    over.span.z() = Foam::min(max1.z(), cyl2.z() + cyl2.len()) - over.z();
                     assert(over.x() > -200.0);
                     assert(over.x() < 2000.0);
                 }
@@ -668,11 +668,11 @@ scalar block_cylinder_overlap
 
                     over.z() = a_centre - a_lblk * 0.5;
                     over.x() = b_centre - b_lblk * 0.5;
-                    over.y() = max(blk1.y(), cyl2.y());
+                    over.y() = Foam::max(blk1.y(), cyl2.y());
 
                     over.span.z() = a_lblk;
                     over.span.x() = b_lblk;
-                    over.span.y() = min(max1.y(), cyl2.y() + cyl2.len()) - over.y();
+                    over.span.y() = Foam::min(max1.y(), cyl2.y() + cyl2.len()) - over.y();
                 }
                 break;
 
@@ -734,11 +734,11 @@ scalar block_cylinder_overlap
 
                     over.y() = a_centre - a_lblk * 0.5;
                     over.z() = b_centre - b_lblk * 0.5;
-                    over.x() = max(blk1.x(), cyl2.x());
+                    over.x() = Foam::max(blk1.x(), cyl2.x());
 
                     over.span.y() = a_lblk;
                     over.span.z() = b_lblk;
-                    over.span.x() = min(max1.x(), cyl2.x() + cyl2.len()) - over.x();
+                    over.span.x() = Foam::min(max1.x(), cyl2.x() + cyl2.len()) - over.x();
                 }
                 break;
             }
diff --git a/applications/utilities/preProcessing/engineSwirl/engineSwirl.C b/applications/utilities/preProcessing/engineSwirl/engineSwirl.C
index cb50df54859..9c1d70e96a4 100644
--- a/applications/utilities/preProcessing/engineSwirl/engineSwirl.C
+++ b/applications/utilities/preProcessing/engineSwirl/engineSwirl.C
@@ -71,9 +71,9 @@ int main(int argc, char *argv[])
         {
             scalar b = j1(swirlProfile*r/cylinderRadius).value();
             scalar vEff = omega*b;
-            r = max(r, SMALL);
+            r = Foam::max(r, SMALL);
             U[celli] = ((vEff/r)*(c & yT))*xT + (-(vEff/r)*(c & xT))*yT;
-            Umax = max(Umax, mag(U[celli]));
+            Umax = Foam::max(Umax, mag(U[celli]));
         }
     }
 
diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C
index 7c6be507e17..15ec124430b 100644
--- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C
+++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C
@@ -887,7 +887,7 @@ int main(int argc, char *argv[])
             writeParts
             (
                 surf,
-                min(outputThreshold, numZones),
+                Foam::min(outputThreshold, numZones),
                 faceZone,
                 surfFilePath,
                 surfFileStem
@@ -953,7 +953,7 @@ int main(int argc, char *argv[])
             writeParts
             (
                 surf,
-                min(outputThreshold, numNormalZones),
+                Foam::min(outputThreshold, numNormalZones),
                 normalZone,
                 surfFilePath,
                 surfFileStem + "_normal"
diff --git a/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C b/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C
index 603f07b43fd..ef0b74fdcf7 100644
--- a/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C
+++ b/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C
@@ -280,7 +280,7 @@ int main(int argc, char *argv[])
     const IOdictionary dict(dictIO);
 
     const scalar dist(args.get<scalar>(1));
-    const scalar matchTolerance(max(1e-6*dist, SMALL));
+    const scalar matchTolerance(Foam::max(1e-6*dist, SMALL));
     const label maxIters = 100;
 
     Info<< "Hooking distance = " << dist << endl;
diff --git a/applications/utilities/surface/surfaceInflate/surfaceInflate.C b/applications/utilities/surface/surfaceInflate/surfaceInflate.C
index 3292780ef73..4a16e37c8b5 100644
--- a/applications/utilities/surface/surfaceInflate/surfaceInflate.C
+++ b/applications/utilities/surface/surfaceInflate/surfaceInflate.C
@@ -276,7 +276,7 @@ label detectIntersectionPoints
 
     // 1. Extrusion offset vectors intersecting new surface location
     {
-        scalar tol = max(tolerance, 10*s.tolerance());
+        scalar tol = Foam::max(tolerance, 10*s.tolerance());
 
         // Collect all the edge vectors. Slightly shorten the edges to prevent
         // finding lots of intersections. The fast triangle intersection routine
@@ -296,7 +296,7 @@ label detectIntersectionPoints
             &&  !localFaces[hits[pointI].index()].found(pointI)
             )
             {
-                scale[pointI] = max(0.0, scale[pointI]-0.2);
+                scale[pointI] = Foam::max(0.0, scale[pointI]-0.2);
 
                 isPointOnHitEdge.set(pointI);
                 nHits++;
@@ -330,7 +330,7 @@ label detectIntersectionPoints
                         << pt
                         << endl;
 
-                    scale[e[0]] = max(0.0, scale[e[0]]-0.2);
+                    scale[e[0]] = Foam::max(0.0, scale[e[0]]-0.2);
                     nHits++;
                 }
                 if (isPointOnHitEdge.set(e[1]))
@@ -342,7 +342,7 @@ label detectIntersectionPoints
                         << pt
                         << endl;
 
-                    scale[e[1]] = max(0.0, scale[e[1]]-0.2);
+                    scale[e[1]] = Foam::max(0.0, scale[e[1]]-0.2);
                     nHits++;
                 }
             }
@@ -418,7 +418,7 @@ void minSmooth
         const edge& e = edges[edgeI];
         scalar w = mag(points[mp[e[0]]]-points[mp[e[1]]]);
 
-        edgeWeights[edgeI] = 1.0/(max(w, SMALL));
+        edgeWeights[edgeI] = 1.0/(Foam::max(w, SMALL));
     }
 
     tmp<scalarField> tavgFld = avg(s, fld, edgeWeights);
@@ -429,7 +429,7 @@ void minSmooth
     {
         if (isAffectedPoint.test(pointI))
         {
-            newFld[pointI] = min
+            newFld[pointI] = Foam::min
             (
                 fld[pointI],
                 0.5*fld[pointI] + 0.5*avgFld[pointI]
diff --git a/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C b/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C
index 6f276914579..fcd551ab61e 100644
--- a/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C
+++ b/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C
@@ -109,7 +109,7 @@ void writeOBJ
     const auto& constraints = ppp.constraints();
     forAll(constraints, i)
     {
-        maxConstraint = max(maxConstraint, constraints[i].first());
+        maxConstraint = Foam::max(maxConstraint, constraints[i].first());
     }
     reduce(maxConstraint, maxOp<label>());
 
diff --git a/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C b/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C
index 220a0da6ddb..7345394f9c2 100644
--- a/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C
+++ b/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C
@@ -180,8 +180,8 @@ int main(int argc, char *argv[])
 
         scalar o2 = (1.0/equiv)*stoicO2;
         scalar n2 = (0.79/0.21)*o2;
-        scalar fres = max(1.0 - 1.0/equiv, 0.0);
-        scalar ores = max(1.0/equiv - 1.0, 0.0);
+        scalar fres = Foam::max(1.0 - 1.0/equiv, 0.0);
+        scalar ores = Foam::max(1.0/equiv - 1.0, 0.0);
         scalar fburnt = 1.0 - fres;
 
         thermo reactants
diff --git a/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C b/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C
index a6f2e4fb63f..89798b21521 100644
--- a/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C
+++ b/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C
@@ -196,12 +196,12 @@ int main(int argc, char *argv[])
         // Number of moles of species for one mole of fuel
         scalar o2 = (1.0/equiv)*stoicO2;
         scalar n2 = (0.79/0.21)*o2;
-        scalar fres = max(1.0 - 1.0/equiv, 0.0);
+        scalar fres = Foam::max(1.0 - 1.0/equiv, 0.0);
         scalar fburnt = 1.0 - fres;
 
         // Initial guess for number of moles of product species
         // ignoring product dissociation
-        scalar oresInit = max(1.0/equiv - 1.0, 0.0)*stoicO2;
+        scalar oresInit = Foam::max(1.0/equiv - 1.0, 0.0)*stoicO2;
         scalar co2Init = fburnt*stoicCO2;
         scalar h2oInit = fburnt*stoicH2O;
 
@@ -231,18 +231,18 @@ int main(int argc, char *argv[])
             if (j > 0)
             {
                 co = co2*
-                    min
+                    Foam::min
                     (
                         CO2BreakUp.Kn(P, equilibriumFlameTemperature, N)
-                       /::sqrt(max(ores, 0.001)),
+                       /::sqrt(Foam::max(ores, 0.001)),
                         1.0
                     );
 
                 h2 = h2o*
-                    min
+                    Foam::min
                     (
                         H2OBreakUp.Kn(P, equilibriumFlameTemperature, N)
-                       /::sqrt(max(ores, 0.001)),
+                       /::sqrt(Foam::max(ores, 0.001)),
                         1.0
                     );
 
diff --git a/src/parallel/decompose/faDecompose/faMeshDecomposition.C b/src/parallel/decompose/faDecompose/faMeshDecomposition.C
index 63806592796..ff97ec03fda 100644
--- a/src/parallel/decompose/faDecompose/faMeshDecomposition.C
+++ b/src/parallel/decompose/faDecompose/faMeshDecomposition.C
@@ -85,7 +85,8 @@ void Foam::faMeshDecomposition::distributeFaces()
         ioAddr.rename("faceProcAddressing");
         labelIOList fvFaceProcAddressing(ioAddr);
 
-        labelHashSet faceProcAddressingHash(2*fvFaceProcAddressing.size());
+        labelHashSet faceProcAddressingHash;
+        faceProcAddressingHash.reserve(fvFaceProcAddressing.size());
 
         // If faMesh's fvPatch is a part of the global face zones, faces of that
         // patch will be present on all processors. Because of that, looping
@@ -941,10 +942,8 @@ void Foam::faMeshDecomposition::decomposeMesh()
 
         // Globally shared points are the ones used by more than 2 processors
         // Size the list approximately and gather the points
-        labelHashSet gSharedPoints
-        (
-            min(100, nPoints()/1000)
-        );
+        labelHashSet gSharedPoints;
+        gSharedPoints.reserve(Foam::min(128, nPoints()/1000));
 
         // Loop through all the processors and mark up points used by
         // processor boundaries.  When a point is used twice, it is a
diff --git a/src/regionModels/pyrolysisModels/pyrolysisModel/pyrolysisModelCollection.C b/src/regionModels/pyrolysisModels/pyrolysisModel/pyrolysisModelCollection.C
index 7559047023f..dd9ca6401bd 100644
--- a/src/regionModels/pyrolysisModels/pyrolysisModel/pyrolysisModelCollection.C
+++ b/src/regionModels/pyrolysisModels/pyrolysisModel/pyrolysisModelCollection.C
@@ -163,7 +163,8 @@ scalar pyrolysisModelCollection::maxDiff() const
     scalar maxDiff = 0.0;
     forAll(*this, i)
     {
-        maxDiff = max(maxDiff, this->operator[](i).maxDiff());
+        maxDiff =
+            Foam::max(maxDiff, this->operator[](i).maxDiff());
     }
 
     return maxDiff;
@@ -175,7 +176,8 @@ scalar pyrolysisModelCollection::solidRegionDiffNo() const
     scalar totalDiNum = GREAT;
     forAll(*this, i)
     {
-        totalDiNum = min(totalDiNum, this->operator[](i).solidRegionDiffNo());
+        totalDiNum =
+            Foam::min(totalDiNum, this->operator[](i).solidRegionDiffNo());
     }
 
     return totalDiNum;
-- 
GitLab