diff --git a/applications/solvers/combustion/XiFoam/bEqn.H b/applications/solvers/combustion/XiFoam/bEqn.H index fda39d3f51..91d211ae2a 100644 --- a/applications/solvers/combustion/XiFoam/bEqn.H +++ b/applications/solvers/combustion/XiFoam/bEqn.H @@ -171,10 +171,7 @@ if (ign.ignited()) fvOptions.correct(Su); - // Limit the maximum Su - // ~~~~~~~~~~~~~~~~~~~~ - Su.min(SuMax); - Su.max(SuMin); + Su.clamp_range(SuMin, SuMax); } else { @@ -218,7 +215,7 @@ if (ign.ignited()) + ( scalar(1) + (2*XiShapeCoef) - *(scalar(0.5) - min(max(b, scalar(0)), scalar(1))) + *(scalar(0.5) - clamp(b, zero_one{})) )*(XiEqStar - scalar(1.001)) ); diff --git a/applications/solvers/combustion/fireFoam/YEEqn.H b/applications/solvers/combustion/fireFoam/YEEqn.H index 5176956acc..adc849bc2d 100644 --- a/applications/solvers/combustion/fireFoam/YEEqn.H +++ b/applications/solvers/combustion/fireFoam/YEEqn.H @@ -39,13 +39,13 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); radiation->correct(); diff --git a/applications/solvers/combustion/reactingFoam/YEqn.H b/applications/solvers/combustion/reactingFoam/YEqn.H index 4d209a3d81..ea8681628a 100644 --- a/applications/solvers/combustion/reactingFoam/YEqn.H +++ b/applications/solvers/combustion/reactingFoam/YEqn.H @@ -38,11 +38,11 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/YEqn.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/YEqn.H index c32c1fdab2..b42c7986ab 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/YEqn.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/YEqn.H @@ -48,7 +48,7 @@ if (Y.size()) fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } @@ -56,6 +56,6 @@ if (Y.size()) if (Y.size()) { Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } } diff --git a/applications/solvers/lagrangian/coalChemistryFoam/YEqn.H b/applications/solvers/lagrangian/coalChemistryFoam/YEqn.H index 49e3f70d89..f3cbb702a7 100644 --- a/applications/solvers/lagrangian/coalChemistryFoam/YEqn.H +++ b/applications/solvers/lagrangian/coalChemistryFoam/YEqn.H @@ -40,11 +40,11 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } diff --git a/applications/solvers/lagrangian/reactingParcelFoam/YEqn.H b/applications/solvers/lagrangian/reactingParcelFoam/YEqn.H index c7f9dbce34..ecbf120887 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/YEqn.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/YEqn.H @@ -41,11 +41,11 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } diff --git a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/YEqn.H b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/YEqn.H index 1510f8e391..db2d6c9b9c 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/YEqn.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/YEqn.H @@ -38,11 +38,11 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } diff --git a/applications/solvers/lagrangian/simpleCoalParcelFoam/YEqn.H b/applications/solvers/lagrangian/simpleCoalParcelFoam/YEqn.H index c81ac66c8b..a6f70bf4f2 100644 --- a/applications/solvers/lagrangian/simpleCoalParcelFoam/YEqn.H +++ b/applications/solvers/lagrangian/simpleCoalParcelFoam/YEqn.H @@ -38,11 +38,11 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } diff --git a/applications/solvers/lagrangian/sprayFoam/YEqn.H b/applications/solvers/lagrangian/sprayFoam/YEqn.H index 60a27fec85..e80f884202 100644 --- a/applications/solvers/lagrangian/sprayFoam/YEqn.H +++ b/applications/solvers/lagrangian/sprayFoam/YEqn.H @@ -39,11 +39,11 @@ tmp> mvConvection fvOptions.correct(Yi); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } } Y[inertIndex] = scalar(1) - Yt; - Y[inertIndex].max(0.0); + Y[inertIndex].clamp_min(0); } diff --git a/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H b/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H index ed799ae4b4..51f3eecd20 100644 --- a/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H +++ b/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H @@ -1,14 +1,5 @@ { - alphav = - max - ( - min - ( - (rho - rholSat)/(rhovSat - rholSat), - scalar(1) - ), - scalar(0) - ); + alphav = clamp((rho - rholSat)/(rhovSat - rholSat), zero_one{}); alphal = 1.0 - alphav; Info<< "max-min alphav: " << max(alphav).value() diff --git a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/constant/constant.C b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/constant/constant.C index 36342d9393..78400b60ff 100644 --- a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/constant/constant.C +++ b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/constant/constant.C @@ -99,17 +99,6 @@ Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::mDotAlphal() const Foam::Pair> Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::mDot() const { - - volScalarField limitedAlpha1 - ( - min(max(mixture_.alpha1(), scalar(0)), scalar(1)) - ); - - volScalarField limitedAlpha2 - ( - min(max(mixture_.alpha2(), scalar(0)), scalar(1)) - ); - const volScalarField& T = mesh_.lookupObject("T"); const twoPhaseMixtureEThermo& thermo = @@ -124,11 +113,15 @@ Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::mDot() const volScalarField mDotE ( - "mDotE", coeffE_*mixture_.rho1()*limitedAlpha1*max(T - TSat, T0) + "mDotE", + coeffE_*mixture_.rho1()*clamp(mixture_.alpha1(), zero_one{}) + * max(T - TSat, T0) ); volScalarField mDotC ( - "mDotC", coeffC_*mixture_.rho2()*limitedAlpha2*max(TSat - T, T0) + "mDotC", + coeffC_*mixture_.rho2()*clamp(mixture_.alpha2(), zero_one{}) + * max(TSat - T, T0) ); if (mesh_.time().outputTime()) @@ -148,16 +141,6 @@ Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::mDot() const Foam::Pair> Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::mDotDeltaT() const { - volScalarField limitedAlpha1 - ( - min(max(mixture_.alpha1(), scalar(0)), scalar(1)) - ); - - volScalarField limitedAlpha2 - ( - min(max(mixture_.alpha2(), scalar(0)), scalar(1)) - ); - const volScalarField& T = mesh_.lookupObject("T"); const twoPhaseMixtureEThermo& thermo = @@ -170,8 +153,14 @@ Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::mDotDeltaT() const return Pair> ( - coeffC_*mixture_.rho2()*limitedAlpha2*pos(TSat - T), - coeffE_*mixture_.rho1()*limitedAlpha1*pos(T - TSat) + ( + coeffC_*mixture_.rho2()*clamp(mixture_.alpha2(), zero_one{}) + * pos(TSat - T) + ), + ( + coeffE_*mixture_.rho1()*clamp(mixture_.alpha1(), zero_one{}) + * pos(T - TSat) + ) ); } @@ -201,25 +190,17 @@ Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::TSource() const const dimensionedScalar& TSat = thermo.TSat(); - dimensionedScalar L = mixture_.Hf2() - mixture_.Hf1(); - - volScalarField limitedAlpha1 - ( - min(max(mixture_.alpha1(), scalar(0)), scalar(1)) - ); - - volScalarField limitedAlpha2 - ( - min(max(mixture_.alpha2(), scalar(0)), scalar(1)) - ); + const dimensionedScalar L = mixture_.Hf2() - mixture_.Hf1(); const volScalarField Vcoeff ( - coeffE_*mixture_.rho1()*limitedAlpha1*L*pos(T - TSat) + coeffE_*mixture_.rho1()*clamp(mixture_.alpha1(), zero_one{}) + * L*pos(T - TSat) ); const volScalarField Ccoeff ( - coeffC_*mixture_.rho2()*limitedAlpha2*L*pos(TSat - T) + coeffC_*mixture_.rho2()*clamp(mixture_.alpha2(), zero_one{}) + * L*pos(TSat - T) ); TSource = diff --git a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/interfaceHeatResistance/interfaceHeatResistance.C b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/interfaceHeatResistance/interfaceHeatResistance.C index 3961c127bd..f59700f556 100644 --- a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/interfaceHeatResistance/interfaceHeatResistance.C +++ b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/interfaceHeatResistance/interfaceHeatResistance.C @@ -167,20 +167,10 @@ Foam::Pair> Foam::temperaturePhaseChangeTwoPhaseMixtures::interfaceHeatResistance:: mDotAlphal() const { - volScalarField limitedAlpha1 - ( - min(max(mixture_.alpha1(), scalar(0)), scalar(1)) - ); - - volScalarField limitedAlpha2 - ( - min(max(mixture_.alpha2(), scalar(0)), scalar(1)) - ); - return Pair> ( - (mDotc_/(limitedAlpha2 + SMALL)), - -(mDote_/(limitedAlpha1 + SMALL)) + (mDotc_/clamp(mixture_.alpha2(), scalarMinMax(SMALL, 1))), + -(mDote_/clamp(mixture_.alpha1(), scalarMinMax(SMALL, 1))) ); } diff --git a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.C b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.C index 26b975263e..0cf652dbf5 100644 --- a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.C +++ b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.C @@ -155,7 +155,7 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::Cp() const { const volScalarField limitedAlpha1 ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_, zero_one{}) ); return tmp @@ -176,13 +176,11 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::Cp const label patchi ) const { - const volScalarField limitedAlpha1 + const scalarField alpha1p ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_.boundaryField()[patchi], zero_one{}) ); - const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi]; - return ( alpha1p*Cp1().value() + (scalar(1) - alpha1p)*Cp2().value() @@ -194,7 +192,7 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::rho() const { const volScalarField limitedAlpha1 ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_, zero_one{}) ); return tmp @@ -214,13 +212,11 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::rho const label patchi ) const { - const volScalarField limitedAlpha1 + const scalarField alpha1p ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_.boundaryField()[patchi], zero_one{}) ); - const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi]; - return ( alpha1p*rho1().value() + (scalar(1) - alpha1p)*rho2().value() @@ -232,7 +228,7 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::Cv() const { const volScalarField limitedAlpha1 ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_, zero_one{}) ); return tmp @@ -253,13 +249,11 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::Cv const label patchi ) const { - const volScalarField limitedAlpha1 + const scalarField alpha1p ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_.boundaryField()[patchi], zero_one{}) ); - const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi]; - return ( alpha1p*Cv1().value() + (scalar(1) - alpha1p)*Cv2().value() @@ -339,7 +333,7 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::kappa() const { const volScalarField limitedAlpha1 ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_, zero_one{}) ); return tmp @@ -358,13 +352,11 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::kappa const label patchi ) const { - const volScalarField limitedAlpha1 + const scalarField alpha1p ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_.boundaryField()[patchi], zero_one{}) ); - const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi]; - return (alpha1p*kappa1().value() + (1 - alpha1p)*kappa2().value()); } @@ -402,13 +394,11 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::kappaEff const label patchi ) const { - const volScalarField limitedAlpha1 + const scalarField alpha1p ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_.boundaryField()[patchi], zero_one{}) ); - const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi]; - return (alpha1p*kappa1().value() + (1 - alpha1p)*kappa2().value()) + kappat; @@ -435,13 +425,11 @@ Foam::tmp Foam::twoPhaseMixtureEThermo::alphaEff const label patchi ) const { - const volScalarField limitedAlpha1 + const scalarField alpha1p ( - min(max(alpha1_, scalar(0)), scalar(1)) + clamp(alpha1_.boundaryField()[patchi], zero_one{}) ); - const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi]; - const scalarField rho ( alpha1p*rho1().value() + (1.0 - alpha1p)*rho2().value() diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.C b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.C index ce32f5a5ea..ad6fe801d9 100644 --- a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.C +++ b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.C @@ -70,7 +70,7 @@ Foam::Pair> Foam::phaseChangeTwoPhaseMixtures::Kunz::mDotAlphal() const { const volScalarField& p = alpha1_.db().lookupObject("p"); - volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1))); + volScalarField limitedAlpha1(clamp(alpha1_, zero_one{})); return Pair> ( @@ -85,7 +85,7 @@ Foam::Pair> Foam::phaseChangeTwoPhaseMixtures::Kunz::mDotP() const { const volScalarField& p = alpha1_.db().lookupObject("p"); - volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1))); + volScalarField limitedAlpha1(clamp(alpha1_, zero_one{})); return Pair> ( diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Merkle/Merkle.C b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Merkle/Merkle.C index ff323e83bb..75d5964db6 100644 --- a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Merkle/Merkle.C +++ b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Merkle/Merkle.C @@ -82,7 +82,7 @@ Foam::Pair> Foam::phaseChangeTwoPhaseMixtures::Merkle::mDotP() const { const volScalarField& p = alpha1_.db().lookupObject("p"); - volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1))); + volScalarField limitedAlpha1(clamp(alpha1_, zero_one{})); return Pair> ( diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C index b1e1d3e7a0..c65d51185b 100644 --- a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C +++ b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C @@ -99,7 +99,7 @@ Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::pCoeff const volScalarField& p ) const { - volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1))); + volScalarField limitedAlpha1(clamp(alpha1_, zero_one{})); volScalarField rho ( limitedAlpha1*rho1() + (scalar(1) - limitedAlpha1)*rho2() @@ -117,7 +117,7 @@ Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::mDotAlphal() const const volScalarField& p = alpha1_.db().lookupObject("p"); volScalarField pCoeff(this->pCoeff(p)); - volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1))); + volScalarField limitedAlpha1(clamp(alpha1_, zero_one{})); return Pair> ( @@ -134,7 +134,7 @@ Foam::phaseChangeTwoPhaseMixtures::SchnerrSauer::mDotP() const const volScalarField& p = alpha1_.db().lookupObject("p"); volScalarField pCoeff(this->pCoeff(p)); - volScalarField limitedAlpha1(min(max(alpha1_, scalar(0)), scalar(1))); + volScalarField limitedAlpha1(clamp(alpha1_, zero_one{})); volScalarField apCoeff(limitedAlpha1*pCoeff); return Pair> diff --git a/applications/test/minMax2/Test-minMax2.C b/applications/test/minMax2/Test-minMax2.C index 201b0548d6..136681d75c 100644 --- a/applications/test/minMax2/Test-minMax2.C +++ b/applications/test/minMax2/Test-minMax2.C @@ -152,19 +152,26 @@ int main(int argc, char *argv[]) Info<< nl << "field: " << flatOutput(someField) << nl; Info<< "clamp01: " - << flatOutput(clamp(someField, scalarMinMax(zero_one{}))()) << nl; + << flatOutput(clamp(someField, zero_one{})()) << nl; Info<< "clamp01: " - << clamp(tmp(someField), scalarMinMax(zero_one{}))<< nl; + << clamp(tmp(someField), zero_one{})<< nl; scalarField result(10); - clamp(result, someField, scalarMinMax(zero_one{})); + clamp(result, someField, zero_one{}); Info<< "result: " << result << nl; - someField.clamp(zero_one{}); - + someField.clamp_range(zero_one{}); Info<< "inplace: " << someField << nl; + + scalar val(1.414); + + Info<< "clamp " << val + // nope << " : " << clamp(val, zero_one{}) + // nope << " : " << clamp(val, scalarMinMax(zero_one{})) + << " : " << clamp(val, 0, 1) + << nl; } Info<< nl << "\nDone\n" << endl; diff --git a/applications/test/speed/vectorSpeed/Test-vectorSpeed.C b/applications/test/speed/vectorSpeed/Test-vectorSpeed.C index 2ab430d34a..0acdc5d84c 100644 --- a/applications/test/speed/vectorSpeed/Test-vectorSpeed.C +++ b/applications/test/speed/vectorSpeed/Test-vectorSpeed.C @@ -1,3 +1,38 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Application + Test-vectorSpeed + +Description + Test speeds, usability of some field operations + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" #include "primitiveFields.H" #include "cpuTime.H" #include "IOstreams.H" @@ -5,12 +40,22 @@ using namespace Foam; -int main() -{ - const label nIter = 100; - const label size = 1000000; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - Info<< "Initialising fields" << endl; +int main(int argc, char *argv[]) +{ + argList::noParallel(); + argList::addBoolOption("lerp"); + + argList args(argc, argv); + + const label nIter = 1000; + const label size = (1000000); + + Info<< "Initialising fields. size:" << size + << " max:" << labelMax << endl; + + scalarField onet(size); vectorField vf1(size, vector::one), @@ -18,11 +63,14 @@ int main() vf3(size, vector::one), vf4(size); - Info<< "Done\n" << endl; + Info<< "Start loop: " << nIter << endl; + cpuTime timing; + + // Timing is mostly malloc anyhow... + + if (!args.found("lerp")) { - cpuTime executionTime; - Info<< "vectorField algebra" << endl; for (int j=0; j= 1e-14)) { diff --git a/applications/utilities/preProcessing/setTurbulenceFields/setTurbulenceFields.C b/applications/utilities/preProcessing/setTurbulenceFields/setTurbulenceFields.C index 06481f514a..71d945503a 100644 --- a/applications/utilities/preProcessing/setTurbulenceFields/setTurbulenceFields.C +++ b/applications/utilities/preProcessing/setTurbulenceFields/setTurbulenceFields.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -241,13 +241,7 @@ void calcF solve(fEqn); // (M:p. 2) - const dimensioned fMinMax - ( - dimless, - scalarMinMax(Zero, scalar(1) - Foam::exp(-scalar(400)/scalar(50))) - ); - - f.clip(fMinMax); + f.clamp_range(0, scalar(1) - Foam::exp(-scalar(400)/scalar(50))); } diff --git a/etc/codeTemplates/BC/BC.C b/etc/codeTemplates/BC/BC.C index 7c1bb0e8d6..7dc8098b37 100644 --- a/etc/codeTemplates/BC/BC.C +++ b/etc/codeTemplates/BC/BC.C @@ -207,7 +207,7 @@ void Foam::CLASS::updateCoeffs() const scalarField& phip = this->patch().template lookupPatchField("phi"); - this->valueFraction() = 1.0 - pos0(phip); + this->valueFraction() = neg(phip); PARENT::updateCoeffs(); } diff --git a/src/ODE/ODESolvers/adaptiveSolver/adaptiveSolver.C b/src/ODE/ODESolvers/adaptiveSolver/adaptiveSolver.C index 126b0cbc1e..04be67825b 100644 --- a/src/ODE/ODESolvers/adaptiveSolver/adaptiveSolver.C +++ b/src/ODE/ODESolvers/adaptiveSolver/adaptiveSolver.C @@ -101,7 +101,7 @@ void Foam::adaptiveSolver::solve if (err > pow(maxScale_/safeScale_, -1.0/alphaInc_)) { dxTry = - min(max(safeScale_*pow(err, -alphaInc_), minScale_), maxScale_)*dx; + clamp(safeScale_*pow(err, -alphaInc_), minScale_, maxScale_)*dx; } else { diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C index 487c655226..621b49200f 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,32 +36,27 @@ License namespace Foam { -// * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template tmp::type, GeoMesh>> pow ( - const DimensionedField& df, + const DimensionedField& f1, typename powProduct::type ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; auto tres = - tmp>::New + reuseTmpDimensionedField::New ( - IOobject - ( - "pow(" + df.name() + ',' + name(r) + ')', - df.instance(), - df.db() - ), - df.mesh(), - pow(df.dimensions(), r) + f1, + "pow(" + f1.name() + ',' + Foam::name(r) + ')', + pow(f1.dimensions(), r) ); - pow(tres.ref().field(), df.field()); + pow(tres.ref().field(), f1.field()); return tres; } @@ -71,166 +66,151 @@ template tmp::type, GeoMesh>> pow ( - const tmp>& tdf, + const tmp>& tf1, typename powProduct::type ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; - const DimensionedField& df = tdf(); + const auto& f1 = tf1(); auto tres = - reuseTmpDimensionedField::New + reuseTmpDimensionedField::New ( - tdf, - "pow(" + df.name() + ',' + name(r) + ')', - pow(df.dimensions(), r) + tf1, + "pow(" + f1.name() + ',' + Foam::name(r) + ')', + pow(f1.dimensions(), r) ); - pow(tres.ref().field(), df.field()); + pow(tres.ref().field(), f1.field()); - tdf.clear(); + tf1.clear(); return tres; } template tmp::type, GeoMesh>> -sqr(const DimensionedField& df) +sqr(const DimensionedField& f1) { - typedef typename outerProduct::type outerProductType; + typedef typename outerProduct::type resultType; auto tres = - tmp>::New + reuseTmpDimensionedField::New ( - IOobject - ( - "sqr(" + df.name() + ')', - df.instance(), - df.db() - ), - df.mesh(), - sqr(df.dimensions()) + f1, + "sqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - sqr(tres.ref().field(), df.field()); + sqr(tres.ref().field(), f1.field()); return tres; } template tmp::type, GeoMesh>> -sqr(const tmp>& tdf) +sqr(const tmp>& tf1) { - typedef typename outerProduct::type outerProductType; + typedef typename outerProduct::type resultType; - const DimensionedField& df = tdf(); + const auto& f1 = tf1(); auto tres = - reuseTmpDimensionedField::New + reuseTmpDimensionedField::New ( - tdf, - "sqr(" + df.name() + ')', - sqr(df.dimensions()) + tf1, + "sqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - sqr(tres.ref().field(), df.field()); + sqr(tres.ref().field(), f1.field()); - tdf.clear(); + tf1.clear(); return tres; } template tmp::type, GeoMesh>> -magSqr(const DimensionedField& df) +magSqr(const DimensionedField& f1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; auto tres = - tmp>::New + reuseTmpDimensionedField::New ( - IOobject - ( - "magSqr(" + df.name() + ')', - df.instance(), - df.db() - ), - df.mesh(), - sqr(df.dimensions()) + f1, + "magSqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - magSqr(tres.ref().field(), df.field()); + magSqr(tres.ref().field(), f1.field()); return tres; } template tmp::type, GeoMesh>> -magSqr(const tmp>& tdf) +magSqr(const tmp>& tf1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - const DimensionedField& df = tdf(); + const auto& f1 = tf1(); auto tres = - reuseTmpDimensionedField::New + reuseTmpDimensionedField::New ( - tdf, - "magSqr(" + df.name() + ')', - sqr(df.dimensions()) + tf1, + "magSqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - magSqr(tres.ref().field(), df.field()); + magSqr(tres.ref().field(), f1.field()); - tdf.clear(); + tf1.clear(); return tres; } template tmp::type, GeoMesh>> -mag(const DimensionedField& df) +mag(const DimensionedField& f1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; auto tres = - tmp>::New + reuseTmpDimensionedField::New ( - IOobject - ( - "mag(" + df.name() + ')', - df.instance(), - df.db() - ), - df.mesh(), - df.dimensions() + f1, + "mag(" + f1.name() + ')', + f1.dimensions() ); - mag(tres.ref().field(), df.field()); + mag(tres.ref().field(), f1.field()); return tres; } template tmp::type, GeoMesh>> -mag(const tmp>& tdf) +mag(const tmp>& tf1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - const DimensionedField& df = tdf(); + const auto& f1 = tf1(); auto tres = - reuseTmpDimensionedField::New + reuseTmpDimensionedField::New ( - tdf, - "mag(" + df.name() + ')', - df.dimensions() + tf1, + "mag(" + f1.name() + ')', + f1.dimensions() ); - mag(tres.ref().field(), df.field()); + mag(tres.ref().field(), f1.field()); - tdf.clear(); + tf1.clear(); return tres; } @@ -243,24 +223,19 @@ tmp typename DimensionedField::cmptType, GeoMesh > > -cmptAv(const DimensionedField& df) +cmptAv(const DimensionedField& f1) { - typedef typename DimensionedField::cmptType cmptType; + typedef typename DimensionedField::cmptType resultType; auto tres = - tmp>::New + reuseTmpDimensionedField::New ( - IOobject - ( - "cmptAv(" + df.name() + ')', - df.instance(), - df.db() - ), - df.mesh(), - df.dimensions() + f1, + "cmptAv(" + f1.name() + ')', + f1.dimensions() ); - cmptAv(tres.ref().field(), df.field()); + cmptAv(tres.ref().field(), f1.field()); return tres; } @@ -274,51 +249,51 @@ tmp typename DimensionedField::cmptType, GeoMesh > > -cmptAv(const tmp>& tdf) +cmptAv(const tmp>& tf1) { - typedef typename DimensionedField::cmptType cmptType; + typedef typename DimensionedField::cmptType resultType; - const DimensionedField& df = tdf(); + const auto& f1 = tf1(); auto tres = - reuseTmpDimensionedField::New + reuseTmpDimensionedField::New ( - tdf, - "cmptAv(" + df.name() + ')', - df.dimensions() + tf1, + "cmptAv(" + f1.name() + ')', + f1.dimensions() ); - cmptAv(tres.ref().field(), df.field()); + cmptAv(tres.ref().field(), f1.field()); - tdf.clear(); + tf1.clear(); return tres; } -#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \ +#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \ \ template \ -dimensioned func \ +dimensioned Func \ ( \ - const DimensionedField& df \ + const DimensionedField& f1 \ ) \ { \ - return dimensioned \ + return dimensioned \ ( \ - #func "(" + df.name() + ')', \ - df.dimensions(), \ - dfunc(df.field()) \ + #Func "(" + f1.name() + ')', \ + f1.dimensions(), \ + gFunc(f1.field()) \ ); \ } \ \ template \ -dimensioned func \ +dimensioned Func \ ( \ - const tmp>& tdf1 \ + const tmp>& tf1 \ ) \ { \ - dimensioned res = func(tdf1()); \ - tdf1.clear(); \ + dimensioned res = Func(tf1()); \ + tf1.clear(); \ return res; \ } @@ -344,10 +319,81 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) -BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clip) + +// ------------------------------------------------------------------------- // + +// Clamp Methods + +template +void clamp +( + DimensionedField& result, + const DimensionedField& f1, + const Foam::zero_one +) +{ + const MinMax range(Foam::zero_one{}); + + clamp(result.field(), f1.field(), range); + result.oriented() = f1.oriented(); +} + +template +tmp> +clamp +( + const DimensionedField& f1, + const Foam::zero_one +) +{ + auto tres = + reuseTmpDimensionedField::New + ( + f1, + "clamp01(" + f1.name() + ')', + f1.dimensions() + ); + + clamp(tres.ref(), f1, Foam::zero_one{}); + + return tres; +} -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +template +tmp> +clamp +( + const tmp>& tf1, + const Foam::zero_one +) +{ + const auto& f1 = tf1(); + + auto tres = + reuseTmpDimensionedField::New + ( + tf1, + "clamp01(" + f1.name() + ')', + f1.dimensions() + ); + + clamp(tres.field(), f1, Foam::zero_one{}); + + tf1.clear(); + return tres; +} + +BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -363,32 +409,27 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define PRODUCT_OPERATOR(product, op, opFunc) \ +#define PRODUCT_OPERATOR(product, Op, OpFunc) \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ - const DimensionedField& df2 \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - '(' + df1.name() + #op + df2.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - df1.dimensions() op df2.dimensions() \ + f1, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), df1.field(), df2.field()); \ + Foam::OpFunc(tres.ref().field(), f1.field(), f2.field()); \ \ return tres; \ } \ @@ -396,113 +437,108 @@ operator op \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ - const tmp>& tdf2 \ + const DimensionedField& f1, \ + const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const DimensionedField& df2 = tdf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ - reuseTmpDimensionedField::New \ + reuseTmpDimensionedField::New \ ( \ - tdf2, \ - '(' + df1.name() + #op + df2.name() + ')', \ - df1.dimensions() op df2.dimensions() \ + tf2, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), df1.field(), df2.field()); \ + Foam::OpFunc(tres.ref().field(), f1.field(), f2.field()); \ \ - tdf2.clear(); \ + tf2.clear(); \ return tres; \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ - const DimensionedField& df2 \ + const tmp>& tf1, \ + const DimensionedField& f2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ - reuseTmpDimensionedField::New \ + reuseTmpDimensionedField::New \ ( \ - tdf1, \ - '(' + df1.name() + #op + df2.name() + ')', \ - df1.dimensions() op df2.dimensions() \ + tf1, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), df1.field(), df2.field()); \ + Foam::OpFunc(tres.ref().field(), f1.field(), f2.field()); \ \ - tdf1.clear(); \ + tf1.clear(); \ return tres; \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const DimensionedField& df1 = tdf1(); \ - const DimensionedField& df2 = tdf2(); \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpTmpDimensionedField \ - ::New \ + ::New \ ( \ - tdf1, \ - tdf2, \ - '(' + df1.name() + #op + df2.name() + ')', \ - df1.dimensions() op df2.dimensions() \ + tf1, \ + tf2, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), df1.field(), df2.field()); \ + Foam::OpFunc(tres.ref().field(), f1.field(), f2.field()); \ \ - tdf1.clear(); \ - tdf2.clear(); \ + tf1.clear(); \ + tf2.clear(); \ return tres; \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ + const DimensionedField& f1, \ const dimensioned
& dvs \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - '(' + df1.name() + #op + dvs.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - df1.dimensions() op dvs.dimensions() \ + f1, \ + '(' + f1.name() + #Op + dvs.name() + ')', \ + (f1.dimensions() Op dvs.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), df1.field(), dvs.value()); \ + Foam::OpFunc(tres.ref().field(), f1.field(), dvs.value()); \ \ return tres; \ } \ @@ -510,79 +546,74 @@ operator op \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ + const DimensionedField& f1, \ const VectorSpace& vs \ ) \ { \ - return df1 op dimensioned(static_cast(vs)); \ + return f1 Op dimensioned(static_cast(vs)); \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ + const tmp>& tf1, \ const dimensioned& dvs \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ - reuseTmpDimensionedField::New \ + reuseTmpDimensionedField::New \ ( \ - tdf1, \ - '(' + df1.name() + #op + dvs.name() + ')', \ - df1.dimensions() op dvs.dimensions() \ + tf1, \ + '(' + f1.name() + #Op + dvs.name() + ')', \ + (f1.dimensions() Op dvs.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), df1.field(), dvs.value()); \ + Foam::OpFunc(tres.ref().field(), f1.field(), dvs.value()); \ \ - tdf1.clear(); \ + tf1.clear(); \ return tres; \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ + const tmp>& tf1, \ const VectorSpace& vs \ ) \ { \ - return tdf1 op dimensioned(static_cast(vs)); \ + return tf1 Op dimensioned(static_cast(vs)); \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const DimensionedField& df1 \ + const DimensionedField& f2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - '(' + dvs.name() + #op + df1.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - dvs.dimensions() op df1.dimensions() \ + f2, \ + '(' + dvs.name() + #Op + f2.name() + ')', \ + (dvs.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), dvs.value(), df1.field()); \ + Foam::OpFunc(tres.ref().field(), dvs.value(), f2.field()); \ \ return tres; \ } \ @@ -590,52 +621,52 @@ operator op \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const DimensionedField& df1 \ + const DimensionedField& f2 \ ) \ { \ - return dimensioned(static_cast(vs)) op df1; \ + return dimensioned(static_cast(vs)) Op f2; \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const tmp>& tdf1 \ + const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const DimensionedField& df1 = tdf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ - reuseTmpDimensionedField::New \ + reuseTmpDimensionedField::New \ ( \ - tdf1, \ - '(' + dvs.name() + #op + df1.name() + ')', \ - dvs.dimensions() op df1.dimensions() \ + tf2, \ + '(' + dvs.name() + #Op + f2.name() + ')', \ + (dvs.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref().field(), dvs.value(), df1.field()); \ + Foam::OpFunc(tres.ref().field(), dvs.value(), f2.field()); \ \ - tdf1.clear(); \ + tf2.clear(); \ return tres; \ } \ \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const tmp>& tdf1 \ + const tmp>& tf2 \ ) \ { \ - return dimensioned(static_cast(vs)) op tdf1; \ + return dimensioned(static_cast(vs)) Op tf2; \ } diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H index 81a625342f..e444690399 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,13 +36,13 @@ License namespace Foam { -// * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template tmp::type, GeoMesh>> pow ( - const DimensionedField& df, + const DimensionedField& f1, typename powProduct::type ); @@ -50,33 +50,33 @@ template tmp::type, GeoMesh>> pow ( - const tmp>& tdf, + const tmp>& tf1, typename powProduct::type ); template tmp::type, GeoMesh>> -sqr(const DimensionedField& df); +sqr(const DimensionedField& f1); template tmp::type, GeoMesh>> -sqr(const tmp>& tdf); +sqr(const tmp>& tf1); template tmp::type, GeoMesh>> -magSqr(const DimensionedField& df); +magSqr(const DimensionedField& f1); template tmp::type, GeoMesh>> -magSqr(const tmp>& tdf); +magSqr(const tmp>& tf1); template tmp::type, GeoMesh>> -mag(const DimensionedField& df); +mag(const DimensionedField& f1); template tmp::type, GeoMesh>> -mag(const tmp>& tdf); +mag(const tmp>& tf1); template tmp @@ -87,7 +87,7 @@ tmp GeoMesh > > -cmptAv(const DimensionedField& df); +cmptAv(const DimensionedField& f1); template tmp @@ -98,21 +98,21 @@ tmp GeoMesh > > -cmptAv(const tmp>& tdf); +cmptAv(const tmp>& tf1); -// Forward to FieldFunction via dfunc() -#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \ +// Forward to FieldFunction via gFunc() +#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \ \ template \ -dimensioned func \ +dimensioned Func \ ( \ - const DimensionedField& df \ + const DimensionedField& f1 \ ); \ template \ -dimensioned func \ +dimensioned Func \ ( \ - const tmp>& tdf1 \ + const tmp>& tf1 \ ); UNARY_REDUCTION_FUNCTION(Type, max, gMax) @@ -137,10 +137,45 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) -BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clip) + +// ------------------------------------------------------------------------- // + +// Clamp Methods + +template +void clamp +( + DimensionedField& result, + const DimensionedField& f1, + const Foam::zero_one +); + +template +tmp> +clamp +( + const DimensionedField& f1, + const Foam::zero_one +); + +template +tmp> +clamp +( + const tmp>& tf1, + const Foam::zero_one +); + +BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -156,102 +191,102 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define PRODUCT_OPERATOR(product, op, opFunc) \ +#define PRODUCT_OPERATOR(product, Op, OpFunc) \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ - const DimensionedField& df2 \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ - const tmp>& tdf2 \ + const DimensionedField& f1, \ + const tmp>& tf2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ - const DimensionedField& df2 \ + const tmp>& tf1, \ + const DimensionedField& f2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ + const DimensionedField& f1, \ const dimensioned& dvs \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const DimensionedField& df1, \ + const DimensionedField& f1, \ const VectorSpace& vs \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ + const tmp>& tf1, \ const dimensioned& dvs \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tdf1, \ + const tmp>& tf1, \ const VectorSpace& vs \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const DimensionedField& df1 \ + const DimensionedField& f2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const DimensionedField& df1 \ + const DimensionedField& f2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const tmp>& tdf1 \ + const tmp>& tf2 \ ); \ \ template \ tmp::type, GeoMesh>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const tmp>& tdf1 \ + const tmp>& tf2 \ ); PRODUCT_OPERATOR(typeOfSum, +, add) diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C index 54978f94ac..c748949715 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,27 +33,32 @@ License #define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc) \ \ TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Func(result.field(), f1.field()); \ + result.oriented() = Dfunc(f1.oriented()); \ +} \ + \ +TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1 \ + const DimensionedField& f1 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - #Func "(" + df1.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - Dfunc(df1.dimensions()) \ + f1, \ + #Func "(" + f1.name() + ')', \ + Dfunc(f1.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field()); \ - tres.ref().oriented() = Dfunc(df1.oriented()); \ - \ + Foam::Func(tres.ref(), f1); \ return tres; \ } \ \ @@ -61,23 +66,21 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1 \ + const tmp>& tf1 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf1, \ - #Func "(" + df1.name() + ')', \ - Dfunc(df1.dimensions()) \ + tf1, \ + #Func "(" + f1.name() + ')', \ + Dfunc(f1.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field()); \ - tres.ref().oriented() = Dfunc(df1.oriented()); \ - \ - tdf1.clear(); \ + Foam::Func(tres.ref(), f1); \ + tf1.clear(); \ return tres; \ } @@ -87,27 +90,32 @@ tmp> Func \ #define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc) \ \ TEMPLATE \ +void OpFunc \ +( \ + DimensionedField& result, \ + const DimensionedField& f1 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Foam::OpFunc(result.field(), f1.field()); \ + result.oriented() = Dfunc(f1.oriented()); \ +} \ + \ +TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1 \ + const DimensionedField& f1 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - #Op + df1.name(), \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - Dfunc(df1.dimensions()) \ + f1, \ + #Op + f1.name(), \ + Dfunc(f1.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field()); \ - tres.ref().oriented() = Dfunc(df1.oriented()); \ - \ + Foam::OpFunc(tres.ref(), f1); \ return tres; \ } \ \ @@ -115,23 +123,21 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1 \ + const tmp>& tf1 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf1, \ - #Op + df1.name(), \ - Dfunc(df1.dimensions()) \ + tf1, \ + #Op + f1.name(), \ + Dfunc(f1.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field()); \ - tres.ref().oriented() = Dfunc(df1.oriented()); \ - \ - tdf1.clear(); \ + Foam::OpFunc(tres.ref(), f1); \ + tf1.clear(); \ return tres; \ } @@ -141,28 +147,34 @@ tmp> operator Op \ #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Foam::Func(result.field(), f1.field(), f2.field()); \ + result.oriented() = Func(f1.oriented(), f2.oriented()); \ +} \ + \ +TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1, \ - const DimensionedField& df2 \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - #Func "(" + df1.name() + ',' + df2.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - Func(df1.dimensions(), df2.dimensions()) \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = Func(df1.oriented(), df2.oriented()); \ - \ + Foam::Func(tres.ref(), f1, f2); \ return tres; \ } \ \ @@ -170,24 +182,22 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1, \ - const tmp>& tdf2 \ + const DimensionedField& f1, \ + const tmp>& tf2 \ ) \ { \ - const DimensionedField& df2 = tdf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf2, \ - #Func "(" + df1.name() + ',' + df2.name() + ')', \ - Func(df1.dimensions(), df2.dimensions()) \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = Func(df1.oriented(), df2.oriented()); \ - \ - tdf2.clear(); \ + Foam::Func(tres.ref(), f1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -195,26 +205,22 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const DimensionedField& df2 \ + const tmp>& tf1, \ + const DimensionedField& f2 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ - tmp> tres \ - ( \ + auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf1, \ - #Func "(" + df1.name() + ',' + df2.name() + ')', \ - Func(df1.dimensions(), df2.dimensions()) \ - ) \ - ); \ + tf1, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ \ - Func(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = Func(df1.oriented(), df2.oriented()); \ - \ - tdf1.clear(); \ + Foam::Func(tres.ref(), f1, f2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -222,28 +228,26 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ - const DimensionedField& df2 = tdf2(); \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpTmpDimensionedField \ ::New \ ( \ - tdf1, \ - tdf2, \ - #Func "(" + df1.name() + ',' + df2.name() + ')', \ - Func(df1.dimensions(), df2.dimensions()) \ + tf1, \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = Func(df1.oriented(), df2.oriented()); \ - \ - tdf1.clear(); \ - tdf2.clear(); \ + Foam::Func(tres.ref(), f1, f2); \ + tf1.clear(); \ + tf2.clear(); \ return tres; \ } @@ -253,28 +257,34 @@ tmp> Func \ #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const dimensioned& dt1, \ + const DimensionedField& f2 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Func(result.field(), dt1.value(), f2.field()); \ + result.oriented() = f2.oriented(); \ +} \ + \ +TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ - const DimensionedField& df2 \ + const DimensionedField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - #Func "(" + dt1.name() + ',' + df2.name() + ')', \ - df2.instance(), \ - df2.db() \ - ), \ - df2.mesh(), \ - Func(dt1.dimensions(), df2.dimensions()) \ + f2, \ + #Func "(" + dt1.name() + ',' + f2.name() + ')', \ + Func(dt1.dimensions(), f2.dimensions()) \ ); \ \ - Func(tres.ref().field(), dt1.value(), df2.field()); \ - tres.ref().oriented() = df2.oriented(); \ - \ + Foam::Func(tres.ref(), dt1, f2); \ return tres; \ } \ \ @@ -282,11 +292,11 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const Type1& t1, \ - const DimensionedField& df2 \ + const Type1& s1, \ + const DimensionedField& f2 \ ) \ { \ - return Func(dimensioned(t1), df2); \ + return Foam::Func(dimensioned(s1), f2); \ } \ \ \ @@ -294,63 +304,66 @@ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ - const tmp>& tdf2 \ + const tmp>& tf2 \ ) \ { \ - const DimensionedField& df2 = tdf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf2, \ - #Func "(" + dt1.name() + ',' + df2.name() + ')', \ - Func(dt1.dimensions(), df2.dimensions()) \ + tf2, \ + #Func "(" + dt1.name() + ',' + f2.name() + ')', \ + Func(dt1.dimensions(), f2.dimensions()) \ ); \ \ - Func(tres.ref().field(), dt1.value(), df2.field()); \ - tres.ref().oriented() = df2.oriented(); \ - \ - tdf2.clear(); \ + Foam::Func(tres.ref(), dt1, f2); \ + tf2.clear(); \ return tres; \ } \ \ - \ TEMPLATE \ tmp> Func \ ( \ - const Type1& t1, \ - const tmp>& tdf2 \ + const Type1& s1, \ + const tmp>& tf2 \ ) \ { \ - return Func(dimensioned(t1), tdf2); \ + return Foam::Func(dimensioned(s1), tf2); \ } #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const dimensioned& dt2 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Func(result.field(), f1.field(), dt2.value()); \ + result.oriented() = f1.oriented(); \ +} \ + \ +TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1, \ + const DimensionedField& f1, \ const dimensioned& dt2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - #Func "(" + df1.name() + ',' + dt2.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - Func(df1.dimensions(), dt2.dimensions()) \ + f1, \ + #Func "(" + f1.name() + ',' + dt2.name() + ')', \ + Func(f1.dimensions(), dt2.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field(), dt2.value()); \ - tres.ref().oriented() = df1.oriented(); \ - \ + Foam::Func(tres.ref(), f1, dt2); \ return tres; \ } \ \ @@ -358,35 +371,33 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1, \ - const Type2& t2 \ + const DimensionedField& f1, \ + const Type2& s2 \ ) \ { \ - return Func(df1, dimensioned(t2)); \ + return Foam::Func(f1, dimensioned(s2)); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ + const tmp>& tf1, \ const dimensioned& dt2 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf1, \ - #Func "(" + df1.name() + ',' + dt2.name() + ')', \ - Func(df1.dimensions(), dt2.dimensions()) \ + tf1, \ + #Func "(" + f1.name() + ',' + dt2.name() + ')', \ + Func(f1.dimensions(), dt2.dimensions()) \ ); \ \ - Func(tres.ref().field(), df1.field(), dt2.value()); \ - tres.ref().oriented() = df1.oriented(); \ - \ - tdf1.clear(); \ + Foam::Func(tres.ref(), f1, dt2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -394,11 +405,11 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const Type2& t2 \ + const tmp>& tf1, \ + const Type2& s2 \ ) \ { \ - return Func(tdf1, dimensioned(t2)); \ + return Foam::Func(tf1, dimensioned(s2)); \ } @@ -412,28 +423,35 @@ tmp> Func \ #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ +void OpFunc \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Foam::OpFunc(result.field(), f1.field(), f2.field()); \ + result.oriented() = f1.oriented() Op f2.oriented(); \ +} \ + \ + \ +TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1, \ - const DimensionedField& df2 \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - '(' + df1.name() + OpName + df2.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - df1.dimensions() Op df2.dimensions() \ + f1, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = df1.oriented() Op df2.oriented(); \ - \ + Foam::OpFunc(tres.ref(), f1, f2); \ return tres; \ } \ \ @@ -441,24 +459,22 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1, \ - const tmp>& tdf2 \ + const DimensionedField& f1, \ + const tmp>& tf2 \ ) \ { \ - const DimensionedField& df2 = tdf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf2, \ - '(' + df1.name() + OpName + df2.name() + ')', \ - df1.dimensions() Op df2.dimensions() \ + tf2, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = df1.oriented() Op df2.oriented(); \ - \ - tdf2.clear(); \ + Foam::OpFunc(tres.ref(), f1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -466,53 +482,48 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const DimensionedField& df2 \ + const tmp>& tf1, \ + const DimensionedField& f2 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf1, \ - '(' + df1.name() + OpName + df2.name() + ')', \ - df1.dimensions() Op df2.dimensions() \ + tf1, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = df1.oriented() Op df2.oriented(); \ - \ - tdf1.clear(); \ + Foam::OpFunc(tres.ref(), f1, f2); \ + tf1.clear(); \ return tres; \ } \ \ - \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ - const DimensionedField& df2 = tdf2(); \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpTmpDimensionedField \ ::New \ ( \ - tdf1, \ - tdf2, \ - '(' + df1.name() + OpName + df2.name() + ')', \ - df1.dimensions() Op df2.dimensions() \ + tf1, \ + tf2, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + f1.dimensions() Op f2.dimensions() \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field(), df2.field()); \ - tres.ref().oriented() = df1.oriented() Op df2.oriented(); \ - \ - tdf1.clear(); \ - tdf2.clear(); \ + Foam::OpFunc(tres.ref(), f1, f2); \ + tf1.clear(); \ + tf2.clear(); \ return tres; \ } @@ -522,29 +533,34 @@ tmp> operator Op \ #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ +void OpFunc \ +( \ + DimensionedField& result, \ + const dimensioned& dt1, \ + const DimensionedField& f2 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Foam::OpFunc(result.field(), dt1.value(), f2.field()); \ + result.oriented() = f2.oriented(); \ +} \ + \ +TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ - const DimensionedField& df2 \ + const DimensionedField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - '(' + dt1.name() + OpName + df2.name() + ')', \ - df2.instance(), \ - df2.db() \ - ), \ - df2.mesh(), \ - dt1.dimensions() Op df2.dimensions() \ + f2, \ + '(' + dt1.name() + OpName + f2.name() + ')', \ + (dt1.dimensions() Op f2.dimensions()) \ ); \ \ - tres.ref().oriented() = df2.oriented(); \ - \ - Foam::OpFunc(tres.ref().field(), dt1.value(), df2.field()); \ - \ + Foam::OpFunc(tres.ref(), dt1, f2); \ return tres; \ } \ \ @@ -552,11 +568,11 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& t1, \ - const DimensionedField& df2 \ + const Type1& s1, \ + const DimensionedField& f2 \ ) \ { \ - return dimensioned(t1) Op df2; \ + return dimensioned(s1) Op f2; \ } \ \ \ @@ -564,23 +580,21 @@ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ - const tmp>& tdf2 \ + const tmp>& tf2 \ ) \ { \ - const DimensionedField& df2 = tdf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf2, \ - '(' + dt1.name() + OpName + df2.name() + ')', \ - dt1.dimensions() Op df2.dimensions() \ + tf2, \ + '(' + dt1.name() + OpName + f2.name() + ')', \ + (dt1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), dt1.value(), tdf2().field()); \ - tres.ref().oriented() = df2.oriented(); \ - \ - tdf2.clear(); \ + Foam::OpFunc(tres.ref(), dt1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -588,39 +602,45 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& t1, \ - const tmp>& tdf2 \ + const Type1& s1, \ + const tmp>& tf2 \ ) \ { \ - return dimensioned(t1) Op tdf2; \ + return dimensioned(s1) Op tf2; \ } #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ +void OpFunc \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const dimensioned& dt2 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Foam::OpFunc(result.field(), f1.field(), dt2.value()); \ + result.oriented() = f1.oriented(); \ +} \ + \ +TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1, \ + const DimensionedField& f1, \ const dimensioned& dt2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpDimensionedField::New \ ( \ - IOobject \ - ( \ - '(' + df1.name() + OpName + dt2.name() + ')', \ - df1.instance(), \ - df1.db() \ - ), \ - df1.mesh(), \ - df1.dimensions() Op dt2.dimensions() \ + f1, \ + '(' + f1.name() + OpName + dt2.name() + ')', \ + (f1.dimensions() Op dt2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), df1.field(), dt2.value()); \ - tres.ref().oriented() = df1.oriented(); \ - \ + Foam::OpFunc(tres.ref(), f1, dt2); \ return tres; \ } \ \ @@ -628,35 +648,33 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1, \ - const Type2& t2 \ + const DimensionedField& f1, \ + const Type2& s2 \ ) \ { \ - return df1 Op dimensioned(t2); \ + return f1 Op dimensioned(s2); \ } \ \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ + const tmp>& tf1, \ const dimensioned& dt2 \ ) \ { \ - const DimensionedField& df1 = tdf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpDimensionedField::New \ ( \ - tdf1, \ - '(' + df1.name() + OpName + dt2.name() + ')', \ - df1.dimensions() Op dt2.dimensions() \ + tf1, \ + '(' + f1.name() + OpName + dt2.name() + ')', \ + (f1.dimensions() Op dt2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref().field(), tdf1().field(), dt2.value()); \ - tres.ref().oriented() = df1.oriented(); \ - \ - tdf1.clear(); \ + Foam::OpFunc(tres.ref(), f1, dt2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -664,11 +682,11 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const Type2& t2 \ + const tmp>& tf1, \ + const Type2& s2 \ ) \ { \ - return tdf1 Op dimensioned(t2); \ + return tf1 Op dimensioned(s2); \ } #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ @@ -676,4 +694,378 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const DimensionedField& f3 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Func(result.field(), f1.field(), f2.field(), f3.field()); \ + result.oriented() = Func(f1.oriented(), f2.oriented()); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const DimensionedField& f3 \ +) \ +{ \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const DimensionedField& f3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + tf1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const DimensionedField& f3 \ +) \ +{ \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + tf2, \ + #Func "(" + f1.name() +','+ f2.name() +','+ f3.name() +')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + tf3, \ + #Func "(" + f1.name() +','+ f2.name() +','+ f3.name() +')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf3.clear(); \ + return tres; \ +} \ + \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const DimensionedField& f3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpTmpDimensionedField \ + ::New \ + ( \ + tf1, \ + tf2, \ + #Func "(" + f1.name() +','+ f2.name() +','+ f3.name() +')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpTmpDimensionedField \ + ::New \ + ( \ + tf1, \ + tf3, \ + #Func "(" + f1.name() +','+ f2.name() +','+ f3.name() +')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f2 = tf2(); \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpTmpDimensionedField \ + ::New \ + ( \ + tf2, \ + tf3, \ + #Func "(" + f1.name() +','+ f2.name() +','+ f3.name() +')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ + const auto& f3 = tf3(); \ + \ + /* TBD: check all three types? */ \ + auto tres = \ + reuseTmpTmpDimensionedField \ + ::New \ + ( \ + tf1, \ + tf2, \ + #Func "(" + f1.name() +','+ f2.name() +','+ f3.name() +')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const dimensioned& dt3 \ +) \ +{ \ + /* TBD: reset dimensions? */ \ + Func(result.field(), f1.field(), f2.field(), dt3.value()); \ + result.oriented() = Func(f1.oriented(), f2.oriented()); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const dimensioned& dt3 \ +) \ +{ \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, dt3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const Type3& s3 \ +) \ +{ \ + return Func(f1, f2, dimensioned(s3)); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const dimensioned& dt3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + tf1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, dt3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const Type3& s3 \ +) \ +{ \ + return Func(tf1, f2, dimensioned(s3)); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +) \ +{ \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpDimensionedField::New \ + ( \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, dt3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + return Func(f1, tf2, dimensioned(s3)); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpTmpDimensionedField \ + ::New \ + ( \ + tf1, \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Func(tres.ref(), f1, f2, dt3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + return Func(tf1, tf2, dimensioned(s3)); \ +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H index d7484d1729..7c1d81c6df 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,32 +31,46 @@ License #define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ - const DimensionedField& df \ + DimensionedField& result, \ + const DimensionedField& f1 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1 \ + const DimensionedField& f1 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1 \ ); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define UNARY_OPERATOR(ReturnType, Type1, Op, opFunc, Dfunc) \ +#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ - const DimensionedField& df1 \ + DimensionedField& result, \ + const DimensionedField& f1 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1 \ + const DimensionedField& f1 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1 \ ); @@ -64,31 +79,39 @@ tmp> operator Op \ #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ - const DimensionedField& df1, \ - const DimensionedField& df2 \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1, \ - const tmp>& tdf2 \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const DimensionedField& df2 \ + const DimensionedField& f1, \ + const tmp>& tf2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const DimensionedField& f2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2 \ ); @@ -97,62 +120,78 @@ tmp> Func \ #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ + DimensionedField& result, \ const dimensioned& dt1, \ - const DimensionedField& df2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const Type1& t1, \ - const DimensionedField& df2 \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ - const tmp>& tdf2 \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const Type1& t1, \ - const tmp>& tdf2 \ + const Type1& s1, \ + const DimensionedField& f2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const dimensioned& dt1, \ + const tmp>& tf2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const Type1& s1, \ + const tmp>& tf2 \ ); #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ - const DimensionedField& df1, \ + DimensionedField& result, \ + const DimensionedField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const DimensionedField& df1, \ - const Type2& t2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const tmp>& tdf1, \ + const DimensionedField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf2, \ - const Type2& t2 \ + const DimensionedField& f1, \ + const Type2& s2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const dimensioned& dt2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const Type2& s2 \ ); @@ -166,31 +205,39 @@ tmp> Func \ #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ - const DimensionedField& df1, \ - const DimensionedField& df2 \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1, \ - const tmp>& tdf2 \ + const DimensionedField& f1, \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const DimensionedField& df2 \ + const DimensionedField& f1, \ + const tmp>& tf2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const DimensionedField& f2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1, \ + const tmp>& tf2 \ ); @@ -199,62 +246,78 @@ tmp> operator Op \ #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ + DimensionedField& result, \ const dimensioned& dt1, \ - const DimensionedField& df2 \ -); \ - \ -TEMPLATE \ -tmp> operator Op \ -( \ - const Type1& t1, \ - const DimensionedField& df2 \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ - const tmp>& tdf2 \ + const DimensionedField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& t1, \ - const tmp>& tdf2 \ + const Type1& s1, \ + const DimensionedField& f2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const dimensioned& dt1, \ + const tmp>& tf2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const Type1& s1, \ + const tmp>& tf2 \ ); #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ - const DimensionedField& df1, \ + DimensionedField& result, \ + const DimensionedField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const DimensionedField& df1, \ - const Type2& t2 \ -); \ - \ -TEMPLATE \ -tmp> operator Op \ -( \ - const tmp>& tdf1, \ + const DimensionedField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const Type2& t2 \ + const DimensionedField& f1, \ + const Type2& s2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1, \ + const dimensioned& dt2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1, \ + const Type2& s2 \ ); @@ -263,4 +326,158 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const DimensionedField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const DimensionedField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const DimensionedField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const DimensionedField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const DimensionedField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + DimensionedField& result, \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const DimensionedField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const DimensionedField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const DimensionedField& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H index 4edd1b6f32..c1aae8ca0a 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,28 +35,51 @@ namespace Foam { // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// One-parameter versions template struct reuseTmpDimensionedField { + //- Pass-through to New DimensionedField static tmp> New ( - const tmp>& tdf1, + const DimensionedField& f1, const word& name, const dimensionSet& dimensions ) { - const auto& df1 = tdf1(); + return tmp>::New + ( + IOobject + ( + name, + f1.instance(), + f1.db() + ), + f1.mesh(), + dimensions + ); + } + + //- Dissimilar types: return new field + static tmp> New + ( + const tmp>& tf1, + const word& name, + const dimensionSet& dimensions + ) + { + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - df1.instance(), - df1.db() + f1.instance(), + f1.db() ), - df1.mesh(), + f1.mesh(), dimensions ); } @@ -70,38 +93,38 @@ struct reuseTmpDimensionedField //- for identical input and output types static tmp> New ( - const tmp>& tdf1, + const tmp>& tf1, const word& name, const dimensionSet& dimensions, const bool initCopy = false ) { - if (tdf1.movable()) + if (tf1.movable()) { - auto& df1 = tdf1.constCast(); + auto& f1 = tf1.constCast(); - df1.rename(name); - df1.dimensions().reset(dimensions); - return tdf1; + f1.rename(name); + f1.dimensions().reset(dimensions); + return tf1; } - const auto& df1 = tdf1(); + const auto& f1 = tf1(); auto tresult = tmp>::New ( IOobject ( name, - df1.instance(), - df1.db() + f1.instance(), + f1.db() ), - df1.mesh(), + f1.mesh(), dimensions ); if (initCopy) { - tresult.ref().field() = tdf1().field(); + tresult.ref().field() = tf1().field(); } return tresult; @@ -113,7 +136,7 @@ struct reuseTmpDimensionedField template tmp> New ( - const tmp>& tdf1, + const tmp>& tf1, const word& name, const dimensionSet& dimensions, const bool initCopy = false @@ -121,7 +144,7 @@ tmp> New { return reuseTmpDimensionedField::New ( - tdf1, + tf1, name, dimensions, initCopy @@ -134,23 +157,23 @@ struct reuseTmpTmpDimensionedField { static tmp> New ( - const tmp>& tdf1, - const tmp>& tdf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - const auto& df1 = tdf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - df1.instance(), - df1.db() + f1.instance(), + f1.db() ), - df1.mesh(), + f1.mesh(), dimensions ); } @@ -162,32 +185,32 @@ struct reuseTmpTmpDimensionedField { static tmp> New ( - const tmp>& tdf1, - const tmp>& tdf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - if (tdf2.movable()) + if (tf2.movable()) { - auto& df2 = tdf2.constCast(); + auto& f2 = tf2.constCast(); - df2.rename(name); - df2.dimensions().reset(dimensions); - return tdf2; + f2.rename(name); + f2.dimensions().reset(dimensions); + return tf2; } - const auto& df1 = tdf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - df1.instance(), - df1.db() + f1.instance(), + f1.db() ), - df1.mesh(), + f1.mesh(), dimensions ); } @@ -199,32 +222,32 @@ struct reuseTmpTmpDimensionedField { static tmp> New ( - const tmp>& tdf1, - const tmp>& tdf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - if (tdf1.movable()) + if (tf1.movable()) { - auto& df1 = tdf1.constCast(); + auto& f1 = tf1.constCast(); - df1.rename(name); - df1.dimensions().reset(dimensions); - return tdf1; + f1.rename(name); + f1.dimensions().reset(dimensions); + return tf1; } - const auto& df1 = tdf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - df1.instance(), - df1.db() + f1.instance(), + f1.db() ), - df1.mesh(), + f1.mesh(), dimensions ); } @@ -236,40 +259,40 @@ struct reuseTmpTmpDimensionedField { static tmp> New ( - const tmp>& tdf1, - const tmp>& tdf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - if (tdf1.movable()) + if (tf1.movable()) { - auto& df1 = tdf1.constCast(); + auto& f1 = tf1.constCast(); - df1.rename(name); - df1.dimensions().reset(dimensions); - return tdf1; + f1.rename(name); + f1.dimensions().reset(dimensions); + return tf1; } - if (tdf2.movable()) + if (tf2.movable()) { - auto& df2 = tdf2.constCast(); + auto& f2 = tf2.constCast(); - df2.rename(name); - df2.dimensions().reset(dimensions); - return tdf2; + f2.rename(name); + f2.dimensions().reset(dimensions); + return tf2; } - const auto& df1 = tdf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - df1.instance(), - df1.db() + f1.instance(), + f1.db() ), - df1.mesh(), + f1.mesh(), dimensions ); } diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C index 5566474746..17d07fb2f0 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C @@ -282,39 +282,6 @@ void FieldField::replace } -template class Field, class Type> -void FieldField::clamp -( - const Type& lower, - const Type& upper -) -{ - if (lower < upper) - { - for (auto& ff : *this) - { - ff.clamp(lower, upper); - } - } -} - - -template class Field, class Type> -void FieldField::clamp -( - const MinMax& range -) -{ - if (range.min() < range.max()) - { - for (auto& ff : *this) - { - ff.clamp(range.min(), range.max()); - } - } -} - - template class Field, class Type> void FieldField::clamp_min ( @@ -341,6 +308,37 @@ void FieldField::clamp_max } +template class Field, class Type> +void FieldField::clamp_range +( + const Type& lower, + const Type& upper +) +{ + // Note: no checks for bad/invalid clamping ranges + + for (auto& ff : *this) + { + ff.clamp_range(lower, upper); + } +} + + +template class Field, class Type> +void FieldField::clamp_range +( + const MinMax& range +) +{ + // Note: no checks for bad/invalid clamping ranges + + for (auto& ff : *this) + { + ff.clamp_range(range.min(), range.max()); + } +} + + template class Field, class Type> tmp> FieldField::T() const { diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H index 11504cbe79..d8dbbcdf0e 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H @@ -149,20 +149,20 @@ public: //- Replace a component field of the field void replace(const direction, const cmptType&); - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. - void clamp(const Type& lower, const Type& upper); - - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. - void clamp(const MinMax& range); - //- Impose lower (floor) clamp on the field values (in-place) void clamp_min(const Type& lower); //- Impose upper (ceiling) clamp on the field values (in-place) void clamp_max(const Type& upper); + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. + void clamp_range(const Type& lower, const Type& upper); + + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. + void clamp_range(const MinMax& range); + //- Return the field transpose (only defined for second rank tensors) tmp> T() const; diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C index 9be878df3d..54a489deac 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,12 +90,9 @@ pow const FieldField& f, typename powProduct::type ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); pow(tres.ref(), f); return tres; @@ -108,12 +105,9 @@ pow const tmp>& tf, typename powProduct::type ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); pow(tres.ref(), tf()); tf.clear(); @@ -140,11 +134,10 @@ template class Field, class Type> tmp::type>> sqr(const FieldField& f) { - typedef typename outerProduct::type outerProductType; - tmp> tres - ( - FieldField::NewCalculatedType(f) - ); + typedef typename outerProduct::type resultType; + + auto tres = FieldField::NewCalculatedType(f); + sqr(tres.ref(), f); return tres; } @@ -153,12 +146,9 @@ template class Field, class Type> tmp::type>> sqr(const tmp>& tf) { - typedef typename outerProduct::type outerProductType; + typedef typename outerProduct::type resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); sqr(tres.ref(), tf()); tf.clear(); @@ -185,12 +175,9 @@ template class Field, class Type> tmp::type>> magSqr(const FieldField& f) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); magSqr(tres.ref(), f); return tres; @@ -200,12 +187,9 @@ template class Field, class Type> tmp::type>> magSqr(const tmp>& tf) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); magSqr(tres.ref(), tf()); tf.clear(); @@ -232,12 +216,9 @@ template class Field, class Type> tmp::type>> mag(const FieldField& f) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); mag(tres.ref(), f); return tres; @@ -247,12 +228,9 @@ template class Field, class Type> tmp::type>> mag(const tmp>& tf) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); mag(tres.ref(), tf()); tf.clear(); @@ -281,12 +259,9 @@ tmp::cmptType>> cmptMax const FieldField& f ) { - typedef typename FieldField::cmptType cmptType; + typedef typename FieldField::cmptType resultType; - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); cmptMax(tres.ref(), f); return tres; @@ -298,12 +273,9 @@ tmp::cmptType>> cmptMax const tmp>& tf ) { - typedef typename FieldField::cmptType cmptType; + typedef typename FieldField::cmptType resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); cmptMax(tres.ref(), tf()); tf.clear(); @@ -332,12 +304,9 @@ tmp::cmptType>> cmptMin const FieldField& f ) { - typedef typename FieldField::cmptType cmptType; + typedef typename FieldField::cmptType resultType; - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); cmptMin(tres.ref(), f); return tres; @@ -349,12 +318,9 @@ tmp::cmptType>> cmptMin const tmp>& tf ) { - typedef typename FieldField::cmptType cmptType; + typedef typename FieldField::cmptType resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); cmptMin(tres.ref(), tf()); tf.clear(); @@ -383,12 +349,9 @@ tmp::cmptType>> cmptAv const FieldField& f ) { - typedef typename FieldField::cmptType cmptType; + typedef typename FieldField::cmptType resultType; - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); cmptAv(tres.ref(), f); return tres; @@ -400,12 +363,9 @@ tmp::cmptType>> cmptAv const tmp>& tf ) { - typedef typename FieldField::cmptType cmptType; + typedef typename FieldField::cmptType resultType; - auto tres - ( - reuseTmpFieldField::New(tf) - ); + auto tres = reuseTmpFieldField::New(tf); cmptAv(tres.ref(), tf()); tf.clear(); @@ -434,10 +394,7 @@ tmp> cmptMag const FieldField& f ) { - auto tres - ( - FieldField::NewCalculatedType(f) - ); + auto tres = FieldField::NewCalculatedType(f); cmptMag(tres.ref(), f); return tres; @@ -456,12 +413,12 @@ tmp> cmptMag } -#define TMP_UNARY_FUNCTION(returnType, func) \ +#define TMP_UNARY_FUNCTION(ReturnType, Func) \ \ template class Field, class Type> \ -returnType func(const tmp>& tf1) \ +ReturnType Func(const tmp>& tf1) \ { \ - returnType res = func(tf1()); \ + ReturnType res = Func(tf1()); \ tf1.clear(); \ return res; \ } @@ -529,9 +486,9 @@ TMP_UNARY_FUNCTION(Type, sum) template class Field, class Type> typename typeOfMag::type sumMag(const FieldField& f) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - magType result = Zero; + resultType result = Zero; const label loopLen = (f).size(); @@ -609,12 +566,12 @@ TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag) // With reduction on ReturnType -#define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc) \ +#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \ \ template class Field, class Type> \ ReturnType gFunc(const FieldField& f) \ { \ - ReturnType res = func(f); \ + ReturnType res = Func(f); \ reduce(res, rFunc##Op()); \ return res; \ } \ @@ -653,7 +610,7 @@ Type gAverage(const FieldField& f) } WarningInFunction - << "empty fieldField, returning zero" << endl; + << "Empty FieldField, returning zero" << endl; return Zero; } @@ -673,10 +630,17 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) +// Note: works with zero_one through implicit conversion to MinMax BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) -/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + + +/* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */ UNARY_OPERATOR(Type, Type, -, negate) @@ -692,7 +656,7 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define PRODUCT_OPERATOR(product, op, opFunc) \ +#define PRODUCT_OPERATOR(product, Op, OpFunc) \ \ template \ < \ @@ -701,7 +665,7 @@ template \ class Type1, \ class Type2 \ > \ -void opFunc \ +void OpFunc \ ( \ FieldField::type>& f, \ const FieldField& f1, \ @@ -712,7 +676,7 @@ void opFunc \ \ for (label i = 0; i < loopLen; ++i) \ { \ - opFunc(f[i], f1[i], f2[i]); \ + OpFunc(f[i], f1[i], f2[i]); \ } \ } \ \ @@ -724,35 +688,29 @@ template \ class Type2 \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const FieldField& f1, \ const FieldField& f2 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ - opFunc(tres.ref(), f1, f2); \ + typedef typename product::type resultType; \ + auto tres = FieldField::NewCalculatedType(f1); \ + OpFunc(tres.ref(), f1, f2); \ return tres; \ } \ \ template class Field, class Type1, class Type2> \ tmp::type>> \ -operator op \ +operator Op \ ( \ const FieldField& f1, \ const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf2) \ - ); \ - opFunc(tres.ref(), f1, tf2()); \ + typedef typename product::type resultType; \ + auto tres = reuseTmpFieldField::New(tf2); \ + OpFunc(tres.ref(), f1, tf2()); \ tf2.clear(); \ return tres; \ } \ @@ -765,18 +723,15 @@ template \ class Type2 \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const FieldField& f1, \ const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ - opFunc(tres.ref(), f1, tf2()); \ + typedef typename product::type resultType; \ + auto tres = FieldField::NewCalculatedType(f1); \ + OpFunc(tres.ref(), f1, tf2()); \ tf2.clear(); \ return tres; \ } \ @@ -789,18 +744,15 @@ template \ class Type2 \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const tmp>& tf1, \ const FieldField& f2 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ - opFunc(tres.ref(), tf1(), f2); \ + typedef typename product::type resultType; \ + auto tres = reuseTmpFieldField::New(tf1); \ + OpFunc(tres.ref(), tf1(), f2); \ tf1.clear(); \ return tres; \ } \ @@ -813,19 +765,19 @@ template \ class Type2 \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const tmp>& tf1, \ const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ + typedef typename product::type resultType; \ + auto tres \ ( \ - reuseTmpTmpFieldField::New \ + reuseTmpTmpFieldField::New \ (tf1, tf2) \ ); \ - opFunc(tres.ref(), tf1(), tf2()); \ + OpFunc(tres.ref(), tf1(), tf2()); \ tf1.clear(); \ tf2.clear(); \ return tres; \ @@ -839,18 +791,18 @@ template \ class Cmpt, \ direction nCmpt \ > \ -void opFunc \ +void OpFunc \ ( \ - FieldField::type>& f, \ + FieldField::type>& result, \ const FieldField& f1, \ const VectorSpace& vs \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - opFunc(f[i], f1[i], vs); \ + OpFunc(result[i], f1[i], vs); \ } \ } \ \ @@ -863,18 +815,15 @@ template \ direction nCmpt \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const FieldField& f1, \ const VectorSpace& vs \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ - opFunc(tres.ref(), f1, static_cast(vs)); \ + typedef typename product::type resultType; \ + auto tres = FieldField::NewCalculatedType(f1); \ + OpFunc(tres.ref(), f1, static_cast(vs)); \ return tres; \ } \ \ @@ -887,18 +836,15 @@ template \ direction nCmpt \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const tmp>& tf1, \ const VectorSpace& vs \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ - opFunc(tres.ref(), tf1(), static_cast(vs)); \ + typedef typename product::type resultType; \ + auto tres = reuseTmpFieldField::New(tf1); \ + OpFunc(tres.ref(), tf1(), static_cast(vs)); \ tf1.clear(); \ return tres; \ } \ @@ -911,18 +857,18 @@ template \ class Cmpt, \ direction nCmpt \ > \ -void opFunc \ +void OpFunc \ ( \ - FieldField::type>& f, \ + FieldField::type>& result, \ const VectorSpace& vs, \ const FieldField& f1 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - opFunc(f[i], vs, f1[i]); \ + OpFunc(result[i], vs, f1[i]); \ } \ } \ \ @@ -935,18 +881,15 @@ template \ direction nCmpt \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ const FieldField& f1 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ - opFunc(tres.ref(), static_cast(vs), f1); \ + typedef typename product::type resultType; \ + auto tres = FieldField::NewCalculatedType(f1); \ + OpFunc(tres.ref(), static_cast(vs), f1); \ return tres; \ } \ \ @@ -959,18 +902,15 @@ template \ direction nCmpt \ > \ tmp::type>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ const tmp>& tf1 \ ) \ { \ - typedef typename product::type productType; \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ - opFunc(tres.ref(), static_cast(vs), tf1()); \ + typedef typename product::type resultType; \ + auto tres = reuseTmpFieldField::New(tf1); \ + OpFunc(tres.ref(), static_cast(vs), tf1()); \ tf1.clear(); \ return tres; \ } diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H index a9a7084e97..843bf67c58 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H @@ -287,10 +287,16 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) +// Note: works with zero_one through implicit conversion to MinMax BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + + +/* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */ UNARY_OPERATOR(Type, Type, -, negate) diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C index 500cd8d54e..5becaa4753 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,92 +31,86 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define UNARY_FUNCTION(ReturnType, Type, Func) \ +#define UNARY_FUNCTION(ReturnType, Type1, Func) \ \ TEMPLATE \ void Func \ ( \ - FieldField& res, \ - const FieldField& f \ + FieldField& result, \ + const FieldField& f1 \ ) \ { \ - const label loopLen = (res).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - Func(res[i], f[i]); \ + Func(result[i], f1[i]); \ } \ } \ \ TEMPLATE \ tmp> Func \ ( \ - const FieldField& f \ + const FieldField& f1 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f) \ - ); \ - Func(tres.ref(), f); \ + auto tres = FieldField::NewCalculatedType(f1); \ + Func(tres.ref(), f1); \ return tres; \ } \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tf \ + const tmp>& tf1 \ ) \ { \ - tmp> tres(New(tf)); \ - Func(tres.ref(), tf()); \ - tf.clear(); \ + auto tres = reuseTmpFieldField::New(tf1); \ + Func(tres.ref(), tf1()); \ + tf1.clear(); \ return tres; \ } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \ +#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc) \ \ TEMPLATE \ void OpFunc \ ( \ - FieldField& res, \ - const FieldField& f \ + FieldField& result, \ + const FieldField& f1 \ ) \ { \ - const label loopLen = (res).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - OpFunc(res[i], f[i]); \ + OpFunc(result[i], f1[i]); \ } \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ - const FieldField& f \ + const FieldField& f1 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f) \ - ); \ - OpFunc(tres.ref(), f); \ + auto tres = FieldField::NewCalculatedType(f1); \ + OpFunc(tres.ref(), f1); \ return tres; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tf \ + const tmp>& tf1 \ ) \ { \ - tmp> tres(New(tf)); \ - OpFunc(tres.ref(), tf()); \ - tf.clear(); \ + auto tres = reuseTmpFieldField::New(tf1); \ + OpFunc(tres.ref(), tf1()); \ + tf1.clear(); \ return tres; \ } @@ -128,16 +122,16 @@ tmp> operator Op \ TEMPLATE \ void Func \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ const FieldField& f2 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - Func(f[i], f1[i], f2[i]); \ + Func(result[i], f1[i], f2[i]); \ } \ } \ \ @@ -148,10 +142,7 @@ tmp> Func \ const FieldField& f2 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ + auto tres = FieldField::NewCalculatedType(f1); \ Func(tres.ref(), f1, f2); \ return tres; \ } \ @@ -163,10 +154,7 @@ tmp> Func \ const tmp>& tf2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf2) \ - ); \ + auto tres = reuseTmpFieldField::New(tf2); \ Func(tres.ref(), f1, tf2()); \ tf2.clear(); \ return tres; \ @@ -179,10 +167,7 @@ tmp> Func \ const FieldField& f2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ + auto tres = reuseTmpFieldField::New(tf1); \ Func(tres.ref(), tf1(), f2); \ tf1.clear(); \ return tres; \ @@ -195,7 +180,7 @@ tmp> Func \ const tmp>& tf2 \ ) \ { \ - tmp> tres \ + auto tres \ ( \ reuseTmpTmpFieldField:: \ New(tf1, tf2) \ @@ -214,46 +199,40 @@ tmp> Func \ TEMPLATE \ void Func \ ( \ - FieldField& f, \ - const Type1& s, \ + FieldField& result, \ + const Type1& s1, \ const FieldField& f2 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - Func(f[i], s, f2[i]); \ + Func(result[i], s1, f2[i]); \ } \ } \ \ TEMPLATE \ tmp> Func \ ( \ - const Type1& s, \ + const Type1& s1, \ const FieldField& f2 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f2) \ - ); \ - Func(tres.ref(), s, f2); \ + auto tres = FieldField::NewCalculatedType(f2); \ + Func(tres.ref(), s1, f2); \ return tres; \ } \ \ TEMPLATE \ tmp> Func \ ( \ - const Type1& s, \ + const Type1& s1, \ const tmp>& tf2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf2) \ - ); \ - Func(tres.ref(), s, tf2()); \ + auto tres = reuseTmpFieldField::New(tf2); \ + Func(tres.ref(), s1, tf2()); \ tf2.clear(); \ return tres; \ } @@ -264,16 +243,16 @@ tmp> Func \ TEMPLATE \ void Func \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ - const Type2& s \ + const Type2& s2 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - Func(f[i], f1[i], s); \ + Func(result[i], f1[i], s2); \ } \ } \ \ @@ -281,14 +260,11 @@ TEMPLATE \ tmp> Func \ ( \ const FieldField& f1, \ - const Type2& s \ + const Type2& s2 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ - Func(tres.ref(), f1, s); \ + auto tres = FieldField::NewCalculatedType(f1); \ + Func(tres.ref(), f1, s2); \ return tres; \ } \ \ @@ -296,14 +272,11 @@ TEMPLATE \ tmp> Func \ ( \ const tmp>& tf1, \ - const Type2& s \ + const Type2& s2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ - Func(tres.ref(), tf1(), s); \ + auto tres = reuseTmpFieldField::New(tf1); \ + Func(tres.ref(), tf1(), s2); \ tf1.clear(); \ return tres; \ } @@ -321,16 +294,16 @@ tmp> Func \ TEMPLATE \ void OpFunc \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ const FieldField& f2 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - OpFunc(f[i], f1[i], f2[i]); \ + OpFunc(result[i], f1[i], f2[i]); \ } \ } \ \ @@ -341,10 +314,7 @@ tmp> operator Op \ const FieldField& f2 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ + auto tres = FieldField::NewCalculatedType(f1); \ OpFunc(tres.ref(), f1, f2); \ return tres; \ } \ @@ -356,10 +326,7 @@ tmp> operator Op \ const tmp>& tf2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf2) \ - ); \ + auto tres = reuseTmpFieldField::New(tf2); \ OpFunc(tres.ref(), f1, tf2()); \ tf2.clear(); \ return tres; \ @@ -372,10 +339,7 @@ tmp> operator Op \ const FieldField& f2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ + auto tres = reuseTmpFieldField::New(tf1); \ OpFunc(tres.ref(), tf1(), f2); \ tf1.clear(); \ return tres; \ @@ -388,7 +352,7 @@ tmp> operator Op \ const tmp>& tf2 \ ) \ { \ - tmp> tres \ + auto tres \ ( \ reuseTmpTmpFieldField:: \ New(tf1, tf2) \ @@ -407,46 +371,40 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - FieldField& f, \ - const Type1& s, \ + FieldField& result, \ + const Type1& s1, \ const FieldField& f2 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - OpFunc(f[i], s, f2[i]); \ + OpFunc(result[i], s1, f2[i]); \ } \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& s, \ + const Type1& s1, \ const FieldField& f2 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f2) \ - ); \ - OpFunc(tres.ref(), s, f2); \ + auto tres = FieldField::NewCalculatedType(f2); \ + OpFunc(tres.ref(), s1, f2); \ return tres; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& s, \ + const Type1& s1, \ const tmp>& tf2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf2) \ - ); \ - OpFunc(tres.ref(), s, tf2()); \ + auto tres = reuseTmpFieldField::New(tf2); \ + OpFunc(tres.ref(), s1, tf2()); \ tf2.clear(); \ return tres; \ } @@ -457,16 +415,16 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ - const Type2& s \ + const Type2& s2 \ ) \ { \ - const label loopLen = (f).size(); \ + const label loopLen = (result).size(); \ \ for (label i = 0; i < loopLen; ++i) \ { \ - OpFunc(f[i], f1[i], s); \ + OpFunc(result[i], f1[i], s2); \ } \ } \ \ @@ -474,14 +432,11 @@ TEMPLATE \ tmp> operator Op \ ( \ const FieldField& f1, \ - const Type2& s \ + const Type2& s2 \ ) \ { \ - tmp> tres \ - ( \ - FieldField::NewCalculatedType(f1) \ - ); \ - OpFunc(tres.ref(), f1, s); \ + auto tres = FieldField::NewCalculatedType(f1); \ + OpFunc(tres.ref(), f1, s2); \ return tres; \ } \ \ @@ -489,14 +444,11 @@ TEMPLATE \ tmp> operator Op \ ( \ const tmp>& tf1, \ - const Type2& s \ + const Type2& s2 \ ) \ { \ - tmp> tres \ - ( \ - reuseTmpFieldField::New(tf1) \ - ); \ - OpFunc(tres.ref(), tf1(), s); \ + auto tres = reuseTmpFieldField::New(tf1); \ + OpFunc(tres.ref(), tf1(), s2); \ tf1.clear(); \ return tres; \ } @@ -506,4 +458,240 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + FieldField& result, \ + const FieldField& f1, \ + const FieldField& f2, \ + const FieldField& f3 \ +) \ +{ \ + const label loopLen = (result).size(); \ + \ + for (label i = 0; i < loopLen; ++i) \ + { \ + Func(result[i], f1[i], f2[i], f3[i]); \ + } \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const FieldField& f2, \ + const FieldField& f3 \ +) \ +{ \ + auto tres = FieldField::NewCalculatedType(f1); \ + Func(tres.ref(), f1, f2, f3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const FieldField& f2, \ + const FieldField& f3 \ +) \ +{ \ + auto tres = reuseTmpFieldField::New(tf1); \ + Func(tres.ref(), tf1(), f2, f3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const tmp>& tf2, \ + const FieldField& f3 \ +) \ +{ \ + auto tres = reuseTmpFieldField::New(tf2); \ + Func(tres.ref(), f1, tf2(), f3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const FieldField& f2, \ + const tmp>& tf3 \ +) \ +{ \ + auto tres = reuseTmpFieldField::New(tf3); \ + Func(tres.ref(), f1, f2, tf3()); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const FieldField& f3 \ +) \ +{ \ + tmp> tres \ + ( \ + reuseTmpTmpFieldField:: \ + New(tf1, tf2) \ + ); \ + Func(tres.ref(), tf1(), tf2(), f3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const FieldField& f2, \ + const tmp>& tf3 \ +) \ +{ \ + tmp> tres \ + ( \ + reuseTmpTmpFieldField:: \ + New(tf1, tf3) \ + ); \ + Func(tres.ref(), tf1(), f2, tf3()); \ + tf1.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + tmp> tres \ + ( \ + reuseTmpTmpFieldField:: \ + New(tf2, tf3) \ + ); \ + Func(tres.ref(), f1, tf2(), tf3()); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + /* TBD: check all three types? */ \ + tmp> tres \ + ( \ + reuseTmpTmpFieldField:: \ + New(tf1, tf2) \ + ); \ + Func(tres.ref(), tf1(), tf2(), tf3()); \ + tf1.clear(); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + FieldField& result, \ + const FieldField& f1, \ + const FieldField& f2, \ + const Type3& s3 \ +) \ +{ \ + const label loopLen = (result).size(); \ + \ + for (label i = 0; i < loopLen; ++i) \ + { \ + Func(result[i], f1[i], f2[i], s3); \ + } \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const FieldField& f2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = FieldField::NewCalculatedType(f1); \ + Func(tres.ref(), f1, f2, s3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const FieldField& f2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = reuseTmpFieldField::New(tf1); \ + Func(tres.ref(), tf1(), f2, s3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = reuseTmpFieldField::New(tf2); \ + Func(tres.ref(), f1, tf2(), s3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + tmp> tres \ + ( \ + reuseTmpTmpFieldField:: \ + New(tf1, tf2) \ + ); \ + Func(tres.ref(), tf1(), tf2(), s3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.H index 1771f2365a..81aac62600 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,9 +25,7 @@ License along with OpenFOAM. If not, see . Description - High performance macro functions for Field\ algebra. - These expand using either array element access (for vector machines) - or pointer dereferencing for scalar machines as appropriate. + Macro functions for FieldField\ algebra. \*---------------------------------------------------------------------------*/ @@ -37,20 +36,20 @@ Description TEMPLATE \ void Func \ ( \ - FieldField& res, \ - const FieldField& f \ + FieldField& result, \ + const FieldField& f1 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const FieldField& f \ + const FieldField& f1 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tf \ + const tmp>& tf1 \ ); @@ -61,20 +60,20 @@ tmp> Func \ TEMPLATE \ void OpFunc \ ( \ - FieldField& res, \ - const FieldField& f \ + FieldField& result, \ + const FieldField& f1 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const FieldField& f \ + const FieldField& f1 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tf \ + const tmp>& tf1 \ ); @@ -83,36 +82,36 @@ tmp> operator Op \ #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -void func \ +void Func \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ const FieldField& f2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const FieldField& f1, \ const FieldField& f2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const FieldField& f1, \ const tmp>& tf2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const tmp>& tf1, \ const FieldField& f2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const tmp>& tf1, \ const tmp>& tf2 \ @@ -124,22 +123,22 @@ tmp> func \ #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -void func \ +void Func \ ( \ - FieldField& f, \ + FieldField& result, \ const Type1& s1, \ const FieldField& f2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const Type1& s1, \ const FieldField& f2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const Type1& s1, \ const tmp>& tf2 \ @@ -149,25 +148,25 @@ tmp> func \ #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -void func \ +void Func \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ - const Type2& s \ + const Type2& s2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const FieldField& f1, \ - const Type2& s \ + const Type2& s2 \ ); \ \ TEMPLATE \ -tmp> func \ +tmp> Func \ ( \ const tmp>& tf1, \ - const Type2& s \ + const Type2& s2 \ ); @@ -183,7 +182,7 @@ tmp> func \ TEMPLATE \ void OpFunc \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ const FieldField& f2 \ ); \ @@ -224,7 +223,7 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - FieldField& f, \ + FieldField& result, \ const Type1& s1, \ const FieldField& f2 \ ); \ @@ -249,7 +248,7 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - FieldField& f, \ + FieldField& result, \ const FieldField& f1, \ const Type2& s2 \ ); \ @@ -274,4 +273,126 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + FieldField& result, \ + const FieldField& f1, \ + const FieldField& f2, \ + const FieldField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const FieldField& f2, \ + const FieldField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const FieldField& f2, \ + const FieldField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const tmp>& tf2, \ + const FieldField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const FieldField& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const FieldField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const FieldField& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + FieldField& result, \ + const FieldField& f1, \ + const FieldField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const FieldField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const FieldField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const FieldField& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H index f0bff7dead..7e51d03daf 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,10 +35,21 @@ namespace Foam { // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// One-parameter versions template class Field, class TypeR, class Type1> struct reuseTmpFieldField { + //- Pass-through to NewCalculatedType + static tmp> New + ( + const FieldField& f1 + ) + { + return FieldField::NewCalculatedType(f1); + } + + //- Dissimilar types: just use size static tmp> New ( const tmp>& tf1 @@ -52,6 +63,8 @@ struct reuseTmpFieldField template class Field, class TypeR> struct reuseTmpFieldField { + //- Identical input and return types: + //- allow optional copy assignment of the initial content static tmp> New ( const tmp>& tf1, @@ -63,19 +76,19 @@ struct reuseTmpFieldField return tf1; } - auto rtf = FieldField::NewCalculatedType(tf1()); + auto tresult = FieldField::NewCalculatedType(tf1()); if (initCopy) { - rtf.ref() = tf1(); + tresult.ref() = tf1(); } - return rtf; + return tresult; } }; -//- Global function forwards to reuseTmpFieldField::New +//- This global function forwards to reuseTmpFieldField::New template class Field, class TypeR> tmp> New ( @@ -87,6 +100,9 @@ tmp> New } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Two-parameter versions + template < template class Field, @@ -97,6 +113,7 @@ template > struct reuseTmpTmpFieldField { + //- Dissimilar types: just use size static tmp> New ( const tmp>& tf1, @@ -111,6 +128,7 @@ struct reuseTmpTmpFieldField template class Field, class TypeR, class Type1, class Type12> struct reuseTmpTmpFieldField { + //- Second input has return type static tmp> New ( const tmp>& tf1, @@ -130,6 +148,7 @@ struct reuseTmpTmpFieldField template class Field, class TypeR, class Type2> struct reuseTmpTmpFieldField { + //- First input has return type static tmp> New ( const tmp>& tf1, @@ -149,6 +168,7 @@ struct reuseTmpTmpFieldField template class Field, class TypeR> struct reuseTmpTmpFieldField { + //- Both inputs have return type static tmp> New ( const tmp>& tf1, diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index fad7a81541..64dc2d73a3 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -658,27 +658,6 @@ void Foam::Field::replace } -template -void Foam::Field::clamp(const Type& lower, const Type& upper) -{ - // Use free functions min(), max() to impose component-wise clamping - if (lower < upper) - { - // std::for_each - for (auto& val : *this) - { - val = min(max(val, lower), upper); - } - } -} - -template -void Foam::Field::clamp(const MinMax& range) -{ - clamp(range.min(), range.max()); -} - - template void Foam::Field::clamp_min(const Type& lower) { @@ -702,6 +681,26 @@ void Foam::Field::clamp_max(const Type& upper) } +template +void Foam::Field::clamp_range(const Type& lower, const Type& upper) +{ + // Note: no checks for bad/invalid clamping ranges + + // Use free functions min(), max() to impose component-wise clamping + // std::for_each + for (auto& val : *this) + { + val = min(max(val, lower), upper); + } +} + +template +void Foam::Field::clamp_range(const MinMax& range) +{ + Field::clamp_range(range.min(), range.max()); +} + + template template VSForm Foam::Field::block(const label start) const diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H index f398928d1a..0f5d81237f 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.H +++ b/src/OpenFOAM/fields/Fields/Field/Field.H @@ -434,20 +434,20 @@ public: //- Replace a component field of the field void replace(const direction, const cmptType&); - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. - void clamp(const Type& lower, const Type& upper); - - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. - void clamp(const MinMax& range); - //- Impose lower (floor) clamp on the field values (in-place) void clamp_min(const Type& lower); //- Impose upper (ceiling) clamp on the field values (in-place) void clamp_max(const Type& upper); + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. + void clamp_range(const Type& lower, const Type& upper); + + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. + void clamp_range(const MinMax& range); + template VSForm block(const label start) const; diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index bfcc7860d3..583c443971 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -42,38 +42,40 @@ namespace Foam template void component ( - Field::cmptType>& res, - const UList& f, + Field::cmptType>& result, + const UList& f1, const direction d ) { - typedef typename Field::cmptType cmptType; + typedef typename Field::cmptType resultType; + TFOR_ALL_F_OP_F_FUNC_S ( - cmptType, res, =, Type, f, .component, const direction, d + resultType, result, =, Type, f1, .component, const direction, d ) } template -void T(Field& res, const UList& f) +void T(Field& result, const UList& f1) { - TFOR_ALL_F_OP_F_FUNC(Type, res, =, Type, f, T) + TFOR_ALL_F_OP_F_FUNC(Type, result, =, Type, f1, T) } template void pow ( - Field::type>& res, - const UList& vf + Field::type>& result, + const UList& f1 ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; + TFOR_ALL_F_OP_FUNC_F_S ( - powProductType, res, =, pow, Type, vf, powProductType, - pTraits::zero + resultType, result, =, pow, Type, f1, resultType, + pTraits::zero ) } @@ -81,16 +83,13 @@ template tmp::type>> pow ( - const UList& f, + const UList& f1, typename powProduct::type ) { - typedef typename powProduct::type powProductType; - auto tres - ( - tmp>::New(f.size()) - ); - pow(tres.ref(), f); + typedef typename powProduct::type resultType; + auto tres = tmp>::New(f1.size()); + pow(tres.ref(), f1); return tres; } @@ -98,14 +97,14 @@ template tmp::type>> pow ( - const tmp>& tf, + const tmp>& tf1, typename powProduct::type ) { - typedef typename powProduct::type powProductType; - auto tres = reuseTmp::New(tf); - pow(tres.ref(), tf()); - tf.clear(); + typedef typename powProduct::type resultType; + auto tres = reuseTmp::New(tf1); + pow(tres.ref(), tf1()); + tf1.clear(); return tres; } @@ -113,35 +112,33 @@ pow template void sqr ( - Field::type>& res, - const UList& vf + Field::type>& result, + const UList& f1 ) { - typedef typename outerProduct::type outerProductType; - TFOR_ALL_F_OP_FUNC_F(outerProductType, res, =, sqr, Type, vf) + typedef typename outerProduct::type resultType; + + TFOR_ALL_F_OP_FUNC_F(resultType, result, =, sqr, Type, f1) } template tmp::type>> -sqr(const UList& f) +sqr(const UList& f1) { - typedef typename outerProduct::type outerProductType; - auto tres - ( - tmp>::New(f.size()) - ); - sqr(tres.ref(), f); + typedef typename outerProduct::type resultType; + auto tres = tmp>::New(f1.size()); + sqr(tres.ref(), f1); return tres; } template tmp::type>> -sqr(const tmp>& tf) +sqr(const tmp>& tf1) { - typedef typename outerProduct::type outerProductType; - auto tres = reuseTmp::New(tf); - sqr(tres.ref(), tf()); - tf.clear(); + typedef typename outerProduct::type resultType; + auto tres = reuseTmp::New(tf1); + sqr(tres.ref(), tf1()); + tf1.clear(); return tres; } @@ -149,35 +146,35 @@ sqr(const tmp>& tf) template void magSqr ( - Field::type>& res, - const UList& f + Field::type>& result, + const UList& f1 ) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - TFOR_ALL_F_OP_FUNC_F(magType, res, =, magSqr, Type, f) + TFOR_ALL_F_OP_FUNC_F(resultType, result, =, magSqr, Type, f1) } template tmp::type>> -magSqr(const UList& f) +magSqr(const UList& f1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres = tmp>::New(f.size()); - magSqr(tres.ref(), f); + auto tres = tmp>::New(f1.size()); + magSqr(tres.ref(), f1); return tres; } template tmp::type>> -magSqr(const tmp>& tf) +magSqr(const tmp>& tf1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres = reuseTmp::New(tf); - magSqr(tres.ref(), tf()); - tf.clear(); + auto tres = reuseTmp::New(tf1); + magSqr(tres.ref(), tf1()); + tf1.clear(); return tres; } @@ -185,164 +182,179 @@ magSqr(const tmp>& tf) template void mag ( - Field::type>& res, - const UList& f + Field::type>& result, + const UList& f1 ) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - TFOR_ALL_F_OP_FUNC_F(magType, res, =, mag, Type, f) + TFOR_ALL_F_OP_FUNC_F(resultType, result, =, mag, Type, f1) } template tmp::type>> -mag(const UList& f) +mag(const UList& f1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres = tmp>::New(f.size()); - mag(tres.ref(), f); + auto tres = tmp>::New(f1.size()); + mag(tres.ref(), f1); return tres; } template tmp::type>> -mag(const tmp>& tf) +mag(const tmp>& tf1) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; - auto tres = reuseTmp::New(tf); - mag(tres.ref(), tf()); - tf.clear(); + auto tres = reuseTmp::New(tf1); + mag(tres.ref(), tf1()); + tf1.clear(); return tres; } template -void cmptMax(Field::cmptType>& res, const UList& f) +void cmptMax +( + Field::cmptType>& result, + const UList& f1 +) { - typedef typename Field::cmptType cmptType; - TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptMax, Type, f) + typedef typename Field::cmptType resultType; + + TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptMax, Type, f1) } template -tmp::cmptType>> cmptMax(const UList& f) +tmp::cmptType>> cmptMax(const UList& f1) { - typedef typename Field::cmptType cmptType; - auto tres = tmp>::New(f.size()); - cmptMax(tres.ref(), f); + typedef typename Field::cmptType resultType; + auto tres = tmp>::New(f1.size()); + cmptMax(tres.ref(), f1); return tres; } template -tmp::cmptType>> cmptMax(const tmp>& tf) +tmp::cmptType>> cmptMax(const tmp>& tf1) { - typedef typename Field::cmptType cmptType; - auto tres = reuseTmp::New(tf); - cmptMax(tres.ref(), tf()); - tf.clear(); + typedef typename Field::cmptType resultType; + auto tres = reuseTmp::New(tf1); + cmptMax(tres.ref(), tf1()); + tf1.clear(); return tres; } template -void cmptMin(Field::cmptType>& res, const UList& f) +void cmptMin +( + Field::cmptType>& result, + const UList& f1 +) { - typedef typename Field::cmptType cmptType; - TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptMin, Type, f) + typedef typename Field::cmptType resultType; + + TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptMin, Type, f1) } template -tmp::cmptType>> cmptMin(const UList& f) +tmp::cmptType>> cmptMin(const UList& f1) { - typedef typename Field::cmptType cmptType; - auto tres = tmp>::New(f.size()); - cmptMin(tres.ref(), f); + typedef typename Field::cmptType resultType; + auto tres = tmp>::New(f1.size()); + cmptMin(tres.ref(), f1); return tres; } template -tmp::cmptType>> cmptMin(const tmp>& tf) +tmp::cmptType>> cmptMin(const tmp>& tf1) { - typedef typename Field::cmptType cmptType; - auto tres = reuseTmp::New(tf); - cmptMin(tres.ref(), tf()); - tf.clear(); + typedef typename Field::cmptType resultType; + auto tres = reuseTmp::New(tf1); + cmptMin(tres.ref(), tf1()); + tf1.clear(); return tres; } template -void cmptAv(Field::cmptType>& res, const UList& f) +void cmptAv +( + Field::cmptType>& result, + const UList& f1 +) { - typedef typename Field::cmptType cmptType; - TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptAv, Type, f) + typedef typename Field::cmptType resultType; + + TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptAv, Type, f1) } template -tmp::cmptType>> cmptAv(const UList& f) +tmp::cmptType>> cmptAv(const UList& f1) { - typedef typename Field::cmptType cmptType; - auto tres = tmp>::New(f.size()); - cmptAv(tres.ref(), f); + typedef typename Field::cmptType resultType; + auto tres = tmp>::New(f1.size()); + cmptAv(tres.ref(), f1); return tres; } template -tmp::cmptType>> cmptAv(const tmp>& tf) +tmp::cmptType>> cmptAv(const tmp>& tf1) { - typedef typename Field::cmptType cmptType; - auto tres = reuseTmp::New(tf); - cmptAv(tres.ref(), tf()); - tf.clear(); + typedef typename Field::cmptType resultType; + auto tres = reuseTmp::New(tf1); + cmptAv(tres.ref(), tf1()); + tf1.clear(); return tres; } template -void cmptMag(Field& res, const UList& f) +void cmptMag(Field& result, const UList& f1) { - TFOR_ALL_F_OP_FUNC_F(Type, res, =, cmptMag, Type, f) + TFOR_ALL_F_OP_FUNC_F(Type, result, =, cmptMag, Type, f1) } template -tmp> cmptMag(const UList& f) +tmp> cmptMag(const UList& f1) { - auto tres = tmp>::New(f.size()); - cmptMag(tres.ref(), f); + auto tres = tmp>::New(f1.size()); + cmptMag(tres.ref(), f1); return tres; } template -tmp> cmptMag(const tmp>& tf) +tmp> cmptMag(const tmp>& tf1) { - auto tres = New(tf); - cmptMag(tres.ref(), tf()); - tf.clear(); + auto tres = New(tf1); + cmptMag(tres.ref(), tf1()); + tf1.clear(); return tres; } template -void cmptMagSqr(Field& res, const UList& f) +void cmptMagSqr(Field& result, const UList& f1) { - TFOR_ALL_F_OP_FUNC_F(Type, res, =, cmptMagSqr, Type, f) + TFOR_ALL_F_OP_FUNC_F(Type, result, =, cmptMagSqr, Type, f1) } template -tmp> cmptMagSqr(const UList& f) +tmp> cmptMagSqr(const UList& f1) { - auto tres = tmp>::New(f.size()); - cmptMagSqr(tres.ref(), f); + auto tres = tmp>::New(f1.size()); + cmptMagSqr(tres.ref(), f1); return tres; } template -tmp> cmptMagSqr(const tmp>& tf) +tmp> cmptMagSqr(const tmp>& tf1) { - auto tres = New(tf); - cmptMagSqr(tres.ref(), tf()); - tf.clear(); + auto tres = New(tf1); + cmptMagSqr(tres.ref(), tf1()); + tf1.clear(); return tres; } @@ -358,13 +370,13 @@ ReturnType Func(const tmp>& tf1) \ } template -Type max(const UList& f) +Type max(const UList& f1) { - if (f.size()) + if (f1.size()) { - Type Max(f[0]); - TFOR_ALL_S_OP_FUNC_F_S(Type, Max, =, max, Type, f, Type, Max) - return Max; + Type result(f1[0]); + TFOR_ALL_S_OP_FUNC_F_S(Type, result, =, max, Type, f1, Type, result) + return result; } return pTraits::min; @@ -373,13 +385,13 @@ Type max(const UList& f) TMP_UNARY_FUNCTION(Type, max) template -Type min(const UList& f) +Type min(const UList& f1) { - if (f.size()) + if (f1.size()) { - Type Min(f[0]); - TFOR_ALL_S_OP_FUNC_F_S(Type, Min, =, min, Type, f, Type, Min) - return Min; + Type result(f1[0]); + TFOR_ALL_S_OP_FUNC_F_S(Type, result, =, min, Type, f1, Type, result) + return result; } return pTraits::max; @@ -388,18 +400,19 @@ Type min(const UList& f) TMP_UNARY_FUNCTION(Type, min) template -Type sum(const UList& f) +Type sum(const UList& f1) { - typedef typename Foam::typeOfSolve::type solveType; + typedef typename Foam::typeOfSolve::type resultType; - solveType Sum = Zero; + resultType result = Zero; - if (f.size()) + if (f1.size()) { - TFOR_ALL_S_OP_FUNC_F(solveType, Sum, +=, solveType, Type, f) + // Use resultType() as functional cast + TFOR_ALL_S_OP_FUNC_F(resultType, result, +=, resultType, Type, f1) } - return Type(Sum); + return Type(result); } TMP_UNARY_FUNCTION(Type, sum) @@ -414,23 +427,23 @@ TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag) template -Type maxMagSqr(const UList& f) +Type maxMagSqr(const UList& f1) { - if (f.size()) + if (f1.size()) { - Type Max(f[0]); + Type result(f1[0]); TFOR_ALL_S_OP_FUNC_F_S ( Type, - Max, + result, =, maxMagSqrOp(), Type, - f, + f1, Type, - Max + result ) - return Max; + return result; } return Zero; @@ -439,23 +452,23 @@ Type maxMagSqr(const UList& f) TMP_UNARY_FUNCTION(Type, maxMagSqr) template -Type minMagSqr(const UList& f) +Type minMagSqr(const UList& f1) { - if (f.size()) + if (f1.size()) { - Type Min(f[0]); + Type result(f1[0]); TFOR_ALL_S_OP_FUNC_F_S ( Type, - Min, + result, =, minMagSqrOp(), Type, - f, + f1, Type, - Min + result ) - return Min; + return result; } return pTraits::rootMax; @@ -467,12 +480,12 @@ template typename scalarProduct::type sumProd(const UList& f1, const UList& f2) { - typedef typename scalarProduct::type prodType; + typedef typename scalarProduct::type resultType; - prodType result = Zero; + resultType result = Zero; if (f1.size() && (f1.size() == f2.size())) { - TFOR_ALL_S_OP_F_OP_F(prodType, result, +=, Type, f1, &&, Type, f2) + TFOR_ALL_S_OP_F_OP_F(resultType, result, +=, Type, f1, &&, Type, f2) } return result; } @@ -502,37 +515,39 @@ Type sumCmptProd(const UList& f1, const UList& f2) template typename outerProduct1::type -sumSqr(const UList& f) +sumSqr(const UList& f1) { - typedef typename outerProduct1::type prodType; - prodType result = Zero; - if (f.size()) + typedef typename outerProduct1::type resultType; + + resultType result = Zero; + if (f1.size()) { - TFOR_ALL_S_OP_FUNC_F(prodType, result, +=, sqr, Type, f) + TFOR_ALL_S_OP_FUNC_F(resultType, result, +=, sqr, Type, f1) } return result; } template typename outerProduct1::type -sumSqr(const tmp>& tf) +sumSqr(const tmp>& tf1) { - typedef typename outerProduct1::type prodType; - prodType result = sumSqr(tf()); - tf.clear(); + typedef typename outerProduct1::type resultType; + resultType result = sumSqr(tf1()); + tf1.clear(); return result; } template typename typeOfMag::type -sumMag(const UList& f) +sumMag(const UList& f1) { - typedef typename typeOfMag::type magType; - magType result = Zero; - if (f.size()) + typedef typename typeOfMag::type resultType; + + resultType result = Zero; + if (f1.size()) { - TFOR_ALL_S_OP_FUNC_F(magType, result, +=, mag, Type, f) + TFOR_ALL_S_OP_FUNC_F(resultType, result, +=, mag, Type, f1) } return result; } @@ -541,12 +556,12 @@ TMP_UNARY_FUNCTION(typename typeOfMag::type, sumMag) template -Type sumCmptMag(const UList& f) +Type sumCmptMag(const UList& f1) { Type result = Zero; - if (f.size()) + if (f1.size()) { - TFOR_ALL_S_OP_FUNC_F(Type, result, +=, cmptMag, Type, f) + TFOR_ALL_S_OP_FUNC_F(Type, result, +=, cmptMag, Type, f1) } return result; } @@ -554,13 +569,13 @@ Type sumCmptMag(const UList& f) TMP_UNARY_FUNCTION(Type, sumCmptMag) template -Type average(const UList& f) +Type average(const UList& f1) { - if (f.size()) + if (f1.size()) { - Type avrg = sum(f)/f.size(); + Type result = sum(f1)/f1.size(); - return avrg; + return result; } WarningInFunction @@ -608,10 +623,10 @@ typename scalarProduct::type gSumProd const label comm ) { - typedef typename scalarProduct::type prodType; + typedef typename scalarProduct::type resultType; - prodType result = sumProd(f1, f2); - reduce(result, sumOp(), UPstream::msgType(), comm); + resultType result = sumProd(f1, f2); + reduce(result, sumOp(), UPstream::msgType(), comm); return result; } @@ -623,27 +638,27 @@ Type gSumCmptProd const label comm ) { - Type SumProd = sumCmptProd(f1, f2); - reduce(SumProd, sumOp(), UPstream::msgType(), comm); - return SumProd; + Type result = sumCmptProd(f1, f2); + reduce(result, sumOp(), UPstream::msgType(), comm); + return result; } template Type gAverage ( - const UList& f, + const UList& f1, const label comm ) { - label n = f.size(); - Type s = sum(f); + label n = f1.size(); + Type s = sum(f1); sumReduce(s, n, UPstream::msgType(), comm); if (n > 0) { - Type avrg = s/n; + Type result = s/n; - return avrg; + return result; } WarningInFunction @@ -656,6 +671,8 @@ TMP_UNARY_FUNCTION(Type, gAverage) #undef TMP_UNARY_FUNCTION + +// Implement BINARY_FUNCTION_TRANSFORM_FS for clamp template void clamp ( @@ -664,55 +681,52 @@ void clamp const MinMax& range ) { + // Note: no checks for bad/invalid clamping ranges + if (result.cdata() == f1.cdata()) { // Apply in-place - result.clamp(range); + result.clamp_range(range); } else { - if (range.good()) - { - std::transform - ( - f1.cbegin(), - f1.cbegin(result.size()), - result.begin(), - clampOp(range) - ); - } - else - { - // No clamping - std::copy(f1.cbegin(), f1.cbegin(result.size()), result.begin()); - } + std::transform + ( + f1.cbegin(), + f1.cbegin(result.size()), + result.begin(), + clampOp(range) + ); } } template -tmp> clamp +void clamp ( + Field& result, const UList& f1, - const MinMax& range + const Foam::zero_one& // Note: macros generate a const reference ) { - auto tres = tmp>::New(f1.size()); - clamp(tres.ref(), f1, range); - return tres; + if (result.cdata() == f1.cdata()) + { + // Apply in-place + result.clamp_range(Foam::zero_one{}); + } + else + { + std::transform + ( + f1.cbegin(), + f1.cbegin(result.size()), + result.begin(), + clampOp(Foam::zero_one{}) + ); + } } -template -tmp> clamp -( - const tmp>& tf1, - const MinMax& range -) -{ - auto tres = reuseTmp::New(tf1); - clamp(tres.ref(), tf1(), range); - tf1.clear(); - return tres; -} +BINARY_FUNCTION_INTERFACE_FS(Type, Type, MinMax, clamp) +BINARY_FUNCTION_INTERFACE_FS(Type, Type, Foam::zero_one, clamp) BINARY_FUNCTION(Type, Type, Type, max) @@ -727,6 +741,11 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clip) // Same as clamp +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + /* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */ @@ -749,21 +768,21 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide) template \ void OpFunc \ ( \ - Field::type>& res, \ + Field::type>& result, \ const UList& f1, \ const UList& f2 \ ) \ { \ - typedef typename product::type productType; \ - TFOR_ALL_F_OP_F_OP_F(productType, res, =, Type1, f1, Op, Type2, f2) \ + typedef typename product::type resultType; \ + TFOR_ALL_F_OP_F_OP_F(resultType, result, =, Type1, f1, Op, Type2, f2) \ } \ \ template \ tmp::type>> \ operator Op(const UList& f1, const UList& f2) \ { \ - typedef typename product::type productType; \ - auto tres = tmp>::New(f1.size()); \ + typedef typename product::type resultType; \ + auto tres = tmp>::New(f1.size()); \ OpFunc(tres.ref(), f1, f2); \ return tres; \ } \ @@ -772,8 +791,8 @@ template \ tmp::type>> \ operator Op(const UList& f1, const tmp>& tf2) \ { \ - typedef typename product::type productType; \ - auto tres = reuseTmp::New(tf2); \ + typedef typename product::type resultType; \ + auto tres = reuseTmp::New(tf2); \ OpFunc(tres.ref(), f1, tf2()); \ tf2.clear(); \ return tres; \ @@ -783,8 +802,8 @@ template \ tmp::type>> \ operator Op(const tmp>& tf1, const UList& f2) \ { \ - typedef typename product::type productType; \ - auto tres = reuseTmp::New(tf1); \ + typedef typename product::type resultType; \ + auto tres = reuseTmp::New(tf1); \ OpFunc(tres.ref(), tf1(), f2); \ tf1.clear(); \ return tres; \ @@ -794,8 +813,8 @@ template \ tmp::type>> \ operator Op(const tmp>& tf1, const tmp>& tf2) \ { \ - typedef typename product::type productType; \ - auto tres = reuseTmpTmp::New(tf1, tf2); \ + typedef typename product::type resultType; \ + auto tres = reuseTmpTmp::New(tf1, tf2); \ OpFunc(tres.ref(), tf1(), tf2()); \ tf1.clear(); \ tf2.clear(); \ @@ -805,22 +824,22 @@ operator Op(const tmp>& tf1, const tmp>& tf2) \ template \ void OpFunc \ ( \ - Field::type>& res, \ + Field::type>& result, \ const UList& f1, \ const VectorSpace& vs \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ TFOR_ALL_F_OP_F_OP_S \ - (productType, res, =,Type, f1, Op, Form, static_cast(vs)) \ + (resultType, result, =,Type, f1, Op, Form, static_cast(vs))\ } \ \ template \ tmp::type>> \ operator Op(const UList& f1, const VectorSpace& vs) \ { \ - typedef typename product::type productType; \ - auto tres = tmp>::New(f1.size()); \ + typedef typename product::type resultType; \ + auto tres = tmp>::New(f1.size()); \ OpFunc(tres.ref(), f1, static_cast(vs)); \ return tres; \ } \ @@ -833,8 +852,8 @@ operator Op \ const VectorSpace& vs \ ) \ { \ - typedef typename product::type productType; \ - auto tres = reuseTmp::New(tf1); \ + typedef typename product::type resultType; \ + auto tres = reuseTmp::New(tf1); \ OpFunc(tres.ref(), tf1(), static_cast(vs)); \ tf1.clear(); \ return tres; \ @@ -843,22 +862,22 @@ operator Op \ template \ void OpFunc \ ( \ - Field::type>& res, \ + Field::type>& result, \ const VectorSpace& vs, \ const UList& f1 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ TFOR_ALL_F_OP_S_OP_F \ - (productType, res, =,Form,static_cast(vs), Op, Type, f1) \ + (resultType, result, =,Form,static_cast(vs), Op, Type, f1)\ } \ \ template \ tmp::type>> \ operator Op(const VectorSpace& vs, const UList& f1) \ { \ - typedef typename product::type productType; \ - auto tres = tmp>::New(f1.size()); \ + typedef typename product::type resultType; \ + auto tres = tmp>::New(f1.size()); \ OpFunc(tres.ref(), static_cast(vs), f1); \ return tres; \ } \ @@ -870,8 +889,8 @@ operator Op \ const VectorSpace& vs, const tmp>& tf1 \ ) \ { \ - typedef typename product::type productType; \ - auto tres = reuseTmp::New(tf1); \ + typedef typename product::type resultType; \ + auto tres = reuseTmp::New(tf1); \ OpFunc(tres.ref(), static_cast(vs), tf1()); \ tf1.clear(); \ return tres; \ diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H index 57a0c5db18..6ed4076872 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H @@ -314,8 +314,14 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) +BINARY_TYPE_FUNCTION_FS(Type, Type, Foam::zero_one, clamp) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clip) // Same as clamp +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C index 59b7a1fd24..39829843ab 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,77 +31,99 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define UNARY_FUNCTION(ReturnType, Type, Func) \ - \ -TEMPLATE \ -void Func(Field& res, const UList& f) \ -{ \ - TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f) \ -} \ - \ -TEMPLATE \ -tmp> Func(const UList& f) \ -{ \ - auto tres = tmp>::New(f.size()); \ - Func(tres.ref(), f); \ - return tres; \ -} \ - \ -TEMPLATE \ -tmp> Func(const tmp>& tf) \ -{ \ - auto tres = reuseTmp::New(tf); \ - Func(tres.ref(), tf()); \ - tf.clear(); \ - return tres; \ -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \ - \ -TEMPLATE \ -void OpFunc(Field& res, const UList& f) \ -{ \ - TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f) \ -} \ - \ -TEMPLATE \ -tmp> operator Op(const UList& f) \ -{ \ - auto tres = tmp>::New(f.size()); \ - OpFunc(tres.ref(), f); \ - return tres; \ -} \ - \ -TEMPLATE \ -tmp> operator Op(const tmp>& tf) \ -{ \ - auto tres = reuseTmp::New(tf); \ - OpFunc(tres.ref(), tf()); \ - tf.clear(); \ - return tres; \ -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ +#define UNARY_FUNCTION(ReturnType, Type1, Func) \ \ TEMPLATE \ void Func \ ( \ - Field& res, \ + Field& result, \ + const UList& f1 \ +) \ +{ \ + TFOR_ALL_F_OP_FUNC_F(ReturnType, result, =, ::Foam::Func, Type1, f1) \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1 \ +) \ +{ \ + auto tres = tmp>::New(f1.size()); \ + Func(tres.ref(), f1); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1 \ +) \ +{ \ + auto tres = reuseTmp::New(tf1); \ + Func(tres.ref(), tf1()); \ + tf1.clear(); \ + return tres; \ +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc) \ + \ +TEMPLATE \ +void OpFunc \ +( \ + Field& result, \ + const UList& f1 \ +) \ +{ \ + TFOR_ALL_F_OP_OP_F(ReturnType, result, =, Op, Type1, f1) \ +} \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const UList& f1 \ +) \ +{ \ + auto tres = tmp>::New(f1.size()); \ + OpFunc(tres.ref(), f1); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1 \ +) \ +{ \ + auto tres = reuseTmp::New(tf1); \ + OpFunc(tres.ref(), tf1()); \ + tf1.clear(); \ + return tres; \ +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define BINARY_FUNCTION_TRANSFORM(ReturnType, Type1, Type2, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + Field& result, \ const UList& f1, \ const UList& f2 \ ) \ { \ TFOR_ALL_F_OP_FUNC_F_F \ ( \ - ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2 \ + ReturnType, result, =, ::Foam::Func, Type1, f1, Type2, f2 \ ) \ -} \ +} + +#define BINARY_FUNCTION_INTERFACE(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ tmp> Func \ @@ -155,24 +177,30 @@ tmp> Func \ return tres; \ } +#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_TRANSFORM(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_INTERFACE(ReturnType, Type1, Type2, Func) + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ +#define BINARY_FUNCTION_TRANSFORM_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ - Field& res, \ + Field& result, \ const Type1& s1, \ const UList& f2 \ ) \ { \ TFOR_ALL_F_OP_FUNC_S_F \ ( \ - ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \ + ReturnType, result, =, ::Foam::Func, Type1, s1, Type2, f2 \ ) \ -} \ +} + +#define BINARY_FUNCTION_INTERFACE_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ tmp> Func \ @@ -199,22 +227,28 @@ tmp> Func \ return tres; \ } +#define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_TRANSFORM_SF(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_INTERFACE_SF(ReturnType, Type1, Type2, Func) -#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ + +#define BINARY_FUNCTION_TRANSFORM_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ - Field& res, \ + Field& result, \ const UList& f1, \ const Type2& s2 \ ) \ { \ TFOR_ALL_F_OP_FUNC_F_S \ ( \ - ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \ + ReturnType, result, =, ::Foam::Func, Type1, f1, Type2, s2 \ ) \ -} \ +} + +#define BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ tmp> Func \ @@ -241,6 +275,10 @@ tmp> Func \ return tres; \ } +#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_TRANSFORM_FS(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func) + #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \ BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ @@ -254,12 +292,12 @@ tmp> Func \ TEMPLATE \ void OpFunc \ ( \ - Field& res, \ + Field& result, \ const UList& f1, \ const UList& f2 \ ) \ { \ - TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \ + TFOR_ALL_F_OP_F_OP_F(ReturnType, result, =, Type1, f1, Op, Type2, f2) \ } \ \ TEMPLATE \ @@ -322,12 +360,12 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - Field& res, \ + Field& result, \ const Type1& s1, \ const UList& f2 \ ) \ { \ - TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \ + TFOR_ALL_F_OP_S_OP_F(ReturnType, result, =, Type1, s1, Op, Type2, f2) \ } \ \ TEMPLATE \ @@ -361,12 +399,12 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - Field& res, \ + Field& result, \ const UList& f1, \ const Type2& s2 \ ) \ { \ - TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \ + TFOR_ALL_F_OP_F_OP_S(ReturnType, result, =, Type1, f1, Op, Type2, s2) \ } \ \ TEMPLATE \ @@ -400,4 +438,215 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + Field& result, \ + const UList& f1, \ + const UList& f2, \ + const UList& f3 \ +) \ +{ \ + TFOR_ALL_F_OP_FUNC_F_F_F \ + ( \ + ReturnType, result, =, ::Foam::Func, Type1, f1, Type2, f2, Type3, f3 \ + ) \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2, \ + const UList& f3 \ +) \ +{ \ + auto tres = tmp>::New(f1.size()); \ + Func(tres.ref(), f1, f2, f3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2, \ + const UList& f3 \ +) \ +{ \ + auto tres = reuseTmp::New(tf1); \ + Func(tres.ref(), tf1(), f2, f3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2, \ + const UList& f3 \ +) \ +{ \ + auto tres = reuseTmp::New(tf2); \ + Func(tres.ref(), f1, tf2(), f3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2, \ + const tmp>& tf3 \ +) \ +{ \ + auto tres = reuseTmp::New(tf3); \ + Func(tres.ref(), f1, f2, tf3()); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const UList& f3 \ +) \ +{ \ + auto tres = reuseTmpTmp::New(tf1, tf2); \ + Func(tres.ref(), tf1(), tf2(), f3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2, \ + const tmp>& tf3 \ +) \ +{ \ + auto tres = reuseTmpTmp::New(tf1, tf3); \ + Func(tres.ref(), tf1(), f2, tf3()); \ + tf1.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + auto tres = reuseTmpTmp::New(tf2, tf3); \ + Func(tres.ref(), f1, tf2(), tf3()); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + /* TBD: check all three types? */ \ + auto tres = reuseTmpTmp::New(tf1, tf2); \ + Func(tres.ref(), tf1(), tf2(), tf3()); \ + tf1.clear(); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + Field& result, \ + const UList& f1, \ + const UList& f2, \ + const Type3& s3 \ +) \ +{ \ + TFOR_ALL_F_OP_FUNC_F_F_S \ + ( \ + ReturnType, result, =, ::Foam::Func, Type1, f1, Type2, f2, Type3, s3 \ + ) \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = tmp>::New(f1.size()); \ + Func(tres.ref(), f1, f2, s3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = reuseTmp::New(tf1); \ + Func(tres.ref(), tf1(), f2, s3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = reuseTmp::New(tf2); \ + Func(tres.ref(), f1, tf2(), s3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + auto tres = reuseTmpTmp::New(tf1, tf2); \ + Func(tres.ref(), tf1(), tf2(), s3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.H index f975bffa52..e8fcb52c5e 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,9 +25,7 @@ License along with OpenFOAM. If not, see . Description - High performance macro functions for Field\ algebra. These expand - using either array element access (for vector machines) or pointer - dereferencing for scalar machines as appropriate. + Macro functions for Field\ algebra. \*---------------------------------------------------------------------------*/ @@ -35,11 +34,13 @@ Description #define UNARY_FUNCTION(ReturnType, Type1, Func) \ \ TEMPLATE \ -void Func(Field& res, const UList& f); \ +void Func(Field& result, const UList& f1); \ + \ TEMPLATE \ -tmp> Func(const UList& f); \ +tmp> Func(const UList& f1); \ + \ TEMPLATE \ -tmp> Func(const tmp>& tf); +tmp> Func(const tmp>& tf1); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,65 +48,74 @@ tmp> Func(const tmp>& tf); #define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc) \ \ TEMPLATE \ -void OpFunc(Field& res, const UList& f); \ +void OpFunc(Field& res, const UList& f1); \ + \ TEMPLATE \ -tmp> operator Op(const UList& f); \ +tmp> operator Op(const UList& f1); \ + \ TEMPLATE \ -tmp> operator Op(const tmp>& tf); +tmp> operator Op(const tmp>& tf1); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#define BINARY_FUNCTION_TRANSFORM(ReturnType, Type1, Type2, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + Field& result, \ + const UList& f1, \ + const UList& f2 \ +); + +#define BINARY_FUNCTION_INTERFACE(ReturnType, Type1, Type2, Func) \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2 \ +); + #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ - \ -TEMPLATE \ -void Func \ -( \ - Field& f, \ - const UList& f1, \ - const UList& f2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const UList& f1, \ - const UList& f2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const UList& f1, \ - const tmp>& tf2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const tmp>& tf1, \ - const UList& f2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const tmp>& tf1, \ - const tmp>& tf2 \ -); - + BINARY_FUNCTION_TRANSFORM(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_INTERFACE(ReturnType, Type1, Type2, Func) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ +#define BINARY_FUNCTION_TRANSFORM_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ - Field& f, \ + Field& result, \ const Type1& s1, \ const UList& f2 \ -); \ +); + +#define BINARY_FUNCTION_INTERFACE_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ tmp> Func \ @@ -121,16 +131,22 @@ tmp> Func \ const tmp>& tf2 \ ); +#define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_TRANSFORM_SF(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_INTERFACE_SF(ReturnType, Type1, Type2, Func) -#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ + +#define BINARY_FUNCTION_TRANSFORM_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ - Field& f, \ + Field& result, \ const UList& f1, \ const Type2& s2 \ -); \ +); + +#define BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ tmp> Func \ @@ -146,6 +162,10 @@ tmp> Func \ const Type2& s2 \ ); +#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_TRANSFORM_FS(ReturnType, Type1, Type2, Func) \ + BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func) + #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \ BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ @@ -159,7 +179,7 @@ tmp> Func \ TEMPLATE \ void OpFunc \ ( \ - Field& f, \ + Field& result, \ const UList& f1, \ const UList& f2 \ ); \ @@ -200,7 +220,7 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - Field& f, \ + Field& result, \ const Type1& s1, \ const UList& f2 \ ); \ @@ -225,7 +245,7 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - Field& f, \ + Field& result, \ const UList& f1, \ const Type2& s2 \ ); \ @@ -250,4 +270,136 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + Field& result, \ + const UList& f1, \ + const UList& f2, \ + const UList& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2, \ + const UList& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2, \ + const UList& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2, \ + const UList& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const UList& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Permutations of ternary functions taking non-field argument(s) +// +// FFS (defined) +// FSF (not defined) +// SFF (not defined) +// SSF (not defined) +// SFS (not defined) +// FSS (not defined) + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + Field& result, \ + const UList& f1, \ + const UList& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const UList& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const UList& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const UList& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/Field/FieldM.H b/src/OpenFOAM/fields/Fields/Field/FieldM.H index 307796eae3..0cb9072bfd 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldM.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldM.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,9 +25,7 @@ License along with OpenFOAM. If not, see . Description - High performance macro functions for Field\ algebra. These expand - using either array element access (for vector machines) or pointer - dereferencing for scalar machines as appropriate. + Declaration macros for Field\ algebra. \*---------------------------------------------------------------------------*/ @@ -86,6 +84,34 @@ void checkFields } } +template +void checkFields +( + const UList& f1, + const UList& f2, + const UList& f3, + const UList& f4, + const char* op +) +{ + if + ( + f1.size() != f2.size() + || f1.size() != f3.size() + || f1.size() != f4.size() + ) + { + FatalErrorInFunction + << " Field<"<::typeName<<"> f1("<::typeName<<"> f2("<::typeName<<"> f3("<::typeName<<"> f4("< @@ -107,12 +133,23 @@ void checkFields ) {} +template +void checkFields +( + const UList&, + const UList&, + const UList&, + const UList&, + const char* +) +{} + #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Member function : f1 OP Func f2 +// Unary Free Function : f1 OP Func f2 #define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2) \ \ @@ -133,7 +170,7 @@ void checkFields } -// Member function : this f1 OP f2.FUNC() +// Nullary Member Function : f1 OP f2.FUNC() #define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC) \ \ @@ -154,7 +191,7 @@ void checkFields } -// Member function : this field f1 OP FUNC(f2, f3) +// Binary Free Function : f1 OP FUNC(f2, f3) #define TFOR_ALL_F_OP_FUNC_F_F(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3) \ \ @@ -176,7 +213,7 @@ void checkFields } -// Member function : s OP FUNC(f1, f2) +// [reduction] Binary Free Function : s OP FUNC(f1, f2) #define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2) \ \ @@ -197,7 +234,7 @@ void checkFields } -// Member function : this f1 OP FUNC(f2, s) +// Binary Free Function : f1 OP FUNC(f2, s) #define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s) \ \ @@ -218,7 +255,7 @@ void checkFields } -// Member function : s1 OP FUNC(f, s2) +// [reduction] Binary Free Function : s1 OP FUNC(f, s2) #define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2) \ \ @@ -235,7 +272,7 @@ void checkFields } -// Member function : this f1 OP FUNC(s, f2) +// Binary Free Function : f1 OP FUNC(s, f2) #define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2) \ \ @@ -256,7 +293,7 @@ void checkFields } -// Member function : this f1 OP FUNC(s1, s2) +// Binary Free Function : f1 OP FUNC(s1, s2) #define TFOR_ALL_F_OP_FUNC_S_S(typeF1, f1, OP, FUNC, typeS1, s1, typeS2, s2) \ \ @@ -273,7 +310,7 @@ void checkFields } -// Member function : this f1 OP f2 FUNC(s) +// Unary Member Function : f1 OP f2 FUNC(s) #define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s) \ \ @@ -294,6 +331,56 @@ void checkFields } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Ternary Free Function : f1 OP FUNC(f2, f3, f4) + +#define TFOR_ALL_F_OP_FUNC_F_F_F\ +(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3, typeF4, f4) \ + \ + /* Check fields have same size */ \ + checkFields(f1, f2, f3, f4, "f1 " #OP " " #FUNC "(f2, f3, f4)"); \ + \ + /* Field access */ \ + List_ACCESS(typeF1, f1, f1P); \ + List_CONST_ACCESS(typeF2, f2, f2P); \ + List_CONST_ACCESS(typeF3, f3, f3P); \ + List_CONST_ACCESS(typeF4, f4, f4P); \ + \ + /* Loop: f1 OP FUNC(f2, f3, f4) */ \ + const label loopLen = (f1).size(); \ + \ + /* pragmas... */ \ + for (label i = 0; i < loopLen; ++i) \ + { \ + (f1P[i]) OP FUNC((f2P[i]), (f3P[i]), (f4P[i])); \ + } + +// Ternary Free Function : f1 OP FUNC(f2, f3, s4) + +#define TFOR_ALL_F_OP_FUNC_F_F_S\ +(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3, typeF4, s4) \ + \ + /* Check fields have same size */ \ + checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3, s)"); \ + \ + /* Field access */ \ + List_ACCESS(typeF1, f1, f1P); \ + List_CONST_ACCESS(typeF2, f2, f2P); \ + List_CONST_ACCESS(typeF3, f3, f3P); \ + \ + /* Loop: f1 OP FUNC(f2, f3, s4) */ \ + const label loopLen = (f1).size(); \ + \ + /* pragmas... */ \ + for (label i = 0; i < loopLen; ++i) \ + { \ + (f1P[i]) OP FUNC((f2P[i]), (f3P[i]), (s4)); \ + } + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // Member operator : this field f1 OP1 f2 OP2 f3 #define TFOR_ALL_F_OP_F_OP_F(typeF1, f1, OP1, typeF2, f2, OP2, typeF3, f3) \ diff --git a/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H index d05c15d427..0d23585fe9 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,10 +35,18 @@ namespace Foam { // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// One-parameter versions template struct reuseTmp { + //- Pass-through to tmp New + static tmp> New(const Field& f1) + { + return tmp>::New(f1.size()); + } + + //- Dissimilar types: just use size static tmp> New(const tmp>& tf1) { return tmp>::New(tf1().size()); @@ -49,8 +57,8 @@ struct reuseTmp template struct reuseTmp { - //- Allow optional copy assignment of the initial content - //- for identical input and output types + //- Identical input and return types: + //- allow optional copy assignment of the initial content static tmp> New ( const tmp>& tf1, @@ -85,9 +93,13 @@ template tmp> New } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Two-parameter versions + template struct reuseTmpTmp { + //- Dissimilar types: just use size static tmp> New ( const tmp>& tf1, @@ -102,6 +114,7 @@ struct reuseTmpTmp template struct reuseTmpTmp { + //- Second input has return type static tmp> New ( const tmp>& tf1, @@ -121,6 +134,7 @@ struct reuseTmpTmp template struct reuseTmpTmp { + //- First input has return type static tmp> New ( const tmp>& tf1, @@ -140,6 +154,7 @@ struct reuseTmpTmp template struct reuseTmpTmp { + //- Both inputs have return type static tmp> New ( const tmp>& tf1, diff --git a/src/OpenFOAM/fields/Fields/Field/undefFieldFunctionsM.H b/src/OpenFOAM/fields/Fields/Field/undefFieldFunctionsM.H index 3eb660e382..0a1e1cc9d3 100644 --- a/src/OpenFOAM/fields/Fields/Field/undefFieldFunctionsM.H +++ b/src/OpenFOAM/fields/Fields/Field/undefFieldFunctionsM.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,20 +27,40 @@ License \*---------------------------------------------------------------------------*/ #undef UNARY_FUNCTION +#undef UNARY_FUNCTION_TRANSFORM +#undef UNARY_FUNCTION_INTERFACE #undef UNARY_OPERATOR +#undef UNARY_OPERATOR_TRANSFORM +#undef UNARY_OPERATOR_INTERFACE #undef BINARY_FUNCTION +#undef BINARY_FUNCTION_TRANSFORM +#undef BINARY_FUNCTION_INTERFACE +#undef BINARY_TYPE_FUNCTION #undef BINARY_TYPE_FUNCTION_SF #undef BINARY_TYPE_FUNCTION_FS -#undef BINARY_TYPE_FUNCTION +#undef BINARY_FUNCTION_TRANSFORM_SF +#undef BINARY_FUNCTION_INTERFACE_SF +#undef BINARY_FUNCTION_TRANSFORM_FS +#undef BINARY_FUNCTION_INTERFACE_FS #undef BINARY_OPERATOR - +#undef BINARY_TYPE_OPERATOR #undef BINARY_TYPE_OPERATOR_SF #undef BINARY_TYPE_OPERATOR_FS -#undef BINARY_TYPE_OPERATOR + +#undef TERNARY_FUNCTION +#undef TERNARY_FUNCTION_TRANSFORM +#undef TERNARY_FUNCTION_INTERFACE +#undef TERNARY_TYPE_FUNCTION +#undef TERNARY_TYPE_FUNCTION_FFS +#undef TERNARY_TYPE_FUNCTION_FSF +#undef TERNARY_TYPE_FUNCTION_SFF +#undef TERNARY_TYPE_FUNCTION_SSF +#undef TERNARY_TYPE_FUNCTION_SFS +#undef TERNARY_TYPE_FUNCTION_FSS #undef TEMPLATE diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index 0f39b3f116..af2ef82dd9 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -1249,50 +1249,6 @@ void Foam::GeometricField::replace } -template class PatchField, class GeoMesh> -void Foam::GeometricField::clamp -( - const Type& lower, - const Type& upper -) -{ - primitiveFieldRef().clamp(lower, upper); - boundaryFieldRef().clamp(lower, upper); -} - - -template class PatchField, class GeoMesh> -void Foam::GeometricField::clamp -( - const MinMax& range -) -{ - primitiveFieldRef().clamp(range.min(), range.max()); - boundaryFieldRef().clamp(range.min(), range.max()); -} - - -template class PatchField, class GeoMesh> -void Foam::GeometricField::clamp -( - const dimensioned& lower, - const dimensioned& upper -) -{ - this->clamp(lower.value(), upper.value()); -} - - -template class PatchField, class GeoMesh> -void Foam::GeometricField::clamp -( - const dimensioned>& range -) -{ - this->clamp(range.value()); -} - - template class PatchField, class GeoMesh> void Foam::GeometricField::clamp_min ( @@ -1335,6 +1291,50 @@ void Foam::GeometricField::clamp_max } +template class PatchField, class GeoMesh> +void Foam::GeometricField::clamp_range +( + const Type& lower, + const Type& upper +) +{ + primitiveFieldRef().clamp_range(lower, upper); + boundaryFieldRef().clamp_range(lower, upper); +} + + +template class PatchField, class GeoMesh> +void Foam::GeometricField::clamp_range +( + const MinMax& range +) +{ + primitiveFieldRef().clamp_range(range.min(), range.max()); + boundaryFieldRef().clamp_range(range.min(), range.max()); +} + + +template class PatchField, class GeoMesh> +void Foam::GeometricField::clamp_range +( + const dimensioned& lower, + const dimensioned& upper +) +{ + this->clamp_range(lower.value(), upper.value()); +} + + +template class PatchField, class GeoMesh> +void Foam::GeometricField::clamp_range +( + const dimensioned>& range +) +{ + this->clamp_range(range.value()); +} + + template class PatchField, class GeoMesh> void Foam::GeometricField::negate() { diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index cf4a09c683..d7fffa0d23 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -629,26 +629,6 @@ public: const dimensioned& ds ); - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. - void clamp(const Type& lower, const Type& upper); - - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. - void clamp(const MinMax& range); - - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. No dimension checking. - void clamp - ( - const dimensioned& lower, - const dimensioned& upper - ); - - //- Clamp field values (in-place) to the specified range. - // A no-op for an invalid range. No dimension checking. - void clamp(const dimensioned>& range); - //- Impose lower (floor) clamp on the field values (in-place) void clamp_min(const Type& lower); @@ -663,6 +643,26 @@ public: // No dimension checking void clamp_max(const dimensioned& upper); + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. No dimension checking. + void clamp_range(const dimensioned>& range); + + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. + void clamp_range(const Type& lower, const Type& upper); + + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. + void clamp_range(const MinMax& range); + + //- Clamp field values (in-place) to the specified range. + // Does not check if range is valid or not. No dimension checking. + void clamp_range + ( + const dimensioned& lower, + const dimensioned& upper + ); + // Member Operators @@ -715,17 +715,17 @@ public: // Housekeeping //- Clamp field values (in-place) to the specified range. - // \deprecated(2023-01) prefer clamp() naming + // \deprecated(2023-01) prefer clamp_range() naming void clip(const dimensioned>& range) { - this->clamp(range); + this->clamp_range(range); } //- Clamp field values (in-place) to the specified range. - // \deprecated(2023-01) prefer clamp() naming + // \deprecated(2023-01) prefer clamp_range() naming void clip(const dimensioned& lo, const dimensioned& hi) { - this->clamp(lo.value(), hi.value()); + this->clamp_range(lo.value(), hi.value()); } //- Use minimum of the field and specified value. ie, clamp_max(). @@ -738,12 +738,12 @@ public: // \deprecated(2023-01) prefer clamp_min() void max(const dimensioned& lower) { this->clamp_min(lower); } - //- Deprecated(2019-01) identical to clamp() - // \deprecated(2019-01) identical to clamp() - FOAM_DEPRECATED_FOR(2019-01, "clamp() method") + //- Deprecated(2019-01) identical to clamp_range() + // \deprecated(2019-01) identical to clamp_range() + FOAM_DEPRECATED_FOR(2019-01, "clamp_range() method") void maxMin(const dimensioned& lo, const dimensioned& hi) { - return this->clamp(lo.value(), hi.value()); + return this->clamp_range(lo.value(), hi.value()); } }; diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C index f6eb4fafd5..18d2b0cdeb 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,7 +37,7 @@ License namespace Foam { -// * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template class PatchField, class GeoMesh> void component @@ -47,27 +47,27 @@ void component typename GeometricField::cmptType, PatchField, GeoMesh - >& gcf, - const GeometricField& gf, + >& result, + const GeometricField& f1, const direction d ) { - component(gcf.primitiveFieldRef(), gf.primitiveField(), d); - component(gcf.boundaryFieldRef(), gf.boundaryField(), d); - gcf.oriented() = gf.oriented(); + component(result.primitiveFieldRef(), f1.primitiveField(), d); + component(result.boundaryFieldRef(), f1.boundaryField(), d); + result.oriented() = f1.oriented(); } template class PatchField, class GeoMesh> void T ( - GeometricField& gf, - const GeometricField& gf1 + GeometricField& result, + const GeometricField& f1 ) { - T(gf.primitiveFieldRef(), gf1.primitiveField()); - T(gf.boundaryFieldRef(), gf1.boundaryField()); - gf.oriented() = gf1.oriented(); + T(result.primitiveFieldRef(), f1.primitiveField()); + T(result.boundaryFieldRef(), f1.boundaryField()); + result.oriented() = f1.oriented(); } @@ -80,13 +80,14 @@ template > void pow ( - GeometricField::type, PatchField, GeoMesh>& gf, - const GeometricField& gf1 + GeometricField + ::type, PatchField, GeoMesh>& result, + const GeometricField& f1 ) { - pow(gf.primitiveFieldRef(), gf1.primitiveField(), r); - pow(gf.boundaryFieldRef(), gf1.boundaryField(), r); - gf.oriented() = pow(gf1.oriented(), r); + pow(result.primitiveFieldRef(), f1.primitiveField(), r); + pow(result.boundaryFieldRef(), f1.boundaryField(), r); + result.oriented() = pow(f1.oriented(), r); } @@ -100,28 +101,21 @@ template tmp::type, PatchField, GeoMesh>> pow ( - const GeometricField& gf, + const GeometricField& f1, typename powProduct::type ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "pow(" + gf.name() + ',' + name(r) + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - pow(gf.dimensions(), r) + f1, + "pow(" + f1.name() + ',' + Foam::name(r) + ')', + pow(f1.dimensions(), r) ); - pow(tres.ref(), gf); + pow(tres.ref(), f1); return tres; } @@ -137,32 +131,25 @@ template tmp::type, PatchField, GeoMesh>> pow ( - const tmp>& tgf, + const tmp>& tf1, typename powProduct::type ) { - typedef typename powProduct::type powProductType; + typedef typename powProduct::type resultType; - const GeometricField& gf = tgf(); + const auto& f1 = tf1(); auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "pow(" + gf.name() + ',' + name(r) + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - pow(gf.dimensions(), r) + tf1, + "pow(" + f1.name() + ',' + Foam::name(r) + ')', + pow(f1.dimensions(), r) ); - pow(tres.ref(), gf); + pow(tres.ref(), f1); - tgf.clear(); + tf1.clear(); return tres; } @@ -171,13 +158,15 @@ template class PatchField, class GeoMesh> void sqr ( GeometricField - ::type, PatchField, GeoMesh>& gf, - const GeometricField& gf1 + < + typename outerProduct::type, PatchField, GeoMesh + >& result, + const GeometricField& f1 ) { - sqr(gf.primitiveFieldRef(), gf1.primitiveField()); - sqr(gf.boundaryFieldRef(), gf1.boundaryField()); - gf.oriented() = sqr(gf1.oriented()); + sqr(result.primitiveFieldRef(), f1.primitiveField()); + sqr(result.boundaryFieldRef(), f1.boundaryField()); + result.oriented() = sqr(f1.oriented()); } @@ -191,26 +180,19 @@ tmp GeoMesh > > -sqr(const GeometricField& gf) +sqr(const GeometricField& f1) { - typedef typename outerProduct::type outerProductType; + typedef typename outerProduct::type resultType; auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "sqr(" + gf.name() + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - sqr(gf.dimensions()) + f1, + "sqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - sqr(tres.ref(), gf); + sqr(tres.ref(), f1); return tres; } @@ -226,31 +208,23 @@ tmp GeoMesh > > -sqr(const tmp>& tgf) +sqr(const tmp>& tf1) { - typedef typename outerProduct::type outerProductType; + typedef typename outerProduct::type resultType; - const GeometricField& gf = tgf(); + const auto& f1 = tf1(); auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "sqr(" + gf.name() + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - sqr(gf.dimensions()) + tf1, + "sqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - sqr(tres.ref(), gf); - - tgf.clear(); + sqr(tres.ref(), f1); + tf1.clear(); return tres; } @@ -258,13 +232,13 @@ sqr(const tmp>& tgf) template class PatchField, class GeoMesh> void magSqr ( - GeometricField::type, PatchField, GeoMesh>& gsf, - const GeometricField& gf + GeometricField::type, PatchField, GeoMesh>& result, + const GeometricField& f1 ) { - magSqr(gsf.primitiveFieldRef(), gf.primitiveField()); - magSqr(gsf.boundaryFieldRef(), gf.boundaryField()); - gsf.oriented() = magSqr(gf.oriented()); + magSqr(result.primitiveFieldRef(), f1.primitiveField()); + magSqr(result.boundaryFieldRef(), f1.boundaryField()); + result.oriented() = magSqr(f1.oriented()); } @@ -272,27 +246,20 @@ template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> magSqr ( - const GeometricField& gf + const GeometricField& f1 ) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "magSqr(" + gf.name() + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - sqr(gf.dimensions()) + f1, + "magSqr(" + f1.name() + ')', + sqr(f1.dimensions()) ); - magSqr(tres.ref(), gf); + magSqr(tres.ref(), f1); return tres; } @@ -301,11 +268,11 @@ template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> magSqr ( - const tmp>& tgf + const tmp>& tf1 ) { - auto tres = magSqr(tgf.cref()); - tgf.clear(); + auto tres = magSqr(tf1.cref()); + tf1.clear(); return tres; } @@ -314,13 +281,13 @@ magSqr template class PatchField, class GeoMesh> void mag ( - GeometricField::type, PatchField, GeoMesh>& gsf, - const GeometricField& gf + GeometricField::type, PatchField, GeoMesh>& result, + const GeometricField& f1 ) { - mag(gsf.primitiveFieldRef(), gf.primitiveField()); - mag(gsf.boundaryFieldRef(), gf.boundaryField()); - gsf.oriented() = mag(gf.oriented()); + mag(result.primitiveFieldRef(), f1.primitiveField()); + mag(result.boundaryFieldRef(), f1.boundaryField()); + result.oriented() = mag(f1.oriented()); } @@ -328,27 +295,20 @@ template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> mag ( - const GeometricField& gf + const GeometricField& f1 ) { - typedef typename typeOfMag::type magType; + typedef typename typeOfMag::type resultType; auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "mag(" + gf.name() + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - gf.dimensions() + f1, + "mag(" + f1.name() + ')', + f1.dimensions() ); - mag(tres.ref(), gf); + mag(tres.ref(), f1); return tres; } @@ -357,11 +317,11 @@ template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> mag ( - const tmp>& tgf + const tmp>& tf1 ) { - auto tres = mag(tgf.cref()); - tgf.clear(); + auto tres = mag(tf1.cref()); + tf1.clear(); return tres; } @@ -375,13 +335,13 @@ void cmptAv typename GeometricField::cmptType, PatchField, GeoMesh - >& gcf, - const GeometricField& gf + >& result, + const GeometricField& f1 ) { - cmptAv(gcf.primitiveFieldRef(), gf.primitiveField()); - cmptAv(gcf.boundaryFieldRef(), gf.boundaryField()); - gcf.oriented() = cmptAv(gf.oriented()); + cmptAv(result.primitiveFieldRef(), f1.primitiveField()); + cmptAv(result.boundaryFieldRef(), f1.boundaryField()); + result.oriented() = cmptAv(f1.oriented()); } template class PatchField, class GeoMesh> @@ -394,27 +354,20 @@ tmp GeoMesh > > -cmptAv(const GeometricField& gf) +cmptAv(const GeometricField& f1) { - typedef typename GeometricField::cmptType - cmptType; + typedef typename + GeometricField::cmptType resultType; auto tres = - tmp>::New + reuseTmpGeometricField::New ( - IOobject - ( - "cmptAv(" + gf.name() + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - gf.dimensions() + f1, + "cmptAv(" + f1.name() + ')', + f1.dimensions() ); - cmptAv(tres.ref(), gf); + cmptAv(tres.ref(), f1); return tres; } @@ -430,68 +383,47 @@ tmp GeoMesh > > -cmptAv(const tmp>& tgf) +cmptAv(const tmp>& tf1) { - typedef typename GeometricField::cmptType - cmptType; - - const GeometricField& gf = tgf(); - - auto tres = - tmp>::New - ( - IOobject - ( - "cmptAv(" + gf.name() + ')', - gf.instance(), - gf.db(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - gf.mesh(), - gf.dimensions() - ); - - cmptAv(tres.ref(), gf); - - tgf.clear(); + auto tres = cmptAv(tf1.cref()); + tf1.clear(); return tres; } -#define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(returnType, func, binaryOp) \ +#define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(ReturnType, Func, BinaryOp) \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const GeometricField& gf \ + const GeometricField& f1 \ ) \ { \ - return dimensioned \ + return dimensioned \ ( \ - #func "(" + gf.name() + ')', \ - gf.dimensions(), \ + #Func "(" + f1.name() + ')', \ + f1.dimensions(), \ returnReduce \ ( \ - Foam::func \ + Foam::Func \ ( \ - Foam::func(gf.primitiveField()), \ - Foam::func(gf.boundaryField()) \ + Foam::Func(f1.primitiveField()), \ + Foam::Func(f1.boundaryField()) \ ), \ - binaryOp() \ + BinaryOp() \ ) \ ); \ } \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const tmp>& tgf1 \ + const tmp>& tf1 \ ) \ { \ - dimensioned res = func(tgf1()); \ - tgf1.clear(); \ + dimensioned res = Func(tf1()); \ + tf1.clear(); \ return res; \ } @@ -503,30 +435,30 @@ UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, minMaxMagOp) #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY -#define UNARY_REDUCTION_FUNCTION(returnType, func, gFunc) \ +#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const GeometricField& gf \ + const GeometricField& f1 \ ) \ { \ - return dimensioned \ + return dimensioned \ ( \ - #func "(" + gf.name() + ')', \ - gf.dimensions(), \ - gFunc(gf.primitiveField()) \ + #Func "(" + f1.name() + ')', \ + f1.dimensions(), \ + gFunc(f1.primitiveField()) \ ); \ } \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const tmp>& tgf1 \ + const tmp>& tf1 \ ) \ { \ - dimensioned res = func(tgf1()); \ - tgf1.clear(); \ + dimensioned res = Func(tf1()); \ + tf1.clear(); \ return res; \ } @@ -548,7 +480,81 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// ------------------------------------------------------------------------- // + +// Clamp Methods + +template class PatchField, class GeoMesh> +void clamp +( + GeometricField& result, + const GeometricField& f1, + const Foam::zero_one +) +{ + const MinMax range(Foam::zero_one{}); + + clamp(result.primitiveFieldRef(), f1.primitiveField(), range); + clamp(result.boundaryFieldRef(), f1.boundaryField(), range); + result.oriented() = f1.oriented(); +} + +template class PatchField, class GeoMesh> +tmp> +clamp +( + const GeometricField& f1, + const Foam::zero_one +) +{ + auto tres = + reuseTmpGeometricField::New + ( + f1, + "clamp01(" + f1.name() + ')', + f1.dimensions() + ); + + clamp(tres.ref(), f1, Foam::zero_one{}); + + return tres; +} + + +template class PatchField, class GeoMesh> +tmp> +clamp +( + const tmp>& tf1, + const Foam::zero_one +) +{ + const auto& f1 = tf1(); + + auto tres = + reuseTmpGeometricField::New + ( + tf1, + "clamp01(" + f1.name() + ')', + f1.dimensions() + ); + + clamp(tres.ref(), f1, Foam::zero_one{}); + + tf1.clear(); + return tres; +} + +BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -564,64 +570,58 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define PRODUCT_OPERATOR(product, op, opFunc) \ +#define PRODUCT_OPERATOR(product, Op, OpFunc) \ \ template \ class PatchField, class GeoMesh> \ -void opFunc \ +void OpFunc \ ( \ GeometricField \ - ::type, PatchField, GeoMesh>& gf, \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + ::type, PatchField, GeoMesh>& result, \ + const GeometricField& f1, \ + const GeometricField& f2 \ ) \ { \ - Foam::opFunc \ + Foam::OpFunc \ ( \ - gf.primitiveFieldRef(), \ - gf1.primitiveField(), \ - gf2.primitiveField() \ + result.primitiveFieldRef(), \ + f1.primitiveField(), \ + f2.primitiveField() \ ); \ - Foam::opFunc \ + Foam::OpFunc \ ( \ - gf.boundaryFieldRef(), \ - gf1.boundaryField(), \ - gf2.boundaryField() \ + result.boundaryFieldRef(), \ + f1.boundaryField(), \ + f2.boundaryField() \ ); \ \ - gf.oriented() = gf1.oriented() op gf2.oriented(); \ + result.oriented() = (f1.oriented() Op f2.oriented()); \ } \ \ + \ template \ class PatchField, class GeoMesh> \ tmp \ < \ GeometricField::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + const GeometricField& f1, \ + const GeometricField& f2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - '(' + gf1.name() + #op + gf2.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - gf1.dimensions() op gf2.dimensions() \ + f1, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), gf1, gf2); \ + Foam::OpFunc(tres.ref(), f1, f2); \ \ return tres; \ } \ @@ -633,28 +633,27 @@ tmp \ < \ GeometricField::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ - const tmp>& tgf2 \ + const GeometricField& f1, \ + const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const GeometricField& gf2 = tgf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ - reuseTmpGeometricField::New \ + reuseTmpGeometricField::New \ ( \ - tgf2, \ - '(' + gf1.name() + #op + gf2.name() + ')', \ - gf1.dimensions() op gf2.dimensions() \ + tf2, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), gf1, gf2); \ - \ - tgf2.clear(); \ + Foam::OpFunc(tres.ref(), f1, f2); \ \ + tf2.clear(); \ return tres; \ } \ \ @@ -664,28 +663,27 @@ tmp \ < \ GeometricField::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ - const GeometricField& gf2 \ + const tmp>& tf1, \ + const GeometricField& f2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ - reuseTmpGeometricField::New \ + reuseTmpGeometricField::New \ ( \ - tgf1, \ - '(' + gf1.name() + #op + gf2.name() + ')', \ - gf1.dimensions() op gf2.dimensions() \ + tf1, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), gf1, gf2); \ - \ - tgf1.clear(); \ + Foam::OpFunc(tres.ref(), f1, f2); \ \ + tf1.clear(); \ return tres; \ } \ \ @@ -695,77 +693,69 @@ tmp \ < \ GeometricField::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ - const tmp>& tgf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const GeometricField& gf1 = tgf1(); \ - const GeometricField& gf2 = tgf2(); \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpTmpGeometricField \ - ::New \ + ::New \ ( \ - tgf1, \ - tgf2, \ - '(' + gf1.name() + #op + gf2.name() + ')', \ - gf1.dimensions() op gf2.dimensions() \ + tf1, \ + tf2, \ + '(' + f1.name() + #Op + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), gf1, gf2); \ - \ - tgf1.clear(); \ - tgf2.clear(); \ + Foam::OpFunc(tres.ref(), f1, f2); \ \ + tf1.clear(); \ + tf2.clear(); \ return tres; \ } \ \ template \ class PatchField, class GeoMesh> \ -void opFunc \ +void OpFunc \ ( \ GeometricField \ - ::type, PatchField, GeoMesh>& gf, \ - const GeometricField& gf1, \ + ::type, PatchField, GeoMesh>& result, \ + const GeometricField& f1, \ const dimensioned& dvs \ ) \ { \ - Foam::opFunc(gf.primitiveFieldRef(), gf1.primitiveField(), dvs.value()); \ - Foam::opFunc(gf.boundaryFieldRef(), gf1.boundaryField(), dvs.value()); \ - gf.oriented() = gf1.oriented(); \ + Foam::OpFunc(result.primitiveFieldRef(), f1.primitiveField(), dvs.value());\ + Foam::OpFunc(result.boundaryFieldRef(), f1.boundaryField(), dvs.value()); \ + result.oriented() = f1.oriented(); \ } \ \ template \ class PatchField, class GeoMesh> \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const dimensioned& dvs \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - '(' + gf1.name() + #op + dvs.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - gf1.dimensions() op dvs.dimensions() \ + f1, \ + '(' + f1.name() + #Op + dvs.name() + ')', \ + (f1.dimensions() Op dvs.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), gf1, dvs); \ + Foam::OpFunc(tres.ref(), f1, dvs); \ \ return tres; \ } \ @@ -779,41 +769,40 @@ template \ class GeoMesh \ > \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const VectorSpace& vs \ ) \ { \ - return gf1 op dimensioned(static_cast(vs)); \ + return f1 Op dimensioned(static_cast(vs)); \ } \ \ \ template \ class PatchField, class GeoMesh> \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const dimensioned& dvs \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ - reuseTmpGeometricField::New \ + reuseTmpGeometricField::New \ ( \ - tgf1, \ - '(' + gf1.name() + #op + dvs.name() + ')', \ - gf1.dimensions() op dvs.dimensions() \ + tf1, \ + '(' + f1.name() + #Op + dvs.name() + ')', \ + (f1.dimensions() Op dvs.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), gf1, dvs); \ - \ - tgf1.clear(); \ + Foam::OpFunc(tres.ref(), f1, dvs); \ \ + tf1.clear(); \ return tres; \ } \ \ @@ -826,58 +815,51 @@ template \ class GeoMesh \ > \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const VectorSpace& vs \ ) \ { \ - return tgf1 op dimensioned(static_cast(vs)); \ + return tf1 Op dimensioned(static_cast(vs)); \ } \ \ \ template \ class PatchField, class GeoMesh> \ -void opFunc \ +void OpFunc \ ( \ GeometricField \ - ::type, PatchField, GeoMesh>& gf, \ + ::type, PatchField, GeoMesh>& result, \ const dimensioned& dvs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ) \ { \ - Foam::opFunc(gf.primitiveFieldRef(), dvs.value(), gf1.primitiveField()); \ - Foam::opFunc(gf.boundaryFieldRef(), dvs.value(), gf1.boundaryField()); \ - gf.oriented() = gf1.oriented(); \ + Foam::OpFunc(result.primitiveFieldRef(), dvs.value(), f2.primitiveField());\ + Foam::OpFunc(result.boundaryFieldRef(), dvs.value(), f2.boundaryField()); \ + result.oriented() = f2.oriented(); \ } \ \ template \ class PatchField, class GeoMesh> \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - '(' + dvs.name() + #op + gf1.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - dvs.dimensions() op gf1.dimensions() \ + f2, \ + '(' + dvs.name() + #Op + f2.name() + ')', \ + (dvs.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), dvs, gf1); \ + Foam::OpFunc(tres.ref(), dvs, f2); \ \ return tres; \ } \ @@ -891,40 +873,39 @@ template \ class GeoMesh \ > \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ) \ { \ - return dimensioned(static_cast(vs)) op gf1; \ + return dimensioned(static_cast(vs)) Op f2; \ } \ \ template \ class PatchField, class GeoMesh> \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const tmp>& tgf1 \ + const tmp>& tf2 \ ) \ { \ - typedef typename product::type productType; \ + typedef typename product::type resultType; \ \ - const GeometricField& gf1 = tgf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ - reuseTmpGeometricField::New \ + reuseTmpGeometricField::New \ ( \ - tgf1, \ - '(' + dvs.name() + #op + gf1.name() + ')', \ - dvs.dimensions() op gf1.dimensions() \ + tf2, \ + '(' + dvs.name() + #Op + f2.name() + ')', \ + (dvs.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::opFunc(tres.ref(), dvs, gf1); \ - \ - tgf1.clear(); \ + Foam::OpFunc(tres.ref(), dvs, f2); \ \ + tf2.clear(); \ return tres; \ } \ \ @@ -937,15 +918,16 @@ template \ class GeoMesh \ > \ tmp::type, PatchField, GeoMesh>> \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const tmp>& tgf1 \ + const tmp>& tf2 \ ) \ { \ - return dimensioned(static_cast(vs)) op tgf1; \ + return dimensioned(static_cast(vs)) Op tf2; \ } + PRODUCT_OPERATOR(typeOfSum, +, add) PRODUCT_OPERATOR(typeOfSum, -, subtract) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H index 1f65866247..65863a90c0 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,7 +37,7 @@ License namespace Foam { -// * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template class PatchField, class GeoMesh> void component @@ -47,16 +47,16 @@ void component typename GeometricField::cmptType, PatchField, GeoMesh - >& gcf, - const GeometricField& gf, + >& result, + const GeometricField& f1, const direction d ); template class PatchField, class GeoMesh> void T ( - GeometricField& gf, - const GeometricField& gf1 + GeometricField& result, + const GeometricField& f1 ); template @@ -68,8 +68,9 @@ template > void pow ( - GeometricField::type, PatchField, GeoMesh>& gf, - const GeometricField& gf1 + GeometricField + ::type, PatchField, GeoMesh>& result, + const GeometricField& f1 ); template @@ -86,7 +87,7 @@ tmp > pow ( - const GeometricField& gf, + const GeometricField& f1, typename powProduct::type ); @@ -104,7 +105,7 @@ tmp > pow ( - const tmp>& tgf, + const tmp>& tf1, typename powProduct::type ); @@ -112,7 +113,7 @@ template class PatchField, class GeoMesh> void sqr ( GeometricField - ::type, PatchField, GeoMesh>& gf, + ::type, PatchField, GeoMesh>& f1, const GeometricField& gf1 ); @@ -126,7 +127,7 @@ tmp GeoMesh > > -sqr(const GeometricField& gf); +sqr(const GeometricField& f1); template class PatchField, class GeoMesh> tmp @@ -138,48 +139,48 @@ tmp GeoMesh > > -sqr(const tmp>& tgf); +sqr(const tmp>& tf1); template class PatchField, class GeoMesh> void magSqr ( - GeometricField::type, PatchField, GeoMesh>& gsf, - const GeometricField& gf + GeometricField::type, PatchField, GeoMesh>& result, + const GeometricField& f1 ); template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> magSqr ( - const GeometricField& gf + const GeometricField& f1 ); template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> magSqr ( - const tmp>& tgf + const tmp>& tf1 ); template class PatchField, class GeoMesh> void mag ( - GeometricField::type, PatchField, GeoMesh>& gsf, - const GeometricField& gf + GeometricField::type, PatchField, GeoMesh>& result, + const GeometricField& tf1 ); template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> mag ( - const GeometricField& gf + const GeometricField& f1 ); template class PatchField, class GeoMesh> tmp::type, PatchField, GeoMesh>> mag ( - const tmp>& tgf + const tmp>& tf1 ); template class PatchField, class GeoMesh> @@ -190,8 +191,8 @@ void cmptAv typename GeometricField::cmptType, PatchField, GeoMesh - >& gcf, - const GeometricField& gf + >& result, + const GeometricField& f1 ); template class PatchField, class GeoMesh> @@ -204,7 +205,7 @@ tmp GeoMesh > > -cmptAv(const GeometricField& gf); +cmptAv(const GeometricField& f1); template class PatchField, class GeoMesh> tmp @@ -216,21 +217,21 @@ tmp GeoMesh > > -cmptAv(const tmp>& tgf); +cmptAv(const tmp>& tf1); -#define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(returnType, func, binaryOp) \ +#define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(ReturnType, Func, BinaryOp) \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const GeometricField& gf \ + const GeometricField& f1 \ ); \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const tmp>& tgf1 \ + const tmp>& tf1 \ ); UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp) @@ -241,18 +242,18 @@ UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, minMaxMagOp) #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY -#define UNARY_REDUCTION_FUNCTION(returnType, func, gFunc) \ +#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const GeometricField& gf \ + const GeometricField& f1 \ ); \ \ template class PatchField, class GeoMesh> \ -dimensioned func \ +dimensioned Func \ ( \ - const tmp>& tgf1 \ + const tmp>& tf1 \ ); UNARY_REDUCTION_FUNCTION(Type, sum, gSum) @@ -272,8 +273,44 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) +// ------------------------------------------------------------------------- // -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// Clamp Methods + +template class PatchField, class GeoMesh> +void clamp +( + GeometricField& result, + const GeometricField& f1, + const Foam::zero_one +); + +template class PatchField, class GeoMesh> +tmp> +clamp +( + const GeometricField& f1, + const Foam::zero_one +); + +template class PatchField, class GeoMesh> +tmp> +clamp +( + const tmp>& tf1, + const Foam::zero_one +); + +BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +TERNARY_FUNCTION(Type, Type, Type, scalar, lerp) +TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp) + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -289,16 +326,16 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define PRODUCT_OPERATOR(product, op, opFunc) \ +#define PRODUCT_OPERATOR(product, Op, OpFunc) \ \ template \ class PatchField, class GeoMesh> \ -void opFunc \ +void OpFunc \ ( \ GeometricField \ - ::type, PatchField, GeoMesh>& gf, \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + ::type, PatchField, GeoMesh>& result, \ + const GeometricField& f1, \ + const GeometricField& f2 \ ); \ \ template \ @@ -308,10 +345,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + const GeometricField& f1, \ + const GeometricField& f2 \ ); \ \ template \ @@ -321,10 +358,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ - const tmp>& tgf2 \ + const GeometricField& f1, \ + const tmp>& tf2 \ ); \ \ template \ @@ -334,10 +371,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ - const GeometricField& gf2 \ + const tmp>& tf1, \ + const GeometricField& f2 \ ); \ \ template \ @@ -347,19 +384,19 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ - const tmp>& tgf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ); \ \ template \ class PatchField, class GeoMesh> \ -void opFunc \ +void OpFunc \ ( \ GeometricField \ - ::type, PatchField, GeoMesh>& gf, \ - const GeometricField& gf1, \ + ::type, PatchField, GeoMesh>& result, \ + const GeometricField& f1, \ const dimensioned& dvs \ ); \ \ @@ -370,9 +407,9 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const dimensioned& dvs \ ); \ \ @@ -389,9 +426,9 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const VectorSpace& vs \ ); \ \ @@ -402,9 +439,9 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const dimensioned& dvs \ ); \ \ @@ -421,20 +458,20 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const VectorSpace& vs \ ); \ \ template \ class PatchField, class GeoMesh> \ -void opFunc \ +void OpFunc \ ( \ GeometricField \ - ::type, PatchField, GeoMesh>& gf, \ + ::type, PatchField, GeoMesh>& result, \ const dimensioned& dvs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ); \ \ template \ @@ -444,10 +481,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ); \ \ template \ @@ -463,10 +500,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ); \ \ template \ @@ -476,10 +513,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const tmp>& tgf1 \ + const tmp>& tf2 \ ); \ \ template \ @@ -495,10 +532,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const tmp>& tgf1 \ + const tmp>& tf2 \ ); PRODUCT_OPERATOR(typeOfSum, +, add) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C index 31d79a638d..d8e5ec5b92 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,39 +40,31 @@ namespace Foam TEMPLATE \ void Func \ ( \ - GeometricField& res, \ - const GeometricField& gf1 \ + GeometricField& result, \ + const GeometricField& f1 \ ) \ { \ - Foam::Func(res.primitiveFieldRef(), gf1.primitiveField()); \ - Foam::Func(res.boundaryFieldRef(), gf1.boundaryField()); \ - res.oriented() = gf1.oriented(); \ + Foam::Func(result.primitiveFieldRef(), f1.primitiveField()); \ + Foam::Func(result.boundaryFieldRef(), f1.boundaryField()); \ + result.oriented() = f1.oriented(); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& gf1 \ + const GeometricField& f1 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - #Func "(" + gf1.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - Dfunc(gf1.dimensions()) \ + f1, \ + #Func "(" + f1.name() + ')', \ + Dfunc(f1.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1); \ - \ + Foam::Func(tres.ref(), f1); \ return tres; \ } \ \ @@ -80,23 +72,21 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tgf1 \ + const tmp>& tf1 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf1, \ - #Func "(" + gf1.name() + ')', \ - Dfunc(gf1.dimensions()) \ - ); \ - \ - Foam::Func(tres.ref(), gf1); \ - \ - tgf1.clear(); \ + tf1, \ + #Func "(" + f1.name() + ')', \ + Dfunc(f1.dimensions()) \ + ); \ \ + Foam::Func(tres.ref(), f1); \ + tf1.clear(); \ return tres; \ } @@ -108,38 +98,31 @@ tmp> Func \ TEMPLATE \ void OpFunc \ ( \ - GeometricField& res, \ - const GeometricField& gf1 \ + GeometricField& result, \ + const GeometricField& f1 \ ) \ { \ - Foam::OpFunc(res.primitiveFieldRef(), gf1.primitiveField()); \ - Foam::OpFunc(res.boundaryFieldRef(), gf1.boundaryField()); \ - res.oriented() = gf1.oriented(); \ + Foam::OpFunc(result.primitiveFieldRef(), f1.primitiveField()); \ + Foam::OpFunc(result.boundaryFieldRef(), f1.boundaryField()); \ + result.oriented() = f1.oriented(); \ } \ \ + \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& gf1 \ + const GeometricField& f1 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - #Op + gf1.name(), \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - Dfunc(gf1.dimensions()) \ + f1, \ + #Op + f1.name(), \ + Dfunc(f1.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1); \ - \ + Foam::OpFunc(tres.ref(), f1); \ return tres; \ } \ \ @@ -147,23 +130,21 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tgf1 \ + const tmp>& tf1 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf1, \ - #Op + gf1.name(), \ - Dfunc(gf1.dimensions()) \ + tf1, \ + #Op + f1.name(), \ + Dfunc(f1.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1); \ - \ - tgf1.clear(); \ - \ + Foam::OpFunc(tres.ref(), f1); \ + tf1.clear(); \ return tres; \ } @@ -175,51 +156,43 @@ tmp> operator Op \ TEMPLATE \ void Func \ ( \ - GeometricField& res, \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2 \ ) \ { \ Foam::Func \ ( \ - res.primitiveFieldRef(), \ - gf1.primitiveField(), \ - gf2.primitiveField() \ + result.primitiveFieldRef(), \ + f1.primitiveField(), \ + f2.primitiveField() \ ); \ Foam::Func \ ( \ - res.boundaryFieldRef(), \ - gf1.boundaryField(), \ - gf2.boundaryField() \ + result.boundaryFieldRef(), \ + f1.boundaryField(), \ + f2.boundaryField() \ ); \ - res.oriented() = Func(gf1.oriented(), gf2.oriented()); \ + result.oriented() = Func(f1.oriented(), f2.oriented()); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + const GeometricField& f1, \ + const GeometricField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - Func(gf1.dimensions(), gf2.dimensions()) \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1, gf2); \ - \ + Foam::Func(tres.ref(), f1, f2); \ return tres; \ } \ \ @@ -227,24 +200,22 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& gf1, \ - const tmp>& tgf2 \ + const GeometricField& f1, \ + const tmp>& tf2 \ ) \ { \ - const GeometricField& gf2 = tgf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf2, \ - #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ - Func(gf1.dimensions(), gf2.dimensions()) \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1, gf2); \ - \ - tgf2.clear(); \ - \ + Foam::Func(tres.ref(), f1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -252,24 +223,22 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tgf1, \ - const GeometricField& gf2 \ + const tmp>& tf1, \ + const GeometricField& f2 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf1, \ - #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ - Func(gf1.dimensions(), gf2.dimensions()) \ + tf1, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1, gf2); \ - \ - tgf1.clear(); \ - \ + Foam::Func(tres.ref(), f1, f2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -277,29 +246,27 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tgf1, \ - const tmp>& tgf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ - const GeometricField& gf2 = tgf2(); \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpTmpGeometricField \ \ ::New \ ( \ - tgf1, \ - tgf2, \ - #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ - Func(gf1.dimensions(), gf2.dimensions()) \ + tf1, \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1, gf2); \ - \ - tgf1.clear(); \ - tgf2.clear(); \ - \ + Foam::Func(tres.ref(), f1, f2); \ + tf1.clear(); \ + tf2.clear(); \ return tres; \ } @@ -311,14 +278,14 @@ tmp> Func \ TEMPLATE \ void Func \ ( \ - GeometricField& res, \ + GeometricField& result, \ const dimensioned& dt1, \ - const GeometricField& gf2 \ + const GeometricField& f2 \ ) \ { \ - Foam::Func(res.primitiveFieldRef(), dt1.value(), gf2.primitiveField()); \ - Foam::Func(res.boundaryFieldRef(), dt1.value(), gf2.boundaryField()); \ - res.oriented() = gf2.oriented(); \ + Foam::Func(result.primitiveFieldRef(), dt1.value(), f2.primitiveField()); \ + Foam::Func(result.boundaryFieldRef(), dt1.value(), f2.boundaryField()); \ + result.oriented() = f2.oriented(); \ } \ \ \ @@ -326,26 +293,18 @@ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ - const GeometricField& gf2 \ + const GeometricField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - #Func "(" + dt1.name() + ',' + gf2.name() + ')', \ - gf2.instance(), \ - gf2.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf2.mesh(), \ - Func(dt1.dimensions(), gf2.dimensions()) \ + f2, \ + #Func "(" + dt1.name() + ',' + f2.name() + ')', \ + Func(dt1.dimensions(), f2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), dt1, gf2); \ - \ + Foam::Func(tres.ref(), dt1, f2); \ return tres; \ } \ \ @@ -353,11 +312,11 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const Type1& t1, \ - const GeometricField& gf2 \ + const Type1& s1, \ + const GeometricField& f2 \ ) \ { \ - return Func(dimensioned(t1), gf2); \ + return Func(dimensioned(s1), f2); \ } \ \ \ @@ -365,23 +324,21 @@ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ - const tmp>& tgf2 \ + const tmp>& tf2 \ ) \ { \ - const GeometricField& gf2 = tgf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf2, \ - #Func "(" + dt1.name() + gf2.name() + ',' + ')', \ - Func(dt1.dimensions(), gf2.dimensions()) \ + tf2, \ + #Func "(" + dt1.name() + ',' + f2.name() + ')', \ + Func(dt1.dimensions(), f2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), dt1, gf2); \ - \ - tgf2.clear(); \ - \ + Foam::Func(tres.ref(), dt1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -389,11 +346,11 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const Type1& t1, \ - const tmp>& tgf2 \ + const Type1& s1, \ + const tmp>& tf2 \ ) \ { \ - return Func(dimensioned(t1), tgf2); \ + return Func(dimensioned(s1), tf2); \ } @@ -402,41 +359,33 @@ tmp> Func \ TEMPLATE \ void Func \ ( \ - GeometricField& res, \ - const GeometricField& gf1, \ + GeometricField& result, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ) \ { \ - Foam::Func(res.primitiveFieldRef(), gf1.primitiveField(), dt2.value()); \ - Foam::Func(res.boundaryFieldRef(), gf1.boundaryField(), dt2.value()); \ - res.oriented() = gf1.oriented(); \ + Foam::Func(result.primitiveFieldRef(), f1.primitiveField(), dt2.value()); \ + Foam::Func(result.boundaryFieldRef(), f1.boundaryField(), dt2.value()); \ + result.oriented() = f1.oriented(); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - #Func "(" + gf1.name() + ',' + dt2.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - Func(gf1.dimensions(), dt2.dimensions()) \ + f1, \ + #Func "(" + f1.name() + ',' + dt2.name() + ')', \ + Func(f1.dimensions(), dt2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1, dt2); \ - \ + Foam::Func(tres.ref(), f1, dt2); \ return tres; \ } \ \ @@ -444,35 +393,33 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& gf1, \ - const Type2& t2 \ + const GeometricField& f1, \ + const Type2& s2 \ ) \ { \ - return Func(gf1, dimensioned(t2)); \ + return Func(f1, dimensioned(s2)); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const dimensioned& dt2 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf1, \ - #Func "(" + gf1.name() + ',' + dt2.name() + ')', \ - Func(gf1.dimensions(), dt2.dimensions()) \ + tf1, \ + #Func "(" + f1.name() + ',' + dt2.name() + ')', \ + Func(f1.dimensions(), dt2.dimensions()) \ ); \ \ - Foam::Func(tres.ref(), gf1, dt2); \ - \ - tgf1.clear(); \ - \ + Foam::Func(tres.ref(), f1, dt2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -480,11 +427,11 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tgf1, \ - const Type2& t2 \ + const tmp>& tf1, \ + const Type2& s2 \ ) \ { \ - return Func(tgf1, dimensioned(t2)); \ + return Func(tf1, dimensioned(s2)); \ } @@ -500,43 +447,43 @@ tmp> Func \ TEMPLATE \ void OpFunc \ ( \ - GeometricField& res, \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2 \ ) \ { \ Foam::OpFunc \ - (res.primitiveFieldRef(), gf1.primitiveField(), gf2.primitiveField()); \ + ( \ + result.primitiveFieldRef(), \ + f1.primitiveField(), \ + f2.primitiveField() \ + ); \ Foam::OpFunc \ - (res.boundaryFieldRef(), gf1.boundaryField(), gf2.boundaryField()); \ - res.oriented() = gf1.oriented() Op gf2.oriented(); \ + ( \ + result.boundaryFieldRef(), \ + f1.boundaryField(), \ + f2.boundaryField() \ + ); \ + result.oriented() = (f1.oriented() Op f2.oriented()); \ } \ \ \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& gf1, \ - const GeometricField& gf2 \ + const GeometricField& f1, \ + const GeometricField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - '(' + gf1.name() + OpName + gf2.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - gf1.dimensions() Op gf2.dimensions() \ + f1, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1, gf2); \ - \ + Foam::OpFunc(tres.ref(), f1, f2); \ return tres; \ } \ \ @@ -544,24 +491,22 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& gf1, \ - const tmp>& tgf2 \ + const GeometricField& f1, \ + const tmp>& tf2 \ ) \ { \ - const GeometricField& gf2 = tgf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf2, \ - '(' + gf1.name() + OpName + gf2.name() + ')', \ - gf1.dimensions() Op gf2.dimensions() \ + tf2, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1, gf2); \ - \ - tgf2.clear(); \ - \ + Foam::OpFunc(tres.ref(), f1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -569,24 +514,22 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tgf1, \ - const GeometricField& gf2 \ + const tmp>& tf1, \ + const GeometricField& f2 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf1, \ - '(' + gf1.name() + OpName + gf2.name() + ')', \ - gf1.dimensions() Op gf2.dimensions() \ + tf1, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1, gf2); \ - \ - tgf1.clear(); \ - \ + Foam::OpFunc(tres.ref(), f1, f2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -594,28 +537,26 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tgf1, \ - const tmp>& tgf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ - const GeometricField& gf2 = tgf2(); \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpTmpGeometricField \ ::New \ ( \ - tgf1, \ - tgf2, \ - '(' + gf1.name() + OpName + gf2.name() + ')', \ - gf1.dimensions() Op gf2.dimensions() \ + tf1, \ + tf2, \ + '(' + f1.name() + OpName + f2.name() + ')', \ + (f1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1, gf2); \ - \ - tgf1.clear(); \ - tgf2.clear(); \ - \ + Foam::OpFunc(tres.ref(), f1, f2); \ + tf1.clear(); \ + tf2.clear(); \ return tres; \ } @@ -627,14 +568,14 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - GeometricField& res, \ + GeometricField& result, \ const dimensioned& dt1, \ - const GeometricField& gf2 \ + const GeometricField& f2 \ ) \ { \ - Foam::OpFunc(res.primitiveFieldRef(), dt1.value(), gf2.primitiveField()); \ - Foam::OpFunc(res.boundaryFieldRef(), dt1.value(), gf2.boundaryField()); \ - res.oriented() = gf2.oriented(); \ + Foam::OpFunc(result.primitiveFieldRef(), dt1.value(), f2.primitiveField());\ + Foam::OpFunc(result.boundaryFieldRef(), dt1.value(), f2.boundaryField()); \ + result.oriented() = f2.oriented(); \ \ } \ \ @@ -642,26 +583,18 @@ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ - const GeometricField& gf2 \ + const GeometricField& f2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - '(' + dt1.name() + OpName + gf2.name() + ')', \ - gf2.instance(), \ - gf2.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf2.mesh(), \ - dt1.dimensions() Op gf2.dimensions() \ + f2, \ + '(' + dt1.name() + OpName + f2.name() + ')', \ + (dt1.dimensions() Op f2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), dt1, gf2); \ - \ + Foam::OpFunc(tres.ref(), dt1, f2); \ return tres; \ } \ \ @@ -670,10 +603,10 @@ TEMPLATE \ tmp> operator Op \ ( \ const Type1& t1, \ - const GeometricField& gf2 \ + const GeometricField& f2 \ ) \ { \ - return dimensioned(t1) Op gf2; \ + return dimensioned(t1) Op f2; \ } \ \ \ @@ -681,23 +614,21 @@ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ - const tmp>& tgf2 \ + const tmp>& tf2 \ ) \ { \ - const GeometricField& gf2 = tgf2(); \ + const auto& f2 = tf2(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf2, \ - '(' + dt1.name() + OpName + gf2.name() + ')', \ - dt1.dimensions() Op gf2.dimensions() \ - ) ; \ - \ - Foam::OpFunc(tres.ref(), dt1, gf2); \ - \ - tgf2.clear(); \ + tf2, \ + '(' + dt1.name() + OpName + f2.name() + ')', \ + (dt1.dimensions() Op f2.dimensions()) \ + ); \ \ + Foam::OpFunc(tres.ref(), dt1, f2); \ + tf2.clear(); \ return tres; \ } \ \ @@ -705,11 +636,11 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& t1, \ - const tmp>& tgf2 \ + const Type1& s1, \ + const tmp>& tf2 \ ) \ { \ - return dimensioned(t1) Op tgf2; \ + return dimensioned(s1) Op tf2; \ } @@ -718,41 +649,33 @@ tmp> operator Op \ TEMPLATE \ void OpFunc \ ( \ - GeometricField& res, \ - const GeometricField& gf1, \ + GeometricField& result, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ) \ { \ - Foam::OpFunc(res.primitiveFieldRef(), gf1.primitiveField(), dt2.value()); \ - Foam::OpFunc(res.boundaryFieldRef(), gf1.boundaryField(), dt2.value()); \ - res.oriented() = gf1.oriented(); \ + Foam::OpFunc(result.primitiveFieldRef(), f1.primitiveField(), dt2.value());\ + Foam::OpFunc(result.boundaryFieldRef(), f1.boundaryField(), dt2.value()); \ + result.oriented() = f1.oriented(); \ } \ \ \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ) \ { \ auto tres = \ - tmp>::New \ + reuseTmpGeometricField::New \ ( \ - IOobject \ - ( \ - '(' + gf1.name() + OpName + dt2.name() + ')', \ - gf1.instance(), \ - gf1.db(), \ - IOobject::NO_READ, \ - IOobject::NO_WRITE \ - ), \ - gf1.mesh(), \ - gf1.dimensions() Op dt2.dimensions() \ + f1, \ + '(' + f1.name() + OpName + dt2.name() + ')', \ + (f1.dimensions() Op dt2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1, dt2); \ - \ + Foam::OpFunc(tres.ref(), f1, dt2); \ return tres; \ } \ \ @@ -760,35 +683,33 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& gf1, \ - const Type2& t2 \ + const GeometricField& f1, \ + const Type2& s2 \ ) \ { \ - return gf1 Op dimensioned(t2); \ + return f1 Op dimensioned(s2); \ } \ \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const dimensioned& dt2 \ ) \ { \ - const GeometricField& gf1 = tgf1(); \ + const auto& f1 = tf1(); \ \ auto tres = \ reuseTmpGeometricField::New \ ( \ - tgf1, \ - '(' + gf1.name() + OpName + dt2.name() + ')', \ - gf1.dimensions() Op dt2.dimensions() \ + tf1, \ + '(' + f1.name() + OpName + dt2.name() + ')', \ + (f1.dimensions() Op dt2.dimensions()) \ ); \ \ - Foam::OpFunc(tres.ref(), gf1, dt2); \ - \ - tgf1.clear(); \ - \ + Foam::OpFunc(tres.ref(), f1, dt2); \ + tf1.clear(); \ return tres; \ } \ \ @@ -796,11 +717,11 @@ tmp> operator Op \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tgf1, \ - const Type2& t2 \ + const tmp>& tf1, \ + const Type2& s2 \ ) \ { \ - return tgf1 Op dimensioned(t2); \ + return tf1 Op dimensioned(s2); \ } @@ -811,6 +732,407 @@ tmp> operator Op \ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const GeometricField& f3 \ +) \ +{ \ + Foam::Func \ + ( \ + result.primitiveFieldRef(), \ + f1.primitiveField(), \ + f2.primitiveField(), \ + f3.primitiveField() \ + ); \ + Foam::Func \ + ( \ + result.boundaryFieldRef(), \ + f1.boundaryField(), \ + f2.boundaryField(), \ + f3.boundaryField() \ + ); \ + result.oriented() = Func(f1.oriented(), f2.oriented()); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const GeometricField& f3 \ +) \ +{ \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const GeometricField& f3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const GeometricField& f3 \ +) \ +{ \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + f2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + f3, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const GeometricField& f3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpTmpGeometricField \ + \ + ::New \ + ( \ + tf1, \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpTmpGeometricField \ + \ + ::New \ + ( \ + tf1, \ + tf3, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f2 = tf2(); \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpTmpGeometricField \ + \ + ::New \ + ( \ + tf2, \ + tf3, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ + const auto& f3 = tf3(); \ + \ + auto tres = \ + reuseTmpTmpGeometricField \ + \ + ::New \ + ( \ + tf1, \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + f3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, f3); \ + tf1.clear(); \ + tf2.clear(); \ + tf3.clear(); \ + return tres; \ +} + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const dimensioned& dt3 \ +) \ +{ \ + Foam::Func \ + ( \ + result.primitiveFieldRef(), \ + f1.primitiveField(), \ + f2.primitiveField(), \ + dt3.value() \ + ); \ + Foam::Func \ + ( \ + result.boundaryFieldRef(), \ + f1.boundaryField(), \ + f2.boundaryField(), \ + dt3.value() \ + ); \ + result.oriented() = Func(f1.oriented(), f2.oriented()); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const dimensioned& dt3 \ +) \ +{ \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, dt3.value()); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const Type3& s3 \ +) \ +{ \ + return Foam::Func(f1, f2, dimensioned(s3)); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const dimensioned& dt3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + f1, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, dt3.value()); \ + tf1.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const Type3& s3 \ +) \ +{ \ + return Foam::Func(tf1, f2, dimensioned(s3)); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +) \ +{ \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpGeometricField::New \ + ( \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, dt3.value()); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + return Foam::Func(f1, tf2, dimensioned(s3)); \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +) \ +{ \ + const auto& f1 = tf1(); \ + const auto& f2 = tf2(); \ + \ + auto tres = \ + reuseTmpTmpGeometricField \ + \ + ::New \ + ( \ + tf1, \ + tf2, \ + #Func "(" + f1.name() + ',' + f2.name() + ',' + dt3.name() + ')', \ + Func(f1.dimensions(), f2.dimensions()) \ + ); \ + \ + Foam::Func(tres.ref(), f1, f2, dt3.value()); \ + tf1.clear(); \ + tf2.clear(); \ + return tres; \ +} \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +) \ +{ \ + return Foam::Func(tf1, tf2, dimensioned(s3)); \ +} + + +// ************************************************************************* // + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.H index 83109528dd..259e1cbea0 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,32 +31,46 @@ License #define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ - const GeometricField& df \ + GeometricField& result, \ + const GeometricField& f1 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1 \ + const GeometricField& f1 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1 \ ); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define UNARY_OPERATOR(ReturnType, Type1, Op, opFunc, Dfunc) \ +#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ - const GeometricField& df1 \ + GeometricField& result, \ + const GeometricField& f1 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1 \ + const GeometricField& f1 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1 \ ); @@ -64,6 +79,14 @@ tmp> operator Op \ #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ +void Func \ +( \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2 \ +); \ + \ +TEMPLATE \ tmp> Func \ ( \ const GeometricField& df1, \ @@ -73,22 +96,22 @@ tmp> Func \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& df1, \ - const tmp>& tdf2 \ + const GeometricField& f1, \ + const tmp>& tf2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const GeometricField& df2 \ + const tmp>& tf1, \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const tmp>& tf2 \ ); @@ -97,62 +120,78 @@ tmp> Func \ #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ + GeometricField& result, \ const dimensioned& dt1, \ - const GeometricField& df2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const Type1& t1, \ - const GeometricField& df2 \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ - const tmp>& tdf2 \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const Type1& t1, \ - const tmp>& tdf2 \ + const Type1& s1, \ + const GeometricField& f2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const dimensioned& dt1, \ + const tmp>& tf2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const Type1& s1, \ + const tmp>& tf2 \ ); #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ -tmp> Func \ +void Func \ ( \ - const GeometricField& df1, \ + GeometricField& result, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const GeometricField& df1, \ - const Type2& t2 \ -); \ - \ -TEMPLATE \ -tmp> Func \ -( \ - const tmp>& tdf1, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> Func \ ( \ - const tmp>& tdf2, \ - const Type2& t2 \ + const GeometricField& f1, \ + const Type2& s2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const dimensioned& dt2 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const Type2& s2 \ ); @@ -166,95 +205,119 @@ tmp> Func \ #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ - const GeometricField& df1, \ - const GeometricField& df2 \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& df1, \ - const tmp>& tdf2 \ + const GeometricField& f1, \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const GeometricField& df2 \ + const GeometricField& f1, \ + const tmp>& tf2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const tmp>& tdf2 \ + const tmp>& tf1, \ + const GeometricField& f2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1, \ + const tmp>& tf2 \ ); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ +#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ + GeometricField& result, \ const dimensioned& dt1, \ - const GeometricField& df2 \ -); \ - \ -TEMPLATE \ -tmp> operator Op \ -( \ - const Type1& t1, \ - const GeometricField& df2 \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ - const tmp>& tdf2 \ + const GeometricField& f2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const Type1& t1, \ - const tmp>& tdf2 \ + const Type1& s1, \ + const GeometricField& f2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const dimensioned& dt1, \ + const tmp>& tf2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const Type1& s1, \ + const tmp>& tf2 \ ); -#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ +#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ -tmp> operator Op \ +void OpFunc \ ( \ - const GeometricField& df1, \ + GeometricField& result, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const GeometricField& df1, \ - const Type2& t2 \ -); \ - \ -TEMPLATE \ -tmp> operator Op \ -( \ - const tmp>& tdf1, \ + const GeometricField& f1, \ const dimensioned& dt2 \ ); \ \ TEMPLATE \ tmp> operator Op \ ( \ - const tmp>& tdf1, \ - const Type2& t2 \ + const GeometricField& f1, \ + const Type2& s2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1, \ + const dimensioned& dt2 \ +); \ + \ +TEMPLATE \ +tmp> operator Op \ +( \ + const tmp>& tf1, \ + const Type2& s2 \ ); @@ -263,4 +326,158 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const GeometricField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const GeometricField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const GeometricField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const GeometricField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const GeometricField& f3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const tmp>& tf3 \ +); + + +#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func) \ + \ +TEMPLATE \ +void Func \ +( \ + GeometricField& result, \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const GeometricField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const GeometricField& f2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const GeometricField& f1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const dimensioned& dt3 \ +); \ + \ +TEMPLATE \ +tmp> Func \ +( \ + const tmp>& tf1, \ + const tmp>& tf2, \ + const Type3& s3 \ +); + + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H index a2c2fe3f56..afe8d4b65b 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,6 +76,7 @@ inline bool reusable // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// One-parameter versions template < @@ -86,24 +87,46 @@ template > struct reuseTmpGeometricField { + //- Pass-through to New GeometricField static tmp> New ( - const tmp>& tgf1, + const GeometricField& f1, const word& name, const dimensionSet& dimensions ) { - const auto& gf1 = tgf1(); + return tmp>::New + ( + IOobject + ( + name, + f1.instance(), + f1.db() + ), + f1.mesh(), + dimensions + ); + } + + //- Dissimilar types: return new field + static tmp> New + ( + const tmp>& tf1, + const word& name, + const dimensionSet& dimensions + ) + { + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - gf1.instance(), - gf1.db() + f1.instance(), + f1.db() ), - gf1.mesh(), + f1.mesh(), dimensions ); } @@ -117,41 +140,41 @@ struct reuseTmpGeometricField //- for identical input and output types static tmp> New ( - const tmp>& tgf1, + const tmp>& tf1, const word& name, const dimensionSet& dimensions, const bool initCopy = false ) { - if (Detail::reusable(tgf1)) + if (Detail::reusable(tf1)) { - auto& gf1 = tgf1.constCast(); + auto& f1 = tf1.constCast(); - gf1.rename(name); - gf1.dimensions().reset(dimensions); - return tgf1; + f1.rename(name); + f1.dimensions().reset(dimensions); + return tf1; } - const auto& gf1 = tgf1(); + const auto& f1 = tf1(); - auto rtgf = tmp>::New + auto tresult = tmp>::New ( IOobject ( name, - gf1.instance(), - gf1.db() + f1.instance(), + f1.db() ), - gf1.mesh(), + f1.mesh(), dimensions ); if (initCopy) { - rtgf.ref() == gf1; + tresult.ref() == f1; } - return rtgf; + return tresult; } }; @@ -163,7 +186,7 @@ tmp GeometricField > New ( - const tmp>& tgf1, + const tmp>& tf1, const word& name, const dimensionSet& dimensions, const bool initCopy = false @@ -171,7 +194,7 @@ tmp { return reuseTmpGeometricField::New ( - tgf1, + tf1, name, dimensions, initCopy @@ -192,23 +215,23 @@ struct reuseTmpTmpGeometricField { static tmp> New ( - const tmp>& tgf1, - const tmp>& tgf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - const auto& gf1 = tgf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - gf1.instance(), - gf1.db() + f1.instance(), + f1.db() ), - gf1.mesh(), + f1.mesh(), dimensions ); } @@ -230,32 +253,32 @@ struct reuseTmpTmpGeometricField { static tmp> New ( - const tmp>& tgf1, - const tmp>& tgf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - if (Detail::reusable(tgf2)) + if (Detail::reusable(tf2)) { - auto& gf2 = tgf2.constCast(); + auto& f2 = tf2.constCast(); - gf2.rename(name); - gf2.dimensions().reset(dimensions); - return tgf2; + f2.rename(name); + f2.dimensions().reset(dimensions); + return tf2; } - const auto& gf1 = tgf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - gf1.instance(), - gf1.db() + f1.instance(), + f1.db() ), - gf1.mesh(), + f1.mesh(), dimensions ); } @@ -276,32 +299,32 @@ struct reuseTmpTmpGeometricField { static tmp> New ( - const tmp>& tgf1, - const tmp>& tgf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - if (Detail::reusable(tgf1)) + if (Detail::reusable(tf1)) { - auto& gf1 = tgf1.constCast(); + auto& f1 = tf1.constCast(); - gf1.rename(name); - gf1.dimensions().reset(dimensions); - return tgf1; + f1.rename(name); + f1.dimensions().reset(dimensions); + return tf1; } - const auto& gf1 = tgf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - gf1.instance(), - gf1.db() + f1.instance(), + f1.db() ), - gf1.mesh(), + f1.mesh(), dimensions ); } @@ -316,47 +339,46 @@ struct reuseTmpTmpGeometricField { static tmp> New ( - const tmp>& tgf1, - const tmp>& tgf2, + const tmp>& tf1, + const tmp>& tf2, const word& name, const dimensionSet& dimensions ) { - if (Detail::reusable(tgf1)) + if (Detail::reusable(tf1)) { - auto& gf1 = tgf1.constCast(); + auto& f1 = tf1.constCast(); - gf1.rename(name); - gf1.dimensions().reset(dimensions); - return tgf1; + f1.rename(name); + f1.dimensions().reset(dimensions); + return tf1; } - if (Detail::reusable(tgf2)) + if (Detail::reusable(tf2)) { - auto& gf2 = tgf2.constCast(); + auto& f2 = tf2.constCast(); - gf2.rename(name); - gf2.dimensions().reset(dimensions); - return tgf2; + f2.rename(name); + f2.dimensions().reset(dimensions); + return tf2; } - const auto& gf1 = tgf1(); + const auto& f1 = tf1(); return tmp>::New ( IOobject ( name, - gf1.instance(), - gf1.db() + f1.instance(), + f1.db() ), - gf1.mesh(), + f1.mesh(), dimensions ); } }; - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C b/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C index 24cae2e413..fa121c73f1 100644 --- a/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C +++ b/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C @@ -149,7 +149,7 @@ Type Foam::uniformInterpolationTable::interpolate(scalar x) const { if (bound_) { - x = max(min(xMax() - SMALL*dx_, x), x0_); + x = clamp(x, x0_, (xMax() - SMALL*dx_)); } else { diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index 470e4b7b47..bf646864a7 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -76,7 +76,7 @@ Foam::label Foam::face::mostConcaveAngle // NOTE: is -ve angle since left edge pointing in other direction scalar edgeCos = (leftEdge & rightEdge); - scalar edgeAngle = acos(max(-1.0, min(1.0, edgeCos))); + scalar edgeAngle = acos(clamp(edgeCos, -1, 1)); scalar angle; @@ -205,7 +205,7 @@ Foam::label Foam::face::split splitEdge.normalise(); const scalar splitCos = splitEdge & rightEdge; - const scalar splitAngle = acos(max(-1.0, min(1.0, splitCos))); + const scalar splitAngle = acos(clamp(splitCos, -1, 1)); const scalar angleDiff = fabs(splitAngle - bisectAngle); if (angleDiff < minDiff) diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C index 04fc7a63b7..255335aafa 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C @@ -101,7 +101,7 @@ bool Foam::polyMesh::checkFaceOrthogonality << " between cells " << own[facei] << " and " << nei[facei] << ": Angle = " - << radToDeg(::acos(min(1.0, max(-1.0, ortho[facei])))) + << radToDeg(::acos(clamp(ortho[facei], -1, 1))) << " deg." << endl; } @@ -130,9 +130,9 @@ bool Foam::polyMesh::checkFaceOrthogonality if (debug || report) { Info<< " Mesh non-orthogonality Max: " - << radToDeg(::acos(min(1.0, max(-1.0, minDDotS)))) + << radToDeg(::acos(clamp(minDDotS, -1, 1))) << " average: " - << radToDeg(::acos(min(1.0, max(-1.0, sumDDotS/nSummed)))) + << radToDeg(::acos(clamp(sumDDotS/nSummed, -1, 1))) << endl; } } diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H index 70f5f177b9..212cdcdc3b 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H @@ -334,7 +334,7 @@ inline Foam::scalar Foam::triangle::circumRadius() const } const scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom; - return 0.5*Foam::sqrt(min(GREAT, max(0, a))); + return 0.5*Foam::sqrt(clamp(a, 0, GREAT)); } diff --git a/src/OpenFOAM/primitives/functions/Function1/InputValueMapper/InputValueMapperI.H b/src/OpenFOAM/primitives/functions/Function1/InputValueMapper/InputValueMapperI.H index 8b769ac647..7fee35bec8 100644 --- a/src/OpenFOAM/primitives/functions/Function1/InputValueMapper/InputValueMapperI.H +++ b/src/OpenFOAM/primitives/functions/Function1/InputValueMapper/InputValueMapperI.H @@ -47,7 +47,7 @@ inline Type Foam::Function1Types::InputValueMapper::value } case mappingMode::MINMAX: { - scalar tlim = min(max(t, min_), max_); + scalar tlim = clamp(t, min_, max_); return value_->value(tlim); } @@ -86,8 +86,8 @@ Type Foam::Function1Types::InputValueMapper::integrate } case mappingMode::MINMAX: { - scalar xlim0 = min(max(x1, min_), max_); - scalar xlim1 = min(max(x2, min_), max_); + scalar xlim0 = clamp(x1, min_, max_); + scalar xlim1 = clamp(x2, min_, max_); Type intValue = value_->integrate(xlim0, xlim1); diff --git a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H index cda3b71016..2dc4e26c17 100644 --- a/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H +++ b/src/OpenFOAM/primitives/functions/Function1/ramp/ramp.H @@ -100,7 +100,7 @@ protected: //- that forms the basis of many more complex ramp functions inline scalar linearRamp(const scalar t) const { - return max(min((t - start_)/duration_, 1), 0); + return clamp((t - start_)/duration_, 0, 1); } diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H index 3738f8847a..be7a3ee8c8 100644 --- a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H +++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H @@ -85,6 +85,7 @@ Description #define Foam_MinMax_H #include "scalar.H" +#include "zero.H" #include "Pair.H" #include "Tuple2.H" #include "VectorSpace.H" @@ -97,8 +98,6 @@ namespace Foam // Forward Declarations template class MinMax; -class zero; -class zero_one; // Common min/max types typedef MinMax