From 01727c84f13e567e35d813245cc7a50892ff1aa4 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 2 Apr 2025 12:01:28 +0200 Subject: [PATCH] ENH: use gMinMax() instead of separate gMin(), gMax() - for reciprocal values, gMinMax() first and then calculate the reciprocal, which avoids creating temporaries STYLE: prefer MinMax to separate min/max accounting COMP: namespace qualify min/max for deltaT, CourantNo, etc (#3348) --- .../solvers/combustion/PDRFoam/setDeltaT.H | 6 +- .../solvers/combustion/chemFoam/setDeltaT.H | 3 +- .../fireFoam/setMultiRegionDeltaT.H | 13 +- .../combustion/reactingFoam/setRDeltaT.H | 24 ++-- .../compressible/rhoCentralFoam/setRDeltaT.H | 10 +- .../compressible/rhoPimpleFoam/setRDeltaT.H | 26 ++-- .../fluid/compressibleMultiRegionCourantNo.H | 2 +- ...woPhaseRadCoupledMixedFvPatchScalarField.C | 35 +++-- .../fluid/compressibleMultiRegionCourantNo.H | 6 +- .../fluid/compressibleMultiRegionCourantNo.H | 4 +- .../include/setInitialMultiRegionDeltaT.H | 6 +- .../include/setMultiRegionDeltaT.H | 12 +- .../solid/solidRegionDiffusionNo.H | 2 +- .../heatTransfer/solidFoam/solidDiffusionNo.H | 2 +- .../incompressible/pimpleFoam/setRDeltaT.H | 26 ++-- .../lagrangian/coalChemistryFoam/setRDeltaT.H | 18 ++- .../reactingParcelFoam/setMultiRegionDeltaT.H | 11 +- .../reactingParcelFoam/setRDeltaT.H | 18 ++- .../solvers/multiphase/VoF/setDeltaT.H | 7 +- .../solvers/multiphase/VoF/setRDeltaT.H | 25 ++-- .../multiphase/cavitatingFoam/setDeltaT.H | 7 +- .../cavitatingFoam/setInitialDeltaT.H | 8 +- .../setDeltaT.H | 12 +- .../reactingMultiphaseEulerFoam/setRDeltaT.H | 6 +- .../reactingTwoPhaseEulerFoam/CourantNos.H | 2 +- .../reactingTwoPhaseEulerFoam/setRDeltaT.H | 6 +- .../multiphase/twoPhaseEulerFoam/CourantNos.H | 2 +- .../test/fieldMapping/Test-fieldMapping.C | 27 ++-- applications/test/hexRef8/Test-hexRef8.C | 27 ++-- .../advanced/refineHexMesh/refineHexMesh.C | 27 ++-- .../mesh/advanced/selectCells/edgeStats.C | 121 +++++++++-------- .../snappyRefineMesh/snappyRefineMesh.C | 117 ++++++++-------- .../mesh/manipulation/refineMesh/refineMesh.C | 122 +++++++---------- .../createBoxTurb/createBoxTurb.C | 14 +- .../setAlphaField/setAlphaField.C | 13 +- src/combustionModels/EDC/EDC.C | 5 +- .../interfaceTrackingFvMesh.C | 7 +- .../motionSmoother/motionSmootherAlgo.C | 17 ++- .../componentDisplacementMotionSolver.C | 4 +- .../displacementInterpolationMotionSolver.C | 23 ++-- .../displacementLayeredMotionMotionSolver.C | 24 ++-- .../edgeLimitedFaGrad/edgeLimitedFaGrads.C | 18 ++- .../faceLimitedFaGrad/faceLimitedFaGrads.C | 18 ++- .../cfdTools/general/include/setDeltaT.H | 6 +- .../general/include/setInitialDeltaT.H | 4 +- ...lectrostaticDepositionFvPatchScalarField.C | 13 +- .../mappedField/mappedFieldFvPatchField.C | 9 +- .../mappedMixedFieldFvPatchField.C | 9 +- .../mappedFixedValueFvPatchField.C | 9 +- .../mappedMixed/mappedMixedFvPatchField.C | 9 +- .../timeVaryingMappedFixedValueFvPatchField.C | 9 +- .../turbulentDFSEMInletFvPatchVectorField.C | 4 +- .../waveSurfacePressureFvPatchScalarField.C | 8 +- .../ddtSchemes/ddtScheme/ddtScheme.C | 16 +-- .../cellLimitedGrad/cellLimitedGrad.C | 9 +- .../faceLimitedGrad/faceLimitedGrads.C | 18 ++- .../averageNeighbourFvGeometryScheme.C | 8 +- .../highAspectRatio/cellAspectRatio.C | 7 +- .../highAspectRatioFvGeometryScheme.C | 7 +- .../field/AMIWeights/AMIWeights.C | 128 +++++++++--------- src/functionObjects/field/yPlus/yPlus.C | 17 ++- ...meVaryingMappedFixedValuePointPatchField.C | 9 +- .../effectivenessTable/effectivenessTable.C | 16 +-- .../Templates/KinematicCloud/KinematicCloud.C | 11 +- .../clouds/Templates/MPPICCloud/MPPICCloud.C | 11 +- .../snappyHexMeshDriver/snappyLayerDriver.C | 3 +- .../snappyHexMeshDriver/snappySnapDriver.C | 6 +- .../AMIInterpolation/AMIInterpolation.C | 42 +++--- .../cyclicPeriodicAMIPolyPatch.C | 35 +++-- .../PatchFunction1/MappedFile/MappedFile.C | 10 +- .../regularisationPDE/Helmoltz/Helmholtz.C | 2 +- .../ThermalPhaseChangePhaseSystem.C | 33 +++-- ...allBoilingWallFunctionFvPatchScalarField.C | 33 ++--- ...ixedMultiPhaseHeatFluxFvPatchScalarField.C | 7 +- .../reactingOneDim/reactingOneDim.C | 7 +- .../thermoSingleLayer/thermoSingleLayer.C | 7 +- ...pedMassWallTemperatureFvPatchScalarField.C | 9 +- .../thermalBaffle1DFvPatchScalarField.C | 10 +- ...tureCoupledBaffleMixedFvPatchScalarField.C | 9 +- .../enthalpySorptionFvPatchScalarField.C | 8 +- .../speciesSorptionFvPatchScalarField.C | 8 +- .../movingConeTopoFvMesh.C | 4 +- .../isoAdvection/isoAdvection.C | 8 +- .../isoAdvection/isoAdvectionTemplates.C | 22 +-- 84 files changed, 837 insertions(+), 646 deletions(-) diff --git a/applications/solvers/combustion/PDRFoam/setDeltaT.H b/applications/solvers/combustion/PDRFoam/setDeltaT.H index 365126ce90..177fc1fa7f 100644 --- a/applications/solvers/combustion/PDRFoam/setDeltaT.H +++ b/applications/solvers/combustion/PDRFoam/setDeltaT.H @@ -36,11 +36,13 @@ Description if (adjustTimeStep) { scalar maxDeltaTFact = maxCo/(CoNum + StCoNum + SMALL); - scalar deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); + + const scalar deltaTFact = + Foam::min(Foam::min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); runTime.setDeltaT ( - min + Foam::min ( deltaTFact*runTime.deltaTValue(), maxDeltaT diff --git a/applications/solvers/combustion/chemFoam/setDeltaT.H b/applications/solvers/combustion/chemFoam/setDeltaT.H index ef50a97026..93f68ceb6c 100644 --- a/applications/solvers/combustion/chemFoam/setDeltaT.H +++ b/applications/solvers/combustion/chemFoam/setDeltaT.H @@ -1,5 +1,6 @@ if (adjustTimeStep) { - runTime.setDeltaT(min(dtChem, maxDeltaT)); + runTime.setDeltaT(Foam::min(dtChem, maxDeltaT)); + Info<< "deltaT = " << runTime.deltaTValue() << endl; } diff --git a/applications/solvers/combustion/fireFoam/setMultiRegionDeltaT.H b/applications/solvers/combustion/fireFoam/setMultiRegionDeltaT.H index 31c9e675fc..a5ac0fcc9a 100644 --- a/applications/solvers/combustion/fireFoam/setMultiRegionDeltaT.H +++ b/applications/solvers/combustion/fireFoam/setMultiRegionDeltaT.H @@ -54,9 +54,18 @@ if (adjustTimeStep) runTime.setDeltaT ( - min + Foam::min ( - dt0*min(min(TFactorFluid, min(TFactorFilm, TFactorSolid)), 1.2), + dt0 + * Foam::min + ( + Foam::min + ( + TFactorFluid, + Foam::min(TFactorFilm, TFactorSolid) + ), + 1.2 + ), maxDeltaT ) ); diff --git a/applications/solvers/combustion/reactingFoam/setRDeltaT.H b/applications/solvers/combustion/reactingFoam/setRDeltaT.H index 7b449fd900..67a2b00f91 100644 --- a/applications/solvers/combustion/reactingFoam/setRDeltaT.H +++ b/applications/solvers/combustion/reactingFoam/setRDeltaT.H @@ -85,9 +85,11 @@ License // Limit the largest time scale (=> smallest reciprocal time) rDeltaT.clamp_min(1/maxDeltaT); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Flow = " - << 1/gMax(rDeltaT.primitiveField()) << ", " - << 1/gMin(rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } // Heat release rate time scale @@ -100,9 +102,11 @@ License rDeltaT.primitiveFieldRef().clamp_min(rDeltaTT); + auto limits = gMinMax(rDeltaTT.field()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Temperature = " - << 1/(gMax(rDeltaTT.field()) + VSMALL) << ", " - << 1/(gMin(rDeltaTT.field()) + VSMALL) << endl; + << limits.min() << ", " << limits.max() << endl; } // Reaction rate time scale @@ -152,9 +156,11 @@ License { rDeltaT.primitiveFieldRef().clamp_min(rDeltaTY); + auto limits = gMinMax(rDeltaTY.field()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Composition = " - << 1/(gMax(rDeltaTY.field()) + VSMALL) << ", " - << 1/(gMin(rDeltaTY.field()) + VSMALL) << endl; + << limits.min() << ", " << limits.max() << endl; } else { @@ -184,9 +190,11 @@ License // Update tho boundary values of the reciprocal time-step rDeltaT.correctBoundaryConditions(); + auto limits = gMinMax(rDeltaT.field()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Overall = " - << 1/gMax(rDeltaT.primitiveField()) - << ", " << 1/gMin(rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } diff --git a/applications/solvers/compressible/rhoCentralFoam/setRDeltaT.H b/applications/solvers/compressible/rhoCentralFoam/setRDeltaT.H index 5e2a2b302c..8f9560b742 100644 --- a/applications/solvers/compressible/rhoCentralFoam/setRDeltaT.H +++ b/applications/solvers/compressible/rhoCentralFoam/setRDeltaT.H @@ -23,7 +23,11 @@ fvc::smooth(rDeltaT, rDeltaTSmoothingCoeff); - Info<< "Flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + + Info<< "Flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } } diff --git a/applications/solvers/compressible/rhoPimpleFoam/setRDeltaT.H b/applications/solvers/compressible/rhoPimpleFoam/setRDeltaT.H index e818402eff..51ecac9f07 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/setRDeltaT.H +++ b/applications/solvers/compressible/rhoPimpleFoam/setRDeltaT.H @@ -52,18 +52,26 @@ // Update the boundary values of the reciprocal time-step rDeltaT.correctBoundaryConditions(); - Info<< "Flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + + Info<< "Flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } if (rDeltaTSmoothingCoeff < 1.0) { fvc::smooth(rDeltaT, rDeltaTSmoothingCoeff); } - Info<< "Smoothed flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + + Info<< "Smoothed flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } // Limit rate of change of time scale // - reduce as much as required @@ -78,8 +86,10 @@ rDeltaT0 *max(rDeltaT/rDeltaT0, scalar(1) - rDeltaTDampingCoeff); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< "Damped flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } } diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/compressibleMultiRegionCourantNo.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/compressibleMultiRegionCourantNo.H index 3ca2f68581..5ccc00d3ad 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/compressibleMultiRegionCourantNo.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/compressibleMultiRegionCourantNo.H @@ -1,7 +1,7 @@ scalar CoNum = -GREAT; forAll(fluidRegions, regionI) { - CoNum = max + CoNum = Foam::max ( compressibleCourantNo ( diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/derivedFvPatchFields/turbulentTemperatureTwoPhaseRadCoupledMixed/turbulentTemperatureTwoPhaseRadCoupledMixedFvPatchScalarField.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/derivedFvPatchFields/turbulentTemperatureTwoPhaseRadCoupledMixed/turbulentTemperatureTwoPhaseRadCoupledMixedFvPatchScalarField.C index 33d1c05548..a0232c0b1c 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/derivedFvPatchFields/turbulentTemperatureTwoPhaseRadCoupledMixed/turbulentTemperatureTwoPhaseRadCoupledMixedFvPatchScalarField.C +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/derivedFvPatchFields/turbulentTemperatureTwoPhaseRadCoupledMixed/turbulentTemperatureTwoPhaseRadCoupledMixedFvPatchScalarField.C @@ -387,15 +387,18 @@ updateCoeffs() { scalar Q = gSum(kappa(Tp)*patch().magSf()*snGrad()); - Info<< "T solid : " << nl << endl; + auto limits = gMinMax(Tp); + auto avg = gAverage(Tp); - Info - << " heat transfer rate from solid:" << Q - << " walltemperature " - << " min:" << gMin(Tp) - << " max:" << gMax(Tp) - << " avg:" << gAverage(Tp) << nl - << endl; + Info<< "T solid : " << nl << endl; + + Info + << " heat transfer rate from solid:" << Q + << " walltemperature " + << " min:" << limits.min() + << " max:" << limits.max() + << " avg:" << avg << nl + << endl; } } else if (regionType_ == fluid) @@ -445,10 +448,16 @@ updateCoeffs() scalarField qLiq((Tp - Tc)*KdeltaLiq); scalarField qVap((Tp - Tv.patchInternalField())*KdeltaVap); + auto infoT = gMinMax(Tp); + auto avgT = gAverage(Tp); + + auto infoLiq = gMinMax(qLiq); + auto infoVap = gMinMax(qVap); + Info<< "T flow : " << nl << endl; - Info<< " qLiq: " << gMin(qLiq) << " - " << gMax(qLiq) << endl; - Info<< " qVap: " << gMin(qVap) << " - " << gMax(qVap) << endl; + Info<< " qLiq: " << infoLiq.min() << " - " << infoLiq.max() << nl + << " qVap: " << infoVap.min() << " - " << infoVap.max() << nl; scalar QLiq = gSum(qLiq*patch().magSf()); scalar QVap = gSum(qVap*patch().magSf()); @@ -457,9 +466,9 @@ updateCoeffs() Info<< " Heat transfer to Vap: " << QVap << endl; Info<< " walltemperature " - << " min:" << gMin(Tp) - << " max:" << gMax(Tp) - << " avg:" << gAverage(Tp) + << " min:" << infoT.min() + << " max:" << infoT.max() + << " avg:" << avgT << endl; } } diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/fluid/compressibleMultiRegionCourantNo.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/fluid/compressibleMultiRegionCourantNo.H index 290bb596cf..392d74f6a3 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/fluid/compressibleMultiRegionCourantNo.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionTwoPhaseEulerFoam/fluid/compressibleMultiRegionCourantNo.H @@ -31,7 +31,7 @@ ); - CoNum = + scalar regionCoNum = 0.5*gMax ( sumPhi/fluidRegions[regioni].V().field() @@ -41,9 +41,9 @@ ( fvc::surfaceSum(mag(phi1 - phi2))().primitiveField() / fluidRegions[regioni].V().field() - )*runTime.deltaTValue(), + )*runTime.deltaTValue(); - CoNum = max(UrCoNum, CoNum); + CoNum = Foam::max(CoNum, Foam::max(regionCoNum, UrCoNum)); } } diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/compressibleMultiRegionCourantNo.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/compressibleMultiRegionCourantNo.H index dd129047dc..d5b5c7ceaa 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/compressibleMultiRegionCourantNo.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/compressibleMultiRegionCourantNo.H @@ -2,7 +2,7 @@ forAll(fluidRegions, regioni) { - CoNum = max + CoNum = Foam::max ( compressibleCourantNo ( @@ -17,7 +17,7 @@ /* forAll(porousFluidRegions, porousi) { - CoNum = max + CoNum = Foam::max ( compressibleCourantNo ( diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setInitialMultiRegionDeltaT.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setInitialMultiRegionDeltaT.H index 09f4a717a9..8be6345765 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setInitialMultiRegionDeltaT.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setInitialMultiRegionDeltaT.H @@ -47,10 +47,10 @@ if (adjustTimeStep) runTime.setDeltaT ( - min + Foam::min ( - min(maxCo/CoNum, maxDi/DiNum)*runTime.deltaTValue(), - min(runTime.deltaTValue(), maxDeltaT) + Foam::min(maxCo/CoNum, maxDi/DiNum)*runTime.deltaTValue(), + Foam::min(runTime.deltaTValue(), maxDeltaT) ) ); Info<< "deltaT = " << runTime.deltaTValue() << endl; diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setMultiRegionDeltaT.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setMultiRegionDeltaT.H index 8eed82dd5c..d81d374f41 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setMultiRegionDeltaT.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/include/setMultiRegionDeltaT.H @@ -48,18 +48,14 @@ if (adjustTimeStep) scalar maxDeltaTFluid = maxCo/(CoNum + SMALL); scalar maxDeltaTSolid = maxDi/(DiNum + SMALL); - scalar deltaTFluid = - min - ( - min(maxDeltaTFluid, 1.0 + 0.1*maxDeltaTFluid), - 1.2 - ); + const scalar deltaTFluid = + Foam::min(Foam::min(maxDeltaTFluid, 1.0 + 0.1*maxDeltaTFluid), 1.2); runTime.setDeltaT ( - min + Foam::min ( - min(deltaTFluid, maxDeltaTSolid)*runTime.deltaTValue(), + Foam::min(deltaTFluid, maxDeltaTSolid)*runTime.deltaTValue(), maxDeltaT ) ); diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solidRegionDiffusionNo.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solidRegionDiffusionNo.H index 6e87fb9203..8c6111d276 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solidRegionDiffusionNo.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solidRegionDiffusionNo.H @@ -22,7 +22,7 @@ forAll(solidRegions, i) tmp trho = thermo.rho(); const volScalarField& rho = trho(); - DiNum = max + DiNum = Foam::max ( solidRegionDiffNo ( diff --git a/applications/solvers/heatTransfer/solidFoam/solidDiffusionNo.H b/applications/solvers/heatTransfer/solidFoam/solidDiffusionNo.H index 90317f67c6..3484c35b9f 100644 --- a/applications/solvers/heatTransfer/solidFoam/solidDiffusionNo.H +++ b/applications/solvers/heatTransfer/solidFoam/solidDiffusionNo.H @@ -17,7 +17,7 @@ scalar DiNum = -GREAT; tmp trho = thermo.rho(); const volScalarField& rho = trho(); - DiNum = max + DiNum = Foam::max ( solidRegionDiffNo ( diff --git a/applications/solvers/incompressible/pimpleFoam/setRDeltaT.H b/applications/solvers/incompressible/pimpleFoam/setRDeltaT.H index 962bfa8766..3acc01c5fa 100644 --- a/applications/solvers/incompressible/pimpleFoam/setRDeltaT.H +++ b/applications/solvers/incompressible/pimpleFoam/setRDeltaT.H @@ -36,18 +36,26 @@ // Update the boundary values of the reciprocal time-step rDeltaT.correctBoundaryConditions(); - Info<< "Flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + + Info<< "Flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } if (rDeltaTSmoothingCoeff < 1.0) { fvc::smooth(rDeltaT, rDeltaTSmoothingCoeff); } - Info<< "Smoothed flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + + Info<< "Smoothed flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } // Limit rate of change of time scale // - reduce as much as required @@ -62,8 +70,10 @@ rDeltaT0 *max(rDeltaT/rDeltaT0, scalar(1) - rDeltaTDampingCoeff); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< "Damped flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } } diff --git a/applications/solvers/lagrangian/coalChemistryFoam/setRDeltaT.H b/applications/solvers/lagrangian/coalChemistryFoam/setRDeltaT.H index aabfd0e015..745249cfdf 100644 --- a/applications/solvers/lagrangian/coalChemistryFoam/setRDeltaT.H +++ b/applications/solvers/lagrangian/coalChemistryFoam/setRDeltaT.H @@ -81,9 +81,11 @@ License // Limit the largest time scale (=> smallest reciprocal time) rDeltaT.clamp_min(1/maxDeltaT); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Flow = " - << gMin(1/rDeltaT.primitiveField()) << ", " - << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } // Reaction source time scale @@ -106,9 +108,11 @@ License rDeltaT.primitiveFieldRef().clamp_min(rDeltaTT); + auto limits = gMinMax(rDeltaTT.field()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Temperature = " - << gMin(1/(rDeltaTT.field() + VSMALL)) << ", " - << gMax(1/(rDeltaTT.field() + VSMALL)) << endl; + << limits.min() << ", " << limits.max() << endl; } // Update tho boundary values of the reciprocal time-step @@ -128,9 +132,11 @@ License rDeltaT.clamp_min(rDeltaT0_damped()); } + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Overall = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } diff --git a/applications/solvers/lagrangian/reactingParcelFoam/setMultiRegionDeltaT.H b/applications/solvers/lagrangian/reactingParcelFoam/setMultiRegionDeltaT.H index 70d55cb8c8..1257447f3e 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/setMultiRegionDeltaT.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/setMultiRegionDeltaT.H @@ -36,13 +36,18 @@ Description if (adjustTimeStep) { const scalar maxDeltaTFact = - min(maxCo/(CoNum + SMALL), maxCo/(surfaceFilm.CourantNumber() + SMALL)); + Foam::min + ( + maxCo/(CoNum + SMALL), + maxCo/(surfaceFilm.CourantNumber() + SMALL) + ); + const scalar deltaTFact = - min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); + Foam::min(Foam::min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); runTime.setDeltaT ( - min + Foam::min ( deltaTFact*runTime.deltaTValue(), maxDeltaT diff --git a/applications/solvers/lagrangian/reactingParcelFoam/setRDeltaT.H b/applications/solvers/lagrangian/reactingParcelFoam/setRDeltaT.H index 8ef4cd1eb2..42e187ed3c 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/setRDeltaT.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/setRDeltaT.H @@ -81,9 +81,11 @@ License // Limit the largest time scale (=> smallest reciprocal time) rDeltaT.clamp_min(1/maxDeltaT); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Flow = " - << gMin(1/rDeltaT.primitiveField()) << ", " - << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } // Reaction source time scale @@ -105,9 +107,11 @@ License rDeltaT.primitiveFieldRef().clamp_min(rDeltaTT); + auto limits = gMinMax(rDeltaTT.field()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Temperature = " - << gMin(1/(rDeltaTT.field() + VSMALL)) << ", " - << gMax(1/(rDeltaTT.field() + VSMALL)) << endl; + << limits.min() << ", " << limits.max() << endl; } // Update the boundary values of the reciprocal time-step @@ -130,9 +134,11 @@ License // Update the boundary values of the reciprocal time-step rDeltaT.correctBoundaryConditions(); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< " Overall = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } diff --git a/applications/solvers/multiphase/VoF/setDeltaT.H b/applications/solvers/multiphase/VoF/setDeltaT.H index ac59647e7e..79fbe90c4f 100644 --- a/applications/solvers/multiphase/VoF/setDeltaT.H +++ b/applications/solvers/multiphase/VoF/setDeltaT.H @@ -36,13 +36,14 @@ Description if (adjustTimeStep) { scalar maxDeltaTFact = - min(maxCo/(CoNum + SMALL), maxAlphaCo/(alphaCoNum + SMALL)); + Foam::min(maxCo/(CoNum + SMALL), maxAlphaCo/(alphaCoNum + SMALL)); - scalar deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); + const scalar deltaTFact = + Foam::min(Foam::min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); runTime.setDeltaT ( - min + Foam::min ( deltaTFact*runTime.deltaTValue(), maxDeltaT diff --git a/applications/solvers/multiphase/VoF/setRDeltaT.H b/applications/solvers/multiphase/VoF/setRDeltaT.H index b690f0accc..bcc6e3b56d 100644 --- a/applications/solvers/multiphase/VoF/setRDeltaT.H +++ b/applications/solvers/multiphase/VoF/setRDeltaT.H @@ -98,10 +98,13 @@ // Update tho boundary values of the reciprocal time-step rDeltaT.correctBoundaryConditions(); - Info<< "Flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< "Flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } if (rDeltaTSmoothingCoeff < 1.0) { fvc::smooth(rDeltaT, rDeltaTSmoothingCoeff); @@ -125,9 +128,13 @@ fvc::sweep(rDeltaT, alpha1, nAlphaSweepIter, alphaSpreadDiff); } - Info<< "Smoothed flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + { + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + + Info<< "Smoothed flow time scale min/max = " + << limits.min() << ", " << limits.max() << endl; + } // Limit rate of change of time scale (=> smallest reciprocal time) // - reduce as much as required @@ -136,8 +143,10 @@ { rDeltaT.clamp_min(rDeltaT0_damped()); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< "Damped flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } } diff --git a/applications/solvers/multiphase/cavitatingFoam/setDeltaT.H b/applications/solvers/multiphase/cavitatingFoam/setDeltaT.H index e1e7427fe0..1d2dd28f6b 100644 --- a/applications/solvers/multiphase/cavitatingFoam/setDeltaT.H +++ b/applications/solvers/multiphase/cavitatingFoam/setDeltaT.H @@ -36,13 +36,14 @@ Description if (adjustTimeStep) { scalar maxDeltaTFact = - min(maxCo/(CoNum + SMALL), maxAcousticCo/(acousticCoNum + SMALL)); + Foam::min(maxCo/(CoNum + SMALL), maxAcousticCo/(acousticCoNum + SMALL)); - scalar deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); + const scalar deltaTFact = + Foam::min(Foam::min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); runTime.setDeltaT ( - min + Foam::min ( deltaTFact*runTime.deltaTValue(), maxDeltaT diff --git a/applications/solvers/multiphase/cavitatingFoam/setInitialDeltaT.H b/applications/solvers/multiphase/cavitatingFoam/setInitialDeltaT.H index 69fbe57333..435b2e4b0b 100644 --- a/applications/solvers/multiphase/cavitatingFoam/setInitialDeltaT.H +++ b/applications/solvers/multiphase/cavitatingFoam/setInitialDeltaT.H @@ -37,11 +37,15 @@ if (adjustTimeStep) if (CoNum > SMALL) { scalar maxDeltaTFact = - min(maxCo/(CoNum + SMALL), maxAcousticCo/(acousticCoNum + SMALL)); + Foam::min + ( + maxCo/(CoNum + SMALL), + maxAcousticCo/(acousticCoNum + SMALL) + ); runTime.setDeltaT ( - min + Foam::min ( maxDeltaTFact*runTime.deltaTValue(), maxDeltaT diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/setDeltaT.H b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/setDeltaT.H index 026fb506bb..9a67a63d13 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/setDeltaT.H +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/setDeltaT.H @@ -36,13 +36,13 @@ Description if (adjustTimeStep) { scalar maxDeltaTFact = - min + Foam::min ( maxCo/(CoNum + SMALL), - min + Foam::min ( maxAlphaCo/(alphaCoNum + SMALL), - min + Foam::min ( maxAlphaDdt/(ddtAlphaNum + SMALL), maxDi/(DiNum + SMALL) @@ -50,16 +50,18 @@ if (adjustTimeStep) ) ); - scalar deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); + const scalar deltaTFact = + Foam::min(Foam::min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2); runTime.setDeltaT ( - min + Foam::min ( deltaTFact*runTime.deltaTValue(), maxDeltaT ) ); + Info<< "deltaT = " << runTime.deltaTValue() << endl; } diff --git a/applications/solvers/multiphase/reactingMultiphaseEulerFoam/setRDeltaT.H b/applications/solvers/multiphase/reactingMultiphaseEulerFoam/setRDeltaT.H index 1d0c65b153..c15dfe4a9f 100644 --- a/applications/solvers/multiphase/reactingMultiphaseEulerFoam/setRDeltaT.H +++ b/applications/solvers/multiphase/reactingMultiphaseEulerFoam/setRDeltaT.H @@ -38,7 +38,9 @@ fvc::smooth(rDeltaT, rDeltaTSmoothingCoeff); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< "Flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } diff --git a/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/CourantNos.H b/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/CourantNos.H index 13c45ad51c..1bd1d9d036 100644 --- a/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/CourantNos.H +++ b/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/CourantNos.H @@ -8,5 +8,5 @@ Info<< "Max Ur Courant Number = " << UrCoNum << endl; - CoNum = max(CoNum, UrCoNum); + CoNum = Foam::max(CoNum, UrCoNum); } diff --git a/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/setRDeltaT.H b/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/setRDeltaT.H index 10a7c9e0f0..45d9e6c74a 100644 --- a/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/setRDeltaT.H +++ b/applications/solvers/multiphase/reactingTwoPhaseEulerFoam/setRDeltaT.H @@ -31,7 +31,9 @@ fvc::smooth(rDeltaT, rDeltaTSmoothingCoeff); + auto limits = gMinMax(rDeltaT.primitiveField()); + limits.reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL)); + Info<< "Flow time scale min/max = " - << gMin(1/rDeltaT.primitiveField()) - << ", " << gMax(1/rDeltaT.primitiveField()) << endl; + << limits.min() << ", " << limits.max() << endl; } diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/CourantNos.H b/applications/solvers/multiphase/twoPhaseEulerFoam/CourantNos.H index d828f32769..96e1ece1ac 100644 --- a/applications/solvers/multiphase/twoPhaseEulerFoam/CourantNos.H +++ b/applications/solvers/multiphase/twoPhaseEulerFoam/CourantNos.H @@ -8,5 +8,5 @@ Info<< "Max Ur Courant Number = " << UrCoNum << endl; - CoNum = max(CoNum, UrCoNum); + CoNum = Foam::max(CoNum, UrCoNum); } diff --git a/applications/test/fieldMapping/Test-fieldMapping.C b/applications/test/fieldMapping/Test-fieldMapping.C index bb4ad0576b..f2bd3a87c9 100644 --- a/applications/test/fieldMapping/Test-fieldMapping.C +++ b/applications/test/fieldMapping/Test-fieldMapping.C @@ -262,13 +262,12 @@ int main(int argc, char *argv[]) // Check constant profile { - const scalar max = gMax(one); - const scalar min = gMin(one); + auto limits = gMinMax(one); - Info<< "Uniform one field min = " << min - << " max = " << max << endl; + Info<< "Uniform one field min = " + << limits.min() << " max = " << limits.max() << endl; - if (isNotEqual(max, 1) || isNotEqual(min, 1)) + if (isNotEqual(limits.min(), 1) || isNotEqual(limits.max(), 1)) { FatalErrorInFunction << "Uniform volVectorField not preserved." @@ -286,13 +285,12 @@ int main(int argc, char *argv[]) { const scalarField diff = ccX-mesh.C().component(0); - const scalar max = gMax(diff); - const scalar min = gMin(diff); + auto limits = gMinMax(diff); - Info<< "Linear profile field min = " << min - << " max = " << max << endl; + Info<< "Linear profile field min = " + << limits.min() << " max = " << limits.max() << endl; - if (isNotEqual(max, 0) || isNotEqual(min, 0)) + if (isNotEqual(limits.min(), 0) || isNotEqual(limits.max(), 0)) { FatalErrorInFunction << "Linear profile not preserved." @@ -309,13 +307,12 @@ int main(int argc, char *argv[]) // Check face field mapping if (surfaceOne.size()) { - const scalar max = gMax(surfaceOne.primitiveField()); - const scalar min = gMin(surfaceOne.primitiveField()); + auto limits = gMinMax(surfaceOne.primitiveField()); - Info<< "Uniform surface field min = " << min - << " max = " << max << endl; + Info<< "Uniform surface field min = " + << limits.min() << " max = " << limits.max() << endl; - if (isNotEqual(max, 1) || isNotEqual(min, 1)) + if (isNotEqual(limits.min(), 1) || isNotEqual(limits.max(), 1)) { FatalErrorInFunction << "Uniform surfaceScalarField not preserved." diff --git a/applications/test/hexRef8/Test-hexRef8.C b/applications/test/hexRef8/Test-hexRef8.C index 12c6d5e38e..f122a6a92e 100644 --- a/applications/test/hexRef8/Test-hexRef8.C +++ b/applications/test/hexRef8/Test-hexRef8.C @@ -344,13 +344,12 @@ int main(int argc, char *argv[]) // Check constant profile { - const scalar max = gMax(one); - const scalar min = gMin(one); + auto limits = gMinMax(one); - Info<< "Uniform one field min = " << min - << " max = " << max << endl; + Info<< "Uniform one field min = " + << limits.min() << " max = " << limits.max() << endl; - if (isNotEqual(min, 1) || isNotEqual(max, 1)) + if (isNotEqual(limits.min(), 1) || isNotEqual(limits.max(), 1)) { FatalErrorInFunction << "Uniform volVectorField not preserved." @@ -368,13 +367,12 @@ int main(int argc, char *argv[]) { const scalarField diff = ccX-mesh.C().component(0); - const scalar max = gMax(diff); - const scalar min = gMin(diff); + auto limits = gMinMax(diff); - Info<< "Linear profile field min = " << min - << " max = " << max << endl; + Info<< "Linear profile field min = " + << limits.min() << " max = " << limits.max() << endl; - if (isNotEqual(min, 0) || isNotEqual(max, 0)) + if (isNotEqual(limits.min(), 0) || isNotEqual(limits.max(), 0)) { Info<< "Linear profile not preserved." << " Min and max should both be 0.0. min:" << min @@ -389,13 +387,12 @@ int main(int argc, char *argv[]) // Check face field mapping if (surfaceOne.size()) { - const scalar max = gMax(surfaceOne.primitiveField()); - const scalar min = gMin(surfaceOne.primitiveField()); + auto limits = gMinMax(surfaceOne.primitiveField()); - Info<< "Uniform surface field min = " << min - << " max = " << max << endl; + Info<< "Uniform surface field min = " + << limits.min() << " max = " << limits.max() << endl; - if (isNotEqual(min, 1) || isNotEqual(max, 1)) + if (isNotEqual(limits.min(), 1) || isNotEqual(limits.max(), 1)) { FatalErrorInFunction << "Uniform surfaceScalarField not preserved." diff --git a/applications/utilities/mesh/advanced/refineHexMesh/refineHexMesh.C b/applications/utilities/mesh/advanced/refineHexMesh/refineHexMesh.C index 0da12172db..fa387d0116 100644 --- a/applications/utilities/mesh/advanced/refineHexMesh/refineHexMesh.C +++ b/applications/utilities/mesh/advanced/refineHexMesh/refineHexMesh.C @@ -145,17 +145,22 @@ int main(int argc, char *argv[]) hexRef8 meshCutter(mesh); // Some stats - Info<< "Read mesh:" << nl - << " cells:" << mesh.globalData().nTotalCells() << nl - << " faces:" << mesh.globalData().nTotalFaces() << nl - << " points:" << mesh.globalData().nTotalPoints() << nl - << " cellLevel :" - << " min:" << gMin(meshCutter.cellLevel()) - << " max:" << gMax(meshCutter.cellLevel()) << nl - << " pointLevel :" - << " min:" << gMin(meshCutter.pointLevel()) - << " max:" << gMax(meshCutter.pointLevel()) << nl - << endl; + { + auto cellLimits = gMinMax(meshCutter.cellLevel()); + auto pointLimits = gMinMax(meshCutter.pointLevel()); + + Info<< "Read mesh:" << nl + << " cells:" << mesh.globalData().nTotalCells() << nl + << " faces:" << mesh.globalData().nTotalFaces() << nl + << " points:" << mesh.globalData().nTotalPoints() << nl + << " cellLevel :" + << " min:" << cellLimits.min() + << " max:" << cellLimits.max() << nl + << " pointLevel :" + << " min:" << pointLimits.min() + << " max:" << pointLimits.max() << nl + << endl; + } // Maintain 2:1 ratio diff --git a/applications/utilities/mesh/advanced/selectCells/edgeStats.C b/applications/utilities/mesh/advanced/selectCells/edgeStats.C index 579a989b4d..1f54ceb793 100644 --- a/applications/utilities/mesh/advanced/selectCells/edgeStats.C +++ b/applications/utilities/mesh/advanced/selectCells/edgeStats.C @@ -37,7 +37,6 @@ License const Foam::scalar Foam::edgeStats::edgeTol_ = 1e-3; - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // Foam::direction Foam::edgeStats::getNormalDir @@ -45,26 +44,25 @@ Foam::direction Foam::edgeStats::getNormalDir const twoDPointCorrector* correct2DPtr ) const { - direction dir = 3; - if (correct2DPtr) { const vector& normal = correct2DPtr->planeNormal(); - if (mag(normal & vector(1, 0, 0)) > 1-edgeTol_) + if (mag(normal.x()) > 1-edgeTol_) { - dir = 0; + return vector::X; } - else if (mag(normal & vector(0, 1, 0)) > 1-edgeTol_) + else if (mag(normal.y()) > 1-edgeTol_) { - dir = 1; + return vector::Y; } - else if (mag(normal & vector(0, 0, 1)) > 1-edgeTol_) + else if (mag(normal.z()) > 1-edgeTol_) { - dir = 2; + return vector::Z; } } - return dir; + + return direction(3); } @@ -95,12 +93,9 @@ Foam::edgeStats::edgeStats(const polyMesh& mesh) { Info<< "Correcting for 2D motion" << endl << endl; - autoPtr correct2DPtr - ( - new twoDPointCorrector(mesh) - ); + twoDPointCorrector correct2D(mesh); - normalDir_ = getNormalDir(&correct2DPtr()); + normalDir_ = getNormalDir(&correct2D); } } } @@ -122,24 +117,15 @@ Foam::edgeStats::edgeStats Foam::scalar Foam::edgeStats::minLen(Ostream& os) const { - label nX = 0; - label nY = 0; - label nZ = 0; + label nAny(0); + label nX(0); + label nY(0); + label nZ(0); - scalar minX = GREAT; - scalar maxX = -GREAT; - vector x(1, 0, 0); - - scalar minY = GREAT; - scalar maxY = -GREAT; - vector y(0, 1, 0); - - scalar minZ = GREAT; - scalar maxZ = -GREAT; - vector z(0, 0, 1); - - scalar minOther = GREAT; - scalar maxOther = -GREAT; + scalarMinMax limitsAny(GREAT, -GREAT); + scalarMinMax limitsX(limitsAny); + scalarMinMax limitsY(limitsAny); + scalarMinMax limitsZ(limitsAny); const edgeList& edges = mesh_.edges(); @@ -151,58 +137,75 @@ Foam::scalar Foam::edgeStats::minLen(Ostream& os) const eVec /= eMag; - if (mag(eVec & x) > 1-edgeTol_) + if (mag(eVec.x()) > 1-edgeTol_) { - minX = min(minX, eMag); - maxX = max(maxX, eMag); + limitsX.add(eMag); nX++; } - else if (mag(eVec & y) > 1-edgeTol_) + else if (mag(eVec.y()) > 1-edgeTol_) { - minY = min(minY, eMag); - maxY = max(maxY, eMag); + limitsY.add(eMag); nY++; } - else if (mag(eVec & z) > 1-edgeTol_) + else if (mag(eVec.z()) > 1-edgeTol_) { - minZ = min(minZ, eMag); - maxZ = max(maxZ, eMag); + limitsZ.add(eMag); nZ++; } else { - minOther = min(minOther, eMag); - maxOther = max(maxOther, eMag); + limitsAny.add(eMag); + nAny++; } } os << "Mesh bounding box:" << boundBox(mesh_.points()) << nl << nl << "Mesh edge statistics:" << nl - << " x aligned : number:" << nX << "\tminLen:" << minX - << "\tmaxLen:" << maxX << nl - << " y aligned : number:" << nY << "\tminLen:" << minY - << "\tmaxLen:" << maxY << nl - << " z aligned : number:" << nZ << "\tminLen:" << minZ - << "\tmaxLen:" << maxZ << nl - << " other : number:" << mesh_.nEdges() - nX - nY - nZ - << "\tminLen:" << minOther - << "\tmaxLen:" << maxOther << nl << endl; + << " x aligned : number:" << nX + << "\tminLen:" << limitsX.min() << "\tmaxLen:" << limitsX.max() << nl + << " y aligned : number:" << nY + << "\tminLen:" << limitsY.min() << "\tmaxLen:" << limitsY.max() << nl + << " z aligned : number:" << nZ + << "\tminLen:" << limitsZ.min() << "\tmaxLen:" << limitsZ.max() << nl + << " other : number:" << nAny + << "\tminLen:" << limitsAny.min() + << "\tmaxLen:" << limitsAny.max() << nl << endl; - if (normalDir_ == 0) + if (normalDir_ == vector::X) { - return min(minY, min(minZ, minOther)); + return Foam::min + ( + limitsAny.min(), + Foam::min(limitsY.min(), limitsZ.min()) + ); } - else if (normalDir_ == 1) + else if (normalDir_ == vector::Y) { - return min(minX, min(minZ, minOther)); + return Foam::min + ( + limitsAny.min(), + Foam::min(limitsX.min(), limitsZ.min()) + ); } - else if (normalDir_ == 2) + else if (normalDir_ == vector::Z) { - return min(minX, min(minY, minOther)); + return Foam::min + ( + limitsAny.min(), + Foam::min(limitsX.min(), limitsY.min()) + ); } else { - return min(minX, min(minY, min(minZ, minOther))); + return Foam::min + ( + limitsAny.min(), + Foam::min + ( + limitsX.min(), + Foam::min(limitsY.min(), limitsZ.min()) + ) + ); } } diff --git a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C index 6aa76e6653..2b537081fe 100644 --- a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C +++ b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C @@ -81,26 +81,25 @@ void writeSet(const cellSet& cells, const string& msg) direction getNormalDir(const twoDPointCorrector* correct2DPtr) { - direction dir = 3; - if (correct2DPtr) { const vector& normal = correct2DPtr->planeNormal(); - if (mag(normal & vector(1, 0, 0)) > 1-edgeTol) + if (mag(normal.x()) > 1-edgeTol) { - dir = 0; + return vector::X; } - else if (mag(normal & vector(0, 1, 0)) > 1-edgeTol) + else if (mag(normal.y()) > 1-edgeTol) { - dir = 1; + return vector::Y; } - else if (mag(normal & vector(0, 0, 1)) > 1-edgeTol) + else if (mag(normal.z()) > 1-edgeTol) { - dir = 2; + return vector::Z; } } - return dir; + + return direction(3); } @@ -109,89 +108,95 @@ direction getNormalDir(const twoDPointCorrector* correct2DPtr) // directions but exclude component (0=x, 1=y, 2=z, other=none) scalar getEdgeStats(const primitiveMesh& mesh, const direction excludeCmpt) { - label nX = 0; - label nY = 0; - label nZ = 0; + label nAny(0); + label nX(0); + label nY(0); + label nZ(0); - scalar minX = GREAT; - scalar maxX = -GREAT; - vector x(1, 0, 0); - - scalar minY = GREAT; - scalar maxY = -GREAT; - vector y(0, 1, 0); - - scalar minZ = GREAT; - scalar maxZ = -GREAT; - vector z(0, 0, 1); - - scalar minOther = GREAT; - scalar maxOther = -GREAT; + scalarMinMax limitsAny(GREAT, -GREAT); + scalarMinMax limitsX(limitsAny); + scalarMinMax limitsY(limitsAny); + scalarMinMax limitsZ(limitsAny); const edgeList& edges = mesh.edges(); - forAll(edges, edgei) + for (const edge& e : edges) { - const edge& e = edges[edgei]; - vector eVec(e.vec(mesh.points())); scalar eMag = mag(eVec); eVec /= eMag; - if (mag(eVec & x) > 1-edgeTol) + if (mag(eVec.x()) > 1-edgeTol) { - minX = min(minX, eMag); - maxX = max(maxX, eMag); + limitsX.add(eMag); nX++; } - else if (mag(eVec & y) > 1-edgeTol) + else if (mag(eVec.y()) > 1-edgeTol) { - minY = min(minY, eMag); - maxY = max(maxY, eMag); + limitsY.add(eMag); nY++; } - else if (mag(eVec & z) > 1-edgeTol) + else if (mag(eVec.z()) > 1-edgeTol) { - minZ = min(minZ, eMag); - maxZ = max(maxZ, eMag); + limitsZ.add(eMag); nZ++; } else { - minOther = min(minOther, eMag); - maxOther = max(maxOther, eMag); + limitsAny.add(eMag); + nAny++; } } Info<< "Mesh bounding box:" << boundBox(mesh.points()) << nl << nl << "Mesh edge statistics:" << nl - << " x aligned : number:" << nX << "\tminLen:" << minX - << "\tmaxLen:" << maxX << nl - << " y aligned : number:" << nY << "\tminLen:" << minY - << "\tmaxLen:" << maxY << nl - << " z aligned : number:" << nZ << "\tminLen:" << minZ - << "\tmaxLen:" << maxZ << nl - << " other : number:" << mesh.nEdges() - nX - nY - nZ - << "\tminLen:" << minOther - << "\tmaxLen:" << maxOther << nl << endl; + << " x aligned : number:" << nX + << "\tminLen:" << limitsX.min() << "\tmaxLen:" << limitsX.max() << nl + << " y aligned : number:" << nY + << "\tminLen:" << limitsY.min() << "\tmaxLen:" << limitsY.max() << nl + << " z aligned : number:" << nZ + << "\tminLen:" << limitsZ.min() << "\tmaxLen:" << limitsZ.max() << nl + << " other : number:" << nAny + << "\tminLen:" << limitsAny.min() + << "\tmaxLen:" << limitsAny.max() << nl << endl; - if (excludeCmpt == 0) + if (excludeCmpt == vector::X) { - return min(minY, min(minZ, minOther)); + return Foam::min + ( + limitsAny.min(), + Foam::min(limitsY.min(), limitsZ.min()) + ); } - else if (excludeCmpt == 1) + else if (excludeCmpt == vector::Y) { - return min(minX, min(minZ, minOther)); + return Foam::min + ( + limitsAny.min(), + Foam::min(limitsX.min(), limitsZ.min()) + ); } - else if (excludeCmpt == 2) + else if (excludeCmpt == vector::Z) { - return min(minX, min(minY, minOther)); + return Foam::min + ( + limitsAny.min(), + Foam::min(limitsX.min(), limitsY.min()) + ); } else { - return min(minX, min(minY, min(minZ, minOther))); + return Foam::min + ( + limitsAny.min(), + Foam::min + ( + limitsX.min(), + Foam::min(limitsY.min(), limitsZ.min()) + ) + ); } } diff --git a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C index 0076597534..3a51efb298 100644 --- a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C +++ b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C @@ -63,96 +63,72 @@ static const scalar edgeTol = 1e-3; // Print edge statistics on mesh. void printEdgeStats(const polyMesh& mesh) { - label nX = 0; - label nY = 0; - label nZ = 0; + label nAny(0); + label nX(0); + label nY(0); + label nZ(0); - scalar minX = GREAT; - scalar maxX = -GREAT; - static const vector x(1, 0, 0); - - scalar minY = GREAT; - scalar maxY = -GREAT; - static const vector y(0, 1, 0); - - scalar minZ = GREAT; - scalar maxZ = -GREAT; - static const vector z(0, 0, 1); - - scalar minOther = GREAT; - scalar maxOther = -GREAT; + scalarMinMax limitsAny(GREAT, -GREAT); + scalarMinMax limitsX(limitsAny); + scalarMinMax limitsY(limitsAny); + scalarMinMax limitsZ(limitsAny); bitSet isMasterEdge(syncTools::getMasterEdges(mesh)); const edgeList& edges = mesh.edges(); - forAll(edges, edgeI) + for (const label edgei : isMasterEdge) { - if (isMasterEdge.test(edgeI)) + const edge& e = edges[edgei]; + + vector eVec(e.vec(mesh.points())); + + scalar eMag = mag(eVec); + + eVec /= eMag; + + if (mag(eVec.x()) > 1-edgeTol) { - const edge& e = edges[edgeI]; - - vector eVec(e.vec(mesh.points())); - - scalar eMag = mag(eVec); - - eVec /= eMag; - - if (mag(eVec & x) > 1-edgeTol) - { - minX = min(minX, eMag); - maxX = max(maxX, eMag); - nX++; - } - else if (mag(eVec & y) > 1-edgeTol) - { - minY = min(minY, eMag); - maxY = max(maxY, eMag); - nY++; - } - else if (mag(eVec & z) > 1-edgeTol) - { - minZ = min(minZ, eMag); - maxZ = max(maxZ, eMag); - nZ++; - } - else - { - minOther = min(minOther, eMag); - maxOther = max(maxOther, eMag); - } + limitsX.add(eMag); + nX++; + } + else if (mag(eVec.y()) > 1-edgeTol) + { + limitsY.add(eMag); + nY++; + } + else if (mag(eVec.z()) > 1-edgeTol) + { + limitsZ.add(eMag); + nZ++; + } + else + { + limitsAny.add(eMag); + nAny++; } } - label nEdges = mesh.nEdges(); - reduce(nEdges, sumOp