diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C index 40c906b57e..a106c8e5aa 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -679,7 +679,7 @@ void Foam::radiation::laserDTRM::calculate() } } - scalar totalQ = gSum(Q_.primitiveFieldRef()*mesh_.V()); + scalar totalQ = gWeightedSum(mesh_.V(), Q_.primitiveField()); Info << "Total energy absorbed [W]: " << totalQ << endl; if (mesh_.time().writeTime()) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C index cc824309b6..5a33ae09a9 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C @@ -79,7 +79,7 @@ cylindricalInletVelocityFvPatchVectorField : fixedValueFvPatchField(p, iF, dict), origin_(dict.getCompat("origin", {{"centre", 1712}})), - axis_(dict.lookup("axis")), + axis_(dict.get("axis")), axialVelocity_(Function1::New("axialVelocity", dict, &db())), radialVelocity_ ( diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C index d6d8a6eb24..6e40b3b97c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedMean/fixedMeanFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2016 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,8 +109,7 @@ void Foam::fixedMeanFvPatchField::updateCoeffs() Field newValues(this->patchInternalField()); Type meanValuePsi = - gSum(this->patch().magSf()*newValues) - /gSum(this->patch().magSf()); + gWeightedAverage(this->patch().magSf(), newValues); if (mag(meanValue) > SMALL && mag(meanValuePsi) > 0.5*mag(meanValue)) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedMeanOutletInlet/fixedMeanOutletInletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedMeanOutletInlet/fixedMeanOutletInletFvPatchField.C index ff40e480f1..3e12360249 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedMeanOutletInlet/fixedMeanOutletInletFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedMeanOutletInlet/fixedMeanOutletInletFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2018 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -117,9 +117,7 @@ void Foam::fixedMeanOutletInletFvPatchField::updateCoeffs() Field newValues(this->patchInternalField()); - Type meanValuePsi = - gSum(this->patch().magSf()*newValues) - /gSum(this->patch().magSf()); + Type meanValuePsi = gWeightedAverage(this->patch().magSf(), newValues); if (mag(meanValue) > SMALL && mag(meanValuePsi) > 0.5*mag(meanValue)) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/Sampled/Sampled.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/Sampled/Sampled.C index 7cc3c3048d..56423e5480 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/Sampled/Sampled.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/Sampled/Sampled.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -285,7 +285,7 @@ Foam::PatchFunction1Types::Sampled::value ( mag(this->mappedPatchBase::patch_.faceAreas()) ); - averagePsi = gSum(magSf*newValues)/gSum(magSf); + averagePsi = gWeightedAverage(magSf, newValues); } else { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C index 786ab2511b..16573052aa 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -788,8 +788,7 @@ Foam::mappedPatchFieldBase::mappedField if (setAverage_) { Type averagePsi = - gSum(patchField_.patch().magSf()*newValues) - /gSum(patchField_.patch().magSf()); + gWeightedAverage(patchField_.patch().magSf(), newValues); if (mag(averagePsi) > 0.5*mag(average_)) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C index 72ae806e5a..bbb48fa41f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletMappedUniformInlet/outletMappedUniformInletFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2022 OpenCFD Ltd. + Copyright (C) 2020-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -369,7 +369,7 @@ void Foam::outletMappedUniformInletFvPatchField::updateCoeffs() mapField.append ( - gSum(outlet.magSf()*outletFld)/gSum(outlet.magSf()) + gWeightedAverage(outlet.magSf(), outletFld) ); } } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C index 6d90bf382b..01eee817ae 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C @@ -130,8 +130,8 @@ void Foam::outletPhaseMeanVelocityFvPatchVectorField::updateCoeffs() patch().lookupPatchField(alphaName_) ); - alphap = max(alphap, scalar(0)); - alphap = min(alphap, scalar(1)); + // Clamp to 0-1 range + alphap.clamp_range(Foam::zero_one{}); // Get the patchInternalField (zero-gradient field) vectorField Uzg(patchInternalField()); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/plenumPressure/plenumPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/plenumPressure/plenumPressureFvPatchScalarField.C index 4b5dc3559f..2dc83bd329 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/plenumPressure/plenumPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/plenumPressure/plenumPressureFvPatchScalarField.C @@ -211,7 +211,7 @@ void Foam::plenumPressureFvPatchScalarField::updateCoeffs() { if (hasRho_) { - massFlowRate = - gSum(rho_*phi); + massFlowRate = - rho_*gSum(phi); } else { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressurePIDControlInletVelocity/pressurePIDControlInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressurePIDControlInletVelocity/pressurePIDControlInletVelocityFvPatchVectorField.C index 84c265f990..4ca7a6c842 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/pressurePIDControlInletVelocity/pressurePIDControlInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/pressurePIDControlInletVelocity/pressurePIDControlInletVelocityFvPatchVectorField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -243,7 +243,7 @@ void Foam::pressurePIDControlInletVelocityFvPatchVectorField::updateCoeffs() { const auto& rhop = patch().lookupPatchField(rhoName_); - rho = gSum(rhop*patch().magSf())/gSum(patch().magSf()); + rho = gWeightedAverage(patch().magSf(), rhop); } else { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/rotatingWallVelocity/rotatingWallVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/rotatingWallVelocity/rotatingWallVelocityFvPatchVectorField.C index 095c96367f..ca57fe5ad7 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/rotatingWallVelocity/rotatingWallVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/rotatingWallVelocity/rotatingWallVelocityFvPatchVectorField.C @@ -41,7 +41,7 @@ rotatingWallVelocityFvPatchVectorField ) : fixedValueFvPatchField(p, iF), - origin_(), + origin_(Zero), axis_(Zero), omega_(nullptr) {} @@ -56,8 +56,8 @@ rotatingWallVelocityFvPatchVectorField ) : fixedValueFvPatchField(p, iF, dict, IOobjectOption::NO_READ), - origin_(dict.lookup("origin")), - axis_(dict.lookup("axis")), + origin_(dict.get("origin")), + axis_(dict.get("axis")), omega_(Function1::New("omega", dict, &db())) { if (!this->readValueEntry(dict)) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C index 86e5291206..5e75e74855 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C @@ -57,8 +57,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump() deltaP /= patch().lookupPatchField(rhoName_); } - const vector axisHat = - gSum(patch().nf()*patch().magSf())/gSum(patch().magSf()); + const vector axisHat = gSum(patch().Sf())/gSum(patch().magSf()); vectorField tanDir ( @@ -131,7 +130,7 @@ Foam::swirlFanVelocityFvPatchField::swirlFanVelocityFvPatchField phiName_("phi"), pName_("p"), rhoName_("rho"), - origin_(), + origin_(Zero), rpm_(nullptr), fanEff_(1), rEff_(0), @@ -158,7 +157,7 @@ Foam::swirlFanVelocityFvPatchField::swirlFanVelocityFvPatchField ( "origin", returnReduceOr(patch().size()) - ? gSum(patch().Cf()*patch().magSf())/gSum(patch().magSf()) + ? gWeightedAverage(patch().magSf(), patch().Cf()) : Zero ) ), diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C index b4e4a38435..beb80502b3 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,7 +45,7 @@ swirlFlowRateInletVelocityFvPatchVectorField fixedValueFvPatchField(p, iF), phiName_("phi"), rhoName_("rho"), - origin_(), + origin_(Zero), axis_(Zero), flowRate_(), rpm_() @@ -69,7 +69,7 @@ swirlFlowRateInletVelocityFvPatchVectorField ( "origin", returnReduceOr(patch().size()) - ? gSum(patch().Cf()*patch().magSf())/gSum(patch().magSf()) + ? gWeightedAverage(patch().magSf(), patch().Cf()) : Zero ) ), diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlInletVelocity/swirlInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlInletVelocity/swirlInletVelocityFvPatchVectorField.C index d3957f09ae..76ab66f0b1 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/swirlInletVelocity/swirlInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/swirlInletVelocity/swirlInletVelocityFvPatchVectorField.C @@ -74,8 +74,8 @@ swirlInletVelocityFvPatchVectorField ) : fixedValueFvPatchField(p, iF, dict), - origin_(dict.lookup("origin")), - axis_(dict.lookup("axis")), + origin_(dict.get("origin")), + axis_(dict.get("axis")), axialVelocity_(Function1::New("axialVelocity", dict, &db())), radialVelocity_ ( diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C index a59ecba23f..888e5bc6c0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C @@ -895,8 +895,7 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::updateCoeffs() // (PCR:p. 522) const vector UBulk ( - gSum(UMean()*patch().magSf()) - /(gSum(patch().magSf()) + ROOTVSMALL) + gWeightedAverage(patch().magSf(), UMean()) ); // Move eddies using bulk velocity diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchField.C index f947bfb24f..770dfcc135 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -174,11 +174,7 @@ void Foam::turbulentDigitalFilterInletFvPatchField::mapMean const vectorField& mean = tmean.cref(); // Calculate flow-rate correction factor for vector fields (KCX:Eq. 8) - const vector bulk - ( - gSum(mean*this->patch().magSf()) - /(gSum(this->patch().magSf()) + ROOTVSMALL) - ); + const vector bulk = gWeightedAverage(this->patch().magSf(), mean); const scalar correct ( diff --git a/src/finiteVolume/fields/fvPatchFields/derived/variableHeightFlowRateInletVelocity/variableHeightFlowRateInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/variableHeightFlowRateInletVelocity/variableHeightFlowRateInletVelocityFvPatchVectorField.C index cc709fe383..067c93d67f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/variableHeightFlowRateInletVelocity/variableHeightFlowRateInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/variableHeightFlowRateInletVelocity/variableHeightFlowRateInletVelocityFvPatchVectorField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2016 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -125,14 +125,14 @@ void Foam::variableHeightFlowRateInletVelocityFvPatchVectorField::updateCoeffs() scalarField alphap(alpha.boundaryField()[patch().index()]); - alphap = max(alphap, scalar(0)); - alphap = min(alphap, scalar(1)); + // Clamp to 0-1 range + alphap.clamp_range(Foam::zero_one{}); const scalar t = db().time().timeOutputValue(); scalar flowRate = flowRate_->value(t); // a simpler way of doing this would be nice - scalar avgU = -flowRate/gSum(patch().magSf()*alphap); + const scalar avgU = -flowRate/gWeightedSum(patch().magSf(), alphap); vectorField n(patch().nf()); diff --git a/src/functionObjects/field/DESModelRegions/DESModelRegions.C b/src/functionObjects/field/DESModelRegions/DESModelRegions.C index ce2e343942..d026e4530b 100644 --- a/src/functionObjects/field/DESModelRegions/DESModelRegions.C +++ b/src/functionObjects/field/DESModelRegions/DESModelRegions.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2015 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -110,23 +110,18 @@ bool Foam::functionObjects::DESModelRegions::execute() { Log << type() << " " << name() << " execute:" << nl; - volScalarField& DESModelRegions = - lookupObjectRef(resultName_); + auto& regions = lookupObjectRef(resultName_); - - if (foundObject(turbulenceModel::propertiesName)) + if + ( + const auto* modelp + = cfindObject(turbulenceModel::propertiesName) + ) { - const DESModelBase& model = - lookupObject - ( - turbulenceModel::propertiesName - ); - - DESModelRegions == model.LESRegion(); + regions == (*modelp).LESRegion(); const scalar prc = - gSum(DESModelRegions.primitiveField()*mesh_.V()) - /gSum(mesh_.V())*100.0; + gWeightedAverage(mesh_.V(), regions.primitiveField())*100.0; file() << time_.value() << token::TAB << prc @@ -149,14 +144,13 @@ bool Foam::functionObjects::DESModelRegions::execute() bool Foam::functionObjects::DESModelRegions::write() { - const volScalarField& DESModelRegions = - lookupObject(resultName_); + const auto& regions = lookupObject(resultName_); Log << type() << " " << name() << " output:" << nl - << " writing field " << DESModelRegions.name() << nl + << " writing field " << regions.name() << nl << endl; - DESModelRegions.write(); + regions.write(); return true; } diff --git a/src/functionObjects/field/comfort/comfort.C b/src/functionObjects/field/comfort/comfort.C index ed0d465e5c..9eca338fe8 100644 --- a/src/functionObjects/field/comfort/comfort.C +++ b/src/functionObjects/field/comfort/comfort.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2019 OpenFOAM Foundation - Copyright (C) 2021-2023 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -89,12 +89,15 @@ Foam::dimensionedScalar Foam::functionObjects::comfort::Trad() const if (isType(pTBf)) { - areaIntegral += gSum(pSf); - TareaIntegral += gSum(pSf*pT); + areaIntegral += sum(pSf); + TareaIntegral += weightedSum(pSf, pT); } } - Trad.value() = TareaIntegral/areaIntegral; + reduce(TareaIntegral, sumOp()); + reduce(areaIntegral, sumOp()); + + Trad.value() = TareaIntegral/(areaIntegral + VSMALL); } // Bounds based on EN ISO 7730 diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C index 70618231d0..4112083a3e 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 OpenFOAM Foundation - Copyright (C) 2016-2024 OpenCFD Ltd. + Copyright (C) 2016-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -272,7 +272,7 @@ bool Foam::functionObjects::wallHeatFlux::execute() const scalarField& hfp = wallHeatFlux.boundaryField()[patchi]; const MinMax limits = gMinMax(hfp); - const scalar integralHfp = gSum(magSf[patchi]*hfp); + const scalar integralHfp = gWeightedSum(magSf[patchi], hfp); if (Pstream::master()) { diff --git a/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingDisplacement/angularOscillatingDisplacementPointPatchVectorField.C b/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingDisplacement/angularOscillatingDisplacementPointPatchVectorField.C index 7ff26948cb..0594512e12 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingDisplacement/angularOscillatingDisplacementPointPatchVectorField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingDisplacement/angularOscillatingDisplacementPointPatchVectorField.C @@ -64,8 +64,8 @@ angularOscillatingDisplacementPointPatchVectorField ) : fixedValuePointPatchField(p, iF, dict), - axis_(dict.lookup("axis")), - origin_(dict.lookup("origin")), + axis_(dict.get("axis")), + origin_(dict.get("origin")), angle0_(dict.get("angle0")), amplitude_(dict.get("amplitude")), omega_(dict.get("omega")) diff --git a/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingVelocity/angularOscillatingVelocityPointPatchVectorField.C b/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingVelocity/angularOscillatingVelocityPointPatchVectorField.C index 792daffdcf..ff3ca22233 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingVelocity/angularOscillatingVelocityPointPatchVectorField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/angularOscillatingVelocity/angularOscillatingVelocityPointPatchVectorField.C @@ -64,8 +64,8 @@ angularOscillatingVelocityPointPatchVectorField ) : fixedValuePointPatchField(p, iF, dict), - axis_(dict.lookup("axis")), - origin_(dict.lookup("origin")), + axis_(dict.get("axis")), + origin_(dict.get("origin")), angle0_(dict.get("angle0")), amplitude_(dict.get("amplitude")), omega_(dict.get("omega")) diff --git a/src/fvOptions/sources/derived/directionalPressureGradientExplicitSource/directionalPressureGradientExplicitSource.C b/src/fvOptions/sources/derived/directionalPressureGradientExplicitSource/directionalPressureGradientExplicitSource.C index c2d6ea05c1..7a78483534 100644 --- a/src/fvOptions/sources/derived/directionalPressureGradientExplicitSource/directionalPressureGradientExplicitSource.C +++ b/src/fvOptions/sources/derived/directionalPressureGradientExplicitSource/directionalPressureGradientExplicitSource.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2015-2023 OpenCFD Ltd. + Copyright (C) 2015-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -337,7 +337,7 @@ void Foam::fv::directionalPressureGradientExplicitSource::correct ); const scalarField rho(turbModel.rho(),cells_); const scalarField cv(mesh_.V(), cells_); - scalar rhoAve = gSumProd(rho, cv)/gSum(cv); + scalar rhoAve = gWeightedAverage(cv, rho); volFlowRate = mag(totalphi)/rhoAve; } diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C index 6381b3733c..ddb5f7fd0d 100644 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C @@ -2687,7 +2687,7 @@ Foam::label Foam::snappyRefineDriver::directionalSmooth const vectorField residual(baseNewPoints - baseMeshPoints); { - scalar res(gSum(mag(residual))); + scalar res(gSumMag(residual)); if (iter == 0) { diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C index 16d7fbc850..ef0856fe7b 100644 --- a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C +++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -700,8 +700,7 @@ Foam::PatchFunction1Types::MappedFile::value if (this->faceValues()) { - const scalarField magSf(mag(this->patch_.faceAreas())); - averagePsi = gSum(magSf*fld)/gSum(magSf); + averagePsi = gWeightedAverage(this->patch_.magFaceAreas(), fld); } else { diff --git a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointRotatingWallVelocity/adjointRotatingWallVelocityFvPatchVectorField.C b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointRotatingWallVelocity/adjointRotatingWallVelocityFvPatchVectorField.C index ad2e887809..c6f0996b86 100644 --- a/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointRotatingWallVelocity/adjointRotatingWallVelocityFvPatchVectorField.C +++ b/src/optimisation/adjointOptimisation/adjoint/adjointBoundaryConditions/adjointRotatingWallVelocity/adjointRotatingWallVelocityFvPatchVectorField.C @@ -39,7 +39,7 @@ adjointRotatingWallVelocityFvPatchVectorField ) : adjointWallVelocityFvPatchVectorField(p, iF), - origin_(), + origin_(Zero), axis_(Zero), omega_(nullptr) {} diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.C b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.C index b315d85985..7324bfc065 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.C +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOSolidVolume/objectiveTopOSolidVolume.C @@ -71,17 +71,17 @@ objectiveTopOSolidVolume::objectiveTopOSolidVolume // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - scalar objectiveTopOSolidVolume::J() { J_ = Zero; - if (mesh_.foundObject("beta")) + + if (const auto* betap = mesh_.cfindObject("beta")) { - const volScalarField& beta = mesh_.lookupObject("beta"); - const DimensionedField& V = mesh_.V(); + const auto& beta = *betap; const scalar time = mesh_.time().timeOutputValue(); + J_ = - gSum(beta.primitiveField()*V)/gSum(V) + gWeightedAverage(mesh_.V(), beta.primitiveField()) - targetPercentage_->value(time); if (percentInDenom_) { @@ -101,6 +101,7 @@ scalar objectiveTopOSolidVolume::J() void objectiveTopOSolidVolume::update_dJdb() { const scalar time = mesh_.time().timeOutputValue(); + dJdbPtr_().primitiveFieldRef() = scalar(1)/gSum(mesh_.V()); if (percentInDenom_) { diff --git a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.C b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.C index d15b68e3df..9d9b4f5da8 100644 --- a/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.C +++ b/src/optimisation/adjointOptimisation/adjoint/objectives/geometric/objectiveTopOVolume/objectiveTopOVolume.C @@ -71,17 +71,17 @@ objectiveTopOVolume::objectiveTopOVolume // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - scalar objectiveTopOVolume::J() { J_ = Zero; - if (mesh_.foundObject("beta")) + + if (const auto* betap = mesh_.cfindObject("beta")) { - const volScalarField& beta = mesh_.lookupObject("beta"); - const DimensionedField& V = mesh_.V(); + const auto& beta = *betap; const scalar time = mesh_.time().timeOutputValue(); + J_ = - scalar(1) - gSum(beta.primitiveField()*V)/gSum(V) + scalar(1) - gWeightedAverage(mesh_.V(), beta.primitiveField()) - targetPercentage_->value(time); if (percentInDenom_) { @@ -101,6 +101,7 @@ scalar objectiveTopOVolume::J() void objectiveTopOVolume::update_dJdb() { const scalar time = mesh_.time().timeOutputValue(); + dJdbPtr_().primitiveFieldRef() = -scalar(1)/gSum(mesh_.V()); if (percentInDenom_) { diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/betaMax/betaMax/betaMax.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/betaMax/betaMax/betaMax.C index 99a1c78eb3..d26f95171d 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/betaMax/betaMax/betaMax.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/betaMax/betaMax/betaMax.C @@ -62,8 +62,9 @@ Foam::scalar Foam::betaMax::computeLength(const dictionary& dict) const for (const label pI : inletPatches) { const fvPatch& patch = mesh_.boundary()[pI]; - length += gSum(patch.magSf()); + length += sum(patch.magSf()); } + reduce(length, sumOp()); // Divide with the span in the empty direction const Vector