diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C index d195d30ca8..7c238e7936 100644 --- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C +++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C @@ -576,8 +576,10 @@ int main(int argc, char *argv[]) } Info<< endl; - label minIndex = findMin(triQ); - label maxIndex = findMax(triQ); + labelPair minMaxIds = findMinMax(triQ); + + const label minIndex = minMaxIds.first(); + const label maxIndex = minMaxIds.second(); Info<< " min " << triQ[minIndex] << " for triangle " << minIndex << nl @@ -656,8 +658,10 @@ int main(int argc, char *argv[]) edgeMag[edgei] = edges[edgei].mag(localPoints); } - label minEdgei = findMin(edgeMag); - label maxEdgei = findMax(edgeMag); + labelPair minMaxIds = findMinMax(edgeMag); + + const label minEdgei = minMaxIds.first(); + const label maxEdgei = minMaxIds.second(); const edge& minE = edges[minEdgei]; const edge& maxE = edges[maxEdgei]; diff --git a/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C b/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C index e30419e537..f11343b570 100644 --- a/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C +++ b/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2017 OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -122,45 +122,36 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFieldType { const label proci = Pstream::myProcNo(); - // Find min internal field value info - List minVs(Pstream::nProcs()); - labelList minCells(Pstream::nProcs()); - List minCs(Pstream::nProcs()); + // Find min/max internal field value info - label minProci = findMin(field); - if (minProci != -1) + List minVs(Pstream::nProcs(), pTraits::max); + labelList minCells(Pstream::nProcs(), Zero); + List minCs(Pstream::nProcs(), Zero); + + List maxVs(Pstream::nProcs(), pTraits::min); + labelList maxCells(Pstream::nProcs(), Zero); + List maxCs(Pstream::nProcs(), Zero); + + labelPair minMaxIds = findMinMax(field); + + label minId = minMaxIds.first(); + if (minId != -1) { - minVs[proci] = field[minProci]; - minCells[proci] = minProci; - minCs[proci] = mesh_.C()[minProci]; - } - else - { - minVs[proci] = pTraits::max; - minCells[proci] = -1; - minCs[proci] = vector::max; + minVs[proci] = field[minId]; + minCells[proci] = minId; + minCs[proci] = mesh_.C()[minId]; } - // Find max internal field value info - List maxVs(Pstream::nProcs()); - labelList maxCells(Pstream::nProcs()); - List maxCs(Pstream::nProcs()); - - label maxProci = findMax(field); - if (maxProci != -1) + label maxId = minMaxIds.second(); + if (maxId != -1) { - maxVs[proci] = field[maxProci]; - maxCells[proci] = maxProci; - maxCs[proci] = mesh_.C()[maxProci]; - } - else - { - maxVs[proci] = pTraits::min; - maxCells[proci] = -1; - maxCs[proci] = vector::max; + maxVs[proci] = field[maxId]; + maxCells[proci] = maxId; + maxCs[proci] = mesh_.C()[maxId]; } - // Find min and max boundary field info + + // Find min/max boundary field info const auto& fieldBoundary = field.boundaryField(); const auto& CfBoundary = mesh_.C().boundaryField(); @@ -174,20 +165,22 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFieldType const labelList& faceCells = fieldBoundary[patchi].patch().faceCells(); - label minPi = findMin(fp); - if (fp[minPi] < minVs[proci]) + minMaxIds = findMinMax(fp); + + minId = minMaxIds.first(); + if (minVs[proci] > fp[minId]) { - minVs[proci] = fp[minPi]; - minCells[proci] = faceCells[minPi]; - minCs[proci] = Cfp[minPi]; + minVs[proci] = fp[minId]; + minCells[proci] = faceCells[minId]; + minCs[proci] = Cfp[minId]; } - label maxPi = findMax(fp); - if (fp[maxPi] > maxVs[proci]) + maxId = minMaxIds.second(); + if (maxVs[proci] < fp[maxId]) { - maxVs[proci] = fp[maxPi]; - maxCells[proci] = faceCells[maxPi]; - maxCs[proci] = Cfp[maxPi]; + maxVs[proci] = fp[maxId]; + maxCells[proci] = faceCells[maxId]; + maxCs[proci] = Cfp[maxId]; } } } @@ -207,15 +200,15 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFieldType Pstream::gatherList(maxCs); Pstream::scatterList(maxCs); - label mini = findMin(minVs); - const Type& minValue = minVs[mini]; - const label minCell = minCells[mini]; - const vector& minC = minCs[mini]; + minId = findMin(minVs); + const Type& minValue = minVs[minId]; + const label minCell = minCells[minId]; + const vector& minC = minCs[minId]; - label maxi = findMax(maxVs); - const Type& maxValue = maxVs[maxi]; - const label maxCell = maxCells[maxi]; - const vector& maxC = maxCs[maxi]; + maxId = findMax(maxVs); + const Type& maxValue = maxVs[maxId]; + const label maxCell = maxCells[maxId]; + const vector& maxC = maxCs[maxId]; output ( @@ -225,8 +218,8 @@ void Foam::functionObjects::fieldMinMax::calcMinMaxFieldType maxCell, minC, maxC, - mini, - maxi, + minId, + maxId, minValue, maxValue ); diff --git a/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C b/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C index 244a6163b0..07e8728ebb 100644 --- a/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C +++ b/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C @@ -211,7 +211,7 @@ void Foam::searchableCone::findNearestAndNormal dist[2] = magSqr(disk2Point-sample); dist[3] = magSqr(iCnearCone-sample); - label minI = findMin(dist); + const label minI = findMin(dist); // Snap the point to the corresponding surface