From 4d7180ae7c87bc992fe52fd38f375ed050f9b6ae Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 2 Feb 2023 14:15:24 +0100 Subject: [PATCH 01/11] COMP: rename field methods clamp() -> clamp_range() - this is slightly longer to write (but consistent with clamp_min etc). The main reason is that this allows easier use of the clamp() free function. STYLE: skip checks for bad/invalid clamping ranges - ranges are either already validated before calling, the caller logic has already made the branching decision. --- applications/test/minMax2/Test-minMax2.C | 11 ++- .../FieldFields/FieldField/FieldField.C | 64 +++++++------- .../FieldFields/FieldField/FieldField.H | 16 ++-- src/OpenFOAM/fields/Fields/Field/Field.C | 41 +++++---- src/OpenFOAM/fields/Fields/Field/Field.H | 16 ++-- .../fields/Fields/Field/FieldFunctions.C | 26 +++--- .../GeometricField/GeometricField.C | 88 +++++++++---------- .../GeometricField/GeometricField.H | 56 ++++++------ 8 files changed, 158 insertions(+), 160 deletions(-) diff --git a/applications/test/minMax2/Test-minMax2.C b/applications/test/minMax2/Test-minMax2.C index 201b0548d6..531235e6f5 100644 --- a/applications/test/minMax2/Test-minMax2.C +++ b/applications/test/minMax2/Test-minMax2.C @@ -162,9 +162,16 @@ int main(int argc, char *argv[]) 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/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/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..d3576ac210 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -664,28 +664,22 @@ 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) + ); } } 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()); } }; From 3d8a6a54331f64b212ed2c96bab6ca23169f1c26 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 20 Jan 2023 09:48:40 +0100 Subject: [PATCH 02/11] ENH: use GeometricField clamp_min, clamp_max, clamp_range - newer naming allows for less confusing code. Eg, max(lower) -> clamp_min(lower) min(upper) -> clamp_max(upper) - prefer combined method, for few operations. Eg, max(lower) + min(upper) -> clamp_range(lower, upper) The updated naming also helps avoid some obvious coding errors. Eg, Re.min(1200.0); Re.max(18800.0); instead of Re.clamp_range(1200.0, 18800.0); - can also use implicit conversion of zero_one to MinMax for this type of code: lambda_.clamp_range(zero_one{}); --- applications/solvers/combustion/XiFoam/bEqn.H | 5 +- .../solvers/combustion/fireFoam/YEEqn.H | 4 +- .../solvers/combustion/reactingFoam/YEqn.H | 4 +- .../chtMultiRegionFoam/fluid/YEqn.H | 4 +- .../lagrangian/coalChemistryFoam/YEqn.H | 4 +- .../lagrangian/reactingParcelFoam/YEqn.H | 4 +- .../simpleReactingParcelFoam/YEqn.H | 4 +- .../lagrangian/simpleCoalParcelFoam/YEqn.H | 4 +- .../solvers/lagrangian/sprayFoam/YEqn.H | 4 +- .../applyBoundaryLayer/applyBoundaryLayer.C | 4 +- .../setTurbulenceFields/setTurbulenceFields.C | 10 +--- .../LES/dynamicKEqn/dynamicKEqn.C | 4 +- .../ReynoldsStress/ReynoldsStress.C | 17 +++---- .../relaxation/relaxation.C | 3 +- .../Poisson/PoissonPatchDistMethod.C | 2 +- .../advectionDiffusionPatchDistMethod.C | 2 +- src/functionObjects/field/comfort/comfort.C | 16 ++++--- .../field/limitFields/limitFields.C | 46 +++++++++++++------ .../field/limitFields/limitFields.H | 15 +++--- .../field/limitFields/limitFieldsTemplates.C | 8 ++-- .../stabilityBlendingFactor.C | 5 +- .../MultiComponentPhaseModel.C | 2 +- .../ThermalPhaseChangePhaseSystem.C | 4 +- .../TwoResistanceHeatTransferPhaseSystem.C | 4 +- .../dragModels/IshiiZuber/IshiiZuber.C | 2 +- .../liftModels/Moraga/Moraga.C | 7 +-- .../multiphaseSystem/multiphaseSystem.C | 2 +- .../MultiComponentPhaseModel.C | 4 +- .../kineticTheoryModel/kineticTheoryModel.C | 6 +-- .../twoPhaseSystem/twoPhaseSystem.C | 2 +- .../kineticTheoryModel/kineticTheoryModel.C | 6 +-- .../dragModels/IshiiZuber/IshiiZuber.C | 2 +- .../liftModels/Moraga/Moraga.C | 7 +-- .../twoPhaseSystem/twoPhaseSystem.C | 3 +- .../filmTurbulenceModel/filmTurbulenceModel.C | 2 +- .../reactingOneDim/reactingOneDim.C | 2 +- .../kinematicSingleLayer.C | 2 +- .../kinematicSingleLayerI.H | 2 +- .../filmTurbulenceModel/laminar/laminar.C | 2 +- .../thixotropicViscosity.C | 6 +-- .../waxSolventEvaporation.C | 3 +- .../thermoSingleLayer/thermoSingleLayer.C | 19 +++++--- .../thermoSingleLayer/thermoSingleLayer.H | 29 ++++++++---- .../thermoSingleLayer/thermoSingleLayerI.H | 15 +++++- .../BilgerMixtureFraction.C | 6 +-- 45 files changed, 163 insertions(+), 145 deletions(-) diff --git a/applications/solvers/combustion/XiFoam/bEqn.H b/applications/solvers/combustion/XiFoam/bEqn.H index fda39d3f51..38740d0dd5 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 { 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/utilities/preProcessing/applyBoundaryLayer/applyBoundaryLayer.C b/applications/utilities/preProcessing/applyBoundaryLayer/applyBoundaryLayer.C index 63f0e514ff..c072c06826 100644 --- a/applications/utilities/preProcessing/applyBoundaryLayer/applyBoundaryLayer.C +++ b/applications/utilities/preProcessing/applyBoundaryLayer/applyBoundaryLayer.C @@ -92,7 +92,7 @@ void blendField volScalarField fld(fieldHeader, mesh); scalarField& pf = fld.primitiveFieldRef(); pf = (1 - mask)*pf + mask*boundaryLayerField; - fld.max(SMALL); + fld.clamp_min(SMALL); // Correct the processor patches only. // Do not correct BC @@ -131,7 +131,7 @@ void calcOmegaField scalarField& pf = omega.primitiveFieldRef(); pf = (1 - mask)*pf + mask*epsilonBL/(Cmu*kBL + SMALL); - omega.max(SMALL); + omega.clamp_min(SMALL); // Correct the processor patches only. // Do not correct BC 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/src/TurbulenceModels/turbulenceModels/LES/dynamicKEqn/dynamicKEqn.C b/src/TurbulenceModels/turbulenceModels/LES/dynamicKEqn/dynamicKEqn.C index 5b173b01aa..bdfc9ef03a 100644 --- a/src/TurbulenceModels/turbulenceModels/LES/dynamicKEqn/dynamicKEqn.C +++ b/src/TurbulenceModels/turbulenceModels/LES/dynamicKEqn/dynamicKEqn.C @@ -102,7 +102,7 @@ volScalarField dynamicKEqn::Ce() const ( 0.5*(filter_(magSqr(this->U_)) - magSqr(filter_(this->U_))) ); - KK.max(dimensionedScalar("small", KK.dimensions(), SMALL)); + KK.clamp_min(SMALL); return Ce(D, KK); } @@ -245,7 +245,7 @@ void dynamicKEqn::correct() tgradU.clear(); volScalarField KK(0.5*(filter_(magSqr(U)) - magSqr(filter_(U)))); - KK.max(dimensionedScalar("small", KK.dimensions(), SMALL)); + KK.clamp_min(SMALL); tmp kEqn ( diff --git a/src/TurbulenceModels/turbulenceModels/ReynoldsStress/ReynoldsStress.C b/src/TurbulenceModels/turbulenceModels/ReynoldsStress/ReynoldsStress.C index d1e785e409..b71be0e31f 100644 --- a/src/TurbulenceModels/turbulenceModels/ReynoldsStress/ReynoldsStress.C +++ b/src/TurbulenceModels/turbulenceModels/ReynoldsStress/ReynoldsStress.C @@ -39,20 +39,15 @@ void Foam::ReynoldsStress::boundNormalStress volSymmTensorField& R ) const { - scalar kMin = this->kMin_.value(); + const scalar kMin = this->kMin_.value(); - R.max + R.clamp_min ( - dimensionedSymmTensor + symmTensor ( - "zero", - R.dimensions(), - symmTensor - ( - kMin, -GREAT, -GREAT, - kMin, -GREAT, - kMin - ) + kMin, -GREAT, -GREAT, + kMin, -GREAT, + kMin ) ); } diff --git a/src/combustionModels/FSD/reactionRateFlameAreaModels/relaxation/relaxation.C b/src/combustionModels/FSD/reactionRateFlameAreaModels/relaxation/relaxation.C index eea9d2fc7a..10df906bd5 100644 --- a/src/combustionModels/FSD/reactionRateFlameAreaModels/relaxation/relaxation.C +++ b/src/combustionModels/FSD/reactionRateFlameAreaModels/relaxation/relaxation.C @@ -136,8 +136,7 @@ void Foam::reactionRateFlameAreaModels::relaxation::correct - fvm::SuSp(rho*(tau + Rc), omega_) ); - omega_.min(omega0); - omega_.max(0.0); + omega_.clamp_range(0, omega0.value()); } diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.C b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.C index 2e54d2d5cb..5984f960c7 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.C +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.C @@ -120,7 +120,7 @@ bool Foam::patchDistMethods::Poisson::correct // Need to stabilise the y for overset meshes since the holed cells // keep the initial value (0.0) so the gradient of that will be // zero as well. Turbulence models do not like zero wall distance. - y.max(SMALL); + y.clamp_min(SMALL); // For overset: enforce smooth y field (yPsi is smooth, magGradyPsi is // not) diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C index be028a323c..4a78d65e05 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C @@ -153,7 +153,7 @@ bool Foam::patchDistMethods::advectionDiffusion::correct // Need to stabilise the y for overset meshes since the holed cells // keep the initial value (0.0) so the gradient of that will be // zero as well. Turbulence models do not like zero wall distance. - y.max(SMALL); + y.clamp_min(SMALL); // Only calculate n if the field is defined if (notNull(n)) diff --git a/src/functionObjects/field/comfort/comfort.C b/src/functionObjects/field/comfort/comfort.C index 2952500de8..ed0d465e5c 100644 --- a/src/functionObjects/field/comfort/comfort.C +++ b/src/functionObjects/field/comfort/comfort.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2019 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,6 +41,11 @@ namespace functionObjects } } + +// Temperature bounds based on EN ISO 7730 (10 - 40 degC) +static const Foam::scalarMinMax Tbounds(283.15, 313.15); + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // Foam::tmp Foam::functionObjects::comfort::magU() const @@ -93,7 +98,7 @@ Foam::dimensionedScalar Foam::functionObjects::comfort::Trad() const } // Bounds based on EN ISO 7730 - if ((Trad.value() < 283.15) || (Trad.value() > 313.15)) + if (!Tbounds.contains(Trad.value())) { WarningInFunction << "The calculated mean wall radiation temperature is out of the\n" @@ -177,9 +182,6 @@ Foam::tmp Foam::functionObjects::comfort::Tcloth Tcl.storePrevIter(); - // Same temperatures as for the radiation - const dimensionedScalar Tmin(dimTemperature, 283.15); - const dimensionedScalar Tmax(dimTemperature, 313.15); // Iterative solving of equation (2) do @@ -208,7 +210,7 @@ Foam::tmp Foam::functionObjects::comfort::Tcloth // Make sure that Tcl is in some physical limit (same range as we used // for the radiative estimation - based on ISO EN 7730:2005) - Tcl.clip(Tmin, Tmax); + Tcl.clamp_range(Tbounds); } while (!converged(Tcl) && i++ < maxClothIter_); @@ -422,7 +424,7 @@ bool Foam::functionObjects::comfort::execute() // Limit the velocity field to the values given in EN ISO 7733 volScalarField Umag(mag(lookupObject("U"))); - Umag.clip(Umin, Umax); + Umag.clamp_range(Umin, Umax); // Calculate the turbulent intensity if turbulent kinetic energy field k // exists diff --git a/src/functionObjects/field/limitFields/limitFields.C b/src/functionObjects/field/limitFields/limitFields.C index c89d230848..c03eb37fcc 100644 --- a/src/functionObjects/field/limitFields/limitFields.C +++ b/src/functionObjects/field/limitFields/limitFields.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd + Copyright (C) 2019-2023 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,9 +46,10 @@ const Foam::Enum > Foam::functionObjects::limitFields::limitTypeNames_ ({ - { limitType::MIN, "min" }, - { limitType::MAX, "max" }, - { limitType::BOTH, "both" }, + { limitType::CLAMP_MIN, "min" }, + { limitType::CLAMP_MAX, "max" }, + { limitType::CLAMP_RANGE, "range" }, + { limitType::CLAMP_RANGE, "both" }, }); @@ -67,16 +68,31 @@ bool Foam::functionObjects::limitFields::limitScalarField auto& field = *fieldPtr; - if (limit_ & MIN) + if (limitType::CLAMP_NONE != withBounds_) { - Log << ": min(" << gMin(field) << ")"; - field.max(dimensionedScalar("", field.dimensions(), min_)); + MinMax currentRange = gMinMax(field); + + if (withBounds_ & limitType::CLAMP_MIN) + { + Log << ": min(" << currentRange.min() << ')'; + } + if (withBounds_ & limitType::CLAMP_MAX) + { + Log << ": max(" << currentRange.max() << ')'; + } } - if (limit_ & MAX) + if (limitType::CLAMP_MIN == withBounds_) { - Log << ": max(" << gMax(field) << ")"; - field.min(dimensionedScalar("", field.dimensions(), max_)); + field.clamp_min(min_); + } + else if (limitType::CLAMP_MAX == withBounds_) + { + field.clamp_max(max_); + } + else if (limitType::CLAMP_RANGE == withBounds_) + { + field.clamp_range(min_, max_); } return true; @@ -93,8 +109,8 @@ Foam::functionObjects::limitFields::limitFields ) : fvMeshFunctionObject(name, runTime, dict), - limit_(MIN), fieldSet_(mesh_), + withBounds_(limitType::CLAMP_NONE), min_(-VGREAT), max_(VGREAT) { @@ -106,19 +122,21 @@ Foam::functionObjects::limitFields::limitFields bool Foam::functionObjects::limitFields::read(const dictionary& dict) { + withBounds_ = limitType::CLAMP_NONE; + if (fvMeshFunctionObject::read(dict)) { Info<< type() << " " << name() << ":" << nl; - limit_ = limitTypeNames_.get("limit", dict); + withBounds_ = limitTypeNames_.get("limit", dict); - if (limit_ & MIN) + if (withBounds_ & limitType::CLAMP_MIN) { min_ = dict.get("min"); Info<< " Imposing lower limit " << min_ << nl; } - if (limit_ & MAX) + if (withBounds_ & limitType::CLAMP_MAX) { max_ = dict.get("max"); Info<< " Imposing upper limit " << max_ << nl; diff --git a/src/functionObjects/field/limitFields/limitFields.H b/src/functionObjects/field/limitFields/limitFields.H index d40324fe8b..405d2c4316 100644 --- a/src/functionObjects/field/limitFields/limitFields.H +++ b/src/functionObjects/field/limitFields/limitFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -127,9 +127,10 @@ public: enum limitType : unsigned { - MIN = 0x1, //!< limit by minimum value - MAX = 0x2, //!< limit by maximum value - BOTH = (MIN | MAX) //!< limit by both minimum and maximum values + CLAMP_NONE = 0, //!< No limit + CLAMP_MIN = 0x1, //!< Clamp minimum value + CLAMP_MAX = 0x2, //!< Clamp maximum value + CLAMP_RANGE = (CLAMP_MIN | CLAMP_MAX) //!< Clamp min/max }; @@ -140,12 +141,12 @@ protected: //- Limit type names static const Enum limitTypeNames_; - //- Limiting type - limitType limit_; - //- Fields to limit volFieldSelection fieldSet_; + //- Limiting type + limitType withBounds_; + //- Minimum limit scalar min_; diff --git a/src/functionObjects/field/limitFields/limitFieldsTemplates.C b/src/functionObjects/field/limitFields/limitFieldsTemplates.C index 3e1bc00483..0b20a6cbe2 100644 --- a/src/functionObjects/field/limitFields/limitFieldsTemplates.C +++ b/src/functionObjects/field/limitFields/limitFieldsTemplates.C @@ -47,23 +47,23 @@ bool Foam::functionObjects::limitFields::limitField(const word& fieldName) const dimensionedScalar eps("eps", field.dimensions(), ROOTVSMALL); - if (limit_ & MIN) + if (withBounds_ & limitType::CLAMP_MIN) { volScalarField mField(typeName + ":mag" + field.name(), mag(field)); Log << " min(|" << gMin(mField) << "|)"; //field.normalise(); field /= mag(field) + eps; - mField.max(dimensionedScalar("min", field.dimensions(), min_)); + mField.clamp_min(min_); field *= mField; } - if (limit_ & MAX) + if (withBounds_ & limitType::CLAMP_MAX) { volScalarField mField(typeName + ":mag" + field.name(), mag(field)); Log << " max(|" << gMax(mField) << "|)"; //field.normalise(); field /= mag(field) + eps; - mField.min(dimensionedScalar("max", field.dimensions(), max_)); + mField.clamp_max(max_); field *= mField; } diff --git a/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C b/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C index 827d882b79..8837f3784d 100644 --- a/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C +++ b/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -448,8 +448,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first) } indicator.correctBoundaryConditions(); - indicator.min(1.0); - indicator.max(0.0); + indicator.clamp_range(zero_one{}); // Update the blended surface field auto& surBlended = mesh_.lookupObjectRef(resultName_); diff --git a/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C b/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C index 3926d26730..1dca7f055c 100644 --- a/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C +++ b/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C @@ -428,7 +428,7 @@ void Foam::MultiComponentPhaseModel::solveYi } X_[inertIndex_] = scalar(1) - Yt; - X_[inertIndex_].max(0.0); + X_[inertIndex_].clamp_min(0); calculateMassFractions(); } diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/ThermalPhaseChangePhaseSystem/ThermalPhaseChangePhaseSystem.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/ThermalPhaseChangePhaseSystem/ThermalPhaseChangePhaseSystem.C index b91b656ae4..e3a2be4b9a 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/ThermalPhaseChangePhaseSystem/ThermalPhaseChangePhaseSystem.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/ThermalPhaseChangePhaseSystem/ThermalPhaseChangePhaseSystem.C @@ -425,8 +425,8 @@ Foam::ThermalPhaseChangePhaseSystem::correctInterfaceThermo() volScalarField H2(heatTransferModelIter().second()->K()); // Limit the H[12] to avoid /0 - H1.max(SMALL); - H2.max(SMALL); + H1.clamp_min(SMALL); + H2.clamp_min(SMALL); Tf = (H1*T1 + H2*T2 + iDmdtNew*L)/(H1 + H2); diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/TwoResistanceHeatTransferPhaseSystem/TwoResistanceHeatTransferPhaseSystem.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/TwoResistanceHeatTransferPhaseSystem/TwoResistanceHeatTransferPhaseSystem.C index d2e61843e3..c08c6601a2 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/TwoResistanceHeatTransferPhaseSystem/TwoResistanceHeatTransferPhaseSystem.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/PhaseSystems/TwoResistanceHeatTransferPhaseSystem/TwoResistanceHeatTransferPhaseSystem.C @@ -297,8 +297,8 @@ correctInterfaceThermo() ); // Limit the H[12] to avoid /0 - H1.max(SMALL); - H2.max(SMALL); + H1.clamp_min(SMALL); + H2.clamp_min(SMALL); Tf = (H1*T1 + H2*T2 + dmdt*L)/(H1 + H2); diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C index 8946f1093d..44f552f592 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C @@ -86,7 +86,7 @@ Foam::dragModels::IshiiZuber::CdRe() const ); volScalarField F((muc/muMix)*sqrt(1 - pair_.dispersed())); - F.max(1e-3); + F.clamp_min(1e-3); const volScalarField Ealpha((1 + 17.67*pow(F, 0.8571428))/(18.67*F)); diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/liftModels/Moraga/Moraga.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/liftModels/Moraga/Moraga.C index 97364b5fe8..ee0067f732 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/liftModels/Moraga/Moraga.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/interfacialModels/liftModels/Moraga/Moraga.C @@ -87,11 +87,8 @@ Foam::tmp Foam::liftModels::Moraga::Cl() const << endl; } - Re.min(1200.0); - Re.max(18800.0); - - sqrSr.min(0.0016); - sqrSr.max(0.04); + Re.clamp_range(1200.0, 18800.0); + sqrSr.clamp_range(0.0016, 0.04); return 0.2*exp(- Re*sqrSr/3.6e5 - 0.12)*exp(Re*sqrSr/3.0e7); } diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/multiphaseSystem/multiphaseSystem.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/multiphaseSystem/multiphaseSystem.C index 3b795194c9..e232ec1e39 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/multiphaseSystem/multiphaseSystem.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/multiphaseSystem/multiphaseSystem.C @@ -708,7 +708,7 @@ void Foam::multiphaseSystem::solve() phase.alphaRhoPhiRef() = fvc::interpolate(phase.rho())*phase.alphaPhi(); - phase.clip(SMALL, 1 - SMALL); + phase.clamp_range(SMALL, 1 - SMALL); } calcAlphas(); diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C index 0f36a58829..9482f0244c 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/MultiComponentPhaseModel/MultiComponentPhaseModel.C @@ -124,14 +124,14 @@ void Foam::MultiComponentPhaseModel::correctThermo() if (inertIndex_ != -1) { Yi[inertIndex_] = scalar(1) - Yt; - Yi[inertIndex_].max(0); + Yi[inertIndex_].clamp_min(0); } else { forAll(Yi, i) { Yi[i] /= Yt; - Yi[i].max(0); + Yi[i].clamp_min(0); } } diff --git a/src/phaseSystemModels/reactingEuler/twoPhaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C b/src/phaseSystemModels/reactingEuler/twoPhaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C index 25572bfb3c..cab9367831 100644 --- a/src/phaseSystemModels/reactingEuler/twoPhaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C +++ b/src/phaseSystemModels/reactingEuler/twoPhaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C @@ -526,8 +526,7 @@ void Foam::RASModels::kineticTheoryModel::correct() kappa_ = conductivityModel_->kappa(alpha, Theta_, gs0_, rho, da, e_); } - Theta_.max(0); - Theta_.min(100); + Theta_.clamp_range(0, 100); { // particle viscosity (Table 3.2, p.47) @@ -559,7 +558,8 @@ void Foam::RASModels::kineticTheoryModel::correct() ); // Limit viscosity and add frictional viscosity - nut_.min(maxNut_); + nut_.clamp_max(maxNut_); + nuFric_ = min(nuFric_, maxNut_ - nut_); nut_ += nuFric_; } diff --git a/src/phaseSystemModels/reactingEuler/twoPhaseSystem/twoPhaseSystem.C b/src/phaseSystemModels/reactingEuler/twoPhaseSystem/twoPhaseSystem.C index c52aae49ed..51f8dd9898 100644 --- a/src/phaseSystemModels/reactingEuler/twoPhaseSystem/twoPhaseSystem.C +++ b/src/phaseSystemModels/reactingEuler/twoPhaseSystem/twoPhaseSystem.C @@ -340,7 +340,7 @@ void Foam::twoPhaseSystem::solve() << endl; // Ensure the phase-fractions are bounded - alpha1.clip(SMALL, 1 - SMALL); + alpha1.clamp_range(SMALL, 1 - SMALL); // Update the phase-fraction of the other phase alpha2 = scalar(1) - alpha1; diff --git a/src/phaseSystemModels/twoPhaseEuler/phaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C b/src/phaseSystemModels/twoPhaseEuler/phaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C index bca4b78442..010322104d 100644 --- a/src/phaseSystemModels/twoPhaseEuler/phaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C +++ b/src/phaseSystemModels/twoPhaseEuler/phaseCompressibleTurbulenceModels/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C @@ -530,8 +530,7 @@ void Foam::RASModels::kineticTheoryModel::correct() kappa_ = conductivityModel_->kappa(alpha, Theta_, gs0_, rho, da, e_); } - Theta_.max(0); - Theta_.min(100); + Theta_.clamp_range(0, 100); { // particle viscosity (Table 3.2, p.47) @@ -563,7 +562,8 @@ void Foam::RASModels::kineticTheoryModel::correct() ); // Limit viscosity and add frictional viscosity - nut_.min(maxNut_); + nut_.clamp_max(maxNut_); + nuFric_ = min(nuFric_, maxNut_ - nut_); nut_ += nuFric_; } diff --git a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C index 96288f39d0..5aa9237fda 100644 --- a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C +++ b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/dragModels/IshiiZuber/IshiiZuber.C @@ -87,7 +87,7 @@ Foam::dragModels::IshiiZuber::CdRe() const ); volScalarField F((muc/muMix)*sqrt(1 - pair_.dispersed())); - F.max(1e-3); + F.clamp_min(1e-3); volScalarField Ealpha((1 + 17.67*pow(F, 0.8571428))/(18.67*F)); diff --git a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/liftModels/Moraga/Moraga.C b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/liftModels/Moraga/Moraga.C index 8064581e6f..dca601c284 100644 --- a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/liftModels/Moraga/Moraga.C +++ b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/interfacialModels/liftModels/Moraga/Moraga.C @@ -87,11 +87,8 @@ Foam::tmp Foam::liftModels::Moraga::Cl() const << endl; } - Re.min(1200.0); - Re.max(18800.0); - - sqrSr.min(0.0016); - sqrSr.max(0.04); + Re.clamp_range(1200.0, 18800.0); + sqrSr.clamp_range(0.0016, 0.04); return 0.2*exp(- Re*sqrSr/3.6e5 - 0.12)*exp(Re*sqrSr/3.0e7); } diff --git a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C index f4198b56fd..fdb52fea29 100644 --- a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C +++ b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C @@ -530,8 +530,7 @@ void Foam::twoPhaseSystem::solve() << endl; // Ensure the phase-fractions are bounded - alpha1.max(0); - alpha1.min(1); + alpha1.clamp_range(zero_one{}); alpha2 = scalar(1) - alpha1; } diff --git a/src/regionFaModels/liquidFilm/subModels/kinematic/filmTurbulenceModel/filmTurbulenceModel/filmTurbulenceModel.C b/src/regionFaModels/liquidFilm/subModels/kinematic/filmTurbulenceModel/filmTurbulenceModel/filmTurbulenceModel.C index 9fbbe55b35..486ab4767c 100644 --- a/src/regionFaModels/liquidFilm/subModels/kinematic/filmTurbulenceModel/filmTurbulenceModel/filmTurbulenceModel.C +++ b/src/regionFaModels/liquidFilm/subModels/kinematic/filmTurbulenceModel/filmTurbulenceModel/filmTurbulenceModel.C @@ -128,7 +128,7 @@ tmp filmTurbulenceModel::Cw() const const scalar h0 = film_.h0().value(); Cw.primitiveFieldRef() = 3*mu/((h + h0)*rho); - Cw.min(5000.0); + Cw.clamp_max(5000.0); break; } diff --git a/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C b/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C index d3c1652d95..acadb10b20 100644 --- a/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C +++ b/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C @@ -276,7 +276,7 @@ void reactingOneDim::solveSpeciesMass() } YiEqn.solve(regionMesh().solver("Yi")); - Yi.max(0.0); + Yi.clamp_min(0); Yt += Yi; } diff --git a/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayer.C b/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayer.C index d448c5fdf6..3e624c271e 100644 --- a/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayer.C +++ b/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayer.C @@ -412,7 +412,7 @@ void kinematicSingleLayer::solveThickness } // Bound film thickness by a minimum of zero - delta_.max(0.0); + delta_.clamp_min(0); // Update U field U_ -= fvc::reconstruct(deltarUAf*phiAdd); diff --git a/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayerI.H b/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayerI.H index f3cd4b31dd..5a022e964b 100644 --- a/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayerI.H +++ b/src/regionModels/surfaceFilmModels/kinematicSingleLayer/kinematicSingleLayerI.H @@ -250,7 +250,7 @@ inline tmp kinematicSingleLayer::gNormClipped() const ); volScalarField& gNormClipped = tgNormClipped.ref(); - gNormClipped.min(0.0); + gNormClipped.clamp_max(0); return tgNormClipped; } diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/filmTurbulenceModel/laminar/laminar.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/filmTurbulenceModel/laminar/laminar.C index 67a5dd47d8..fd2bbc8de7 100644 --- a/src/regionModels/surfaceFilmModels/submodels/kinematic/filmTurbulenceModel/laminar/laminar.C +++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/filmTurbulenceModel/laminar/laminar.C @@ -136,7 +136,7 @@ tmp laminar::Su(volVectorField& U) const // employ simple coeff-based model volScalarField Cs("Cs", Cf_*rhop*mag(Up - U)); volScalarField Cw("Cw", mu/((1.0/3.0)*(delta + film.deltaSmall()))); - Cw.min(5000.0); + Cw.clamp_max(5000.0); return ( diff --git a/src/regionModels/surfaceFilmModels/submodels/thermo/filmViscosityModel/thixotropicViscosity/thixotropicViscosity.C b/src/regionModels/surfaceFilmModels/submodels/thermo/filmViscosityModel/thixotropicViscosity/thixotropicViscosity.C index f7f991820f..931b23d3ff 100644 --- a/src/regionModels/surfaceFilmModels/submodels/thermo/filmViscosityModel/thixotropicViscosity/thixotropicViscosity.C +++ b/src/regionModels/surfaceFilmModels/submodels/thermo/filmViscosityModel/thixotropicViscosity/thixotropicViscosity.C @@ -85,8 +85,7 @@ thixotropicViscosity::thixotropicViscosity film.regionMesh() ) { - lambda_.min(1); - lambda_.max(0); + lambda_.clamp_range(zero_one{}); // Initialise viscosity to inf value because it cannot be evaluated yet mu_ = muInf_; @@ -166,8 +165,7 @@ void thixotropicViscosity::correct lambdaEqn.relax(); lambdaEqn.solve(); - lambda_.min(1); - lambda_.max(0); + lambda_.clamp_range(zero_one{}); mu_ = muInf_/(sqr(1 - K_*lambda_) + ROOTVSMALL); mu_.correctBoundaryConditions(); diff --git a/src/regionModels/surfaceFilmModels/submodels/thermo/phaseChangeModel/waxSolventEvaporation/waxSolventEvaporation.C b/src/regionModels/surfaceFilmModels/submodels/thermo/phaseChangeModel/waxSolventEvaporation/waxSolventEvaporation.C index 0b20fe648f..737382070c 100644 --- a/src/regionModels/surfaceFilmModels/submodels/thermo/phaseChangeModel/waxSolventEvaporation/waxSolventEvaporation.C +++ b/src/regionModels/surfaceFilmModels/submodels/thermo/phaseChangeModel/waxSolventEvaporation/waxSolventEvaporation.C @@ -357,8 +357,7 @@ void waxSolventEvaporation::correctModel YsolventEqn.relax(); YsolventEqn.solve(); - Ysolvent_.min(1); - Ysolvent_.max(0); + Ysolvent_.clamp_range(zero_one{}); scalarField dm ( diff --git a/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.C b/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.C index d46132aa6f..79d805c38b 100644 --- a/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.C +++ b/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -478,18 +478,23 @@ thermoSingleLayer::thermoSingleLayer ), phaseChange_(phaseChangeModel::New(*this, coeffs())), radiation_(filmRadiationModel::New(*this, coeffs())), - Tmin_(-VGREAT), - Tmax_(VGREAT) + withTbounds_(limitType::CLAMP_NONE), + Tbounds_(0, 5000) { - if (coeffs().readIfPresent("Tmin", Tmin_)) + unsigned userLimits(limitType::CLAMP_NONE); + + if (coeffs().readIfPresent("Tmin", Tbounds_.min())) { - Info<< " limiting minimum temperature to " << Tmin_ << endl; + userLimits |= limitType::CLAMP_MIN; + Info<< " limiting minimum temperature to " << Tbounds_.min() << nl; } - if (coeffs().readIfPresent("Tmax", Tmax_)) + if (coeffs().readIfPresent("Tmax", Tbounds_.max())) { - Info<< " limiting maximum temperature to " << Tmax_ << endl; + userLimits |= limitType::CLAMP_MAX; + Info<< " limiting maximum temperature to " << Tbounds_.max() << nl; } + withTbounds_ = limitType(userLimits); if (thermo_.hasMultiComponentCarrier()) { diff --git a/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.H b/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.H index 4ebda18c47..6835f1dee5 100644 --- a/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.H +++ b/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayer.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,8 +41,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef thermoSingleLayer_H -#define thermoSingleLayer_H +#ifndef Foam_thermoSingleLayer_H +#define Foam_thermoSingleLayer_H #include "kinematicSingleLayer.H" #include "SLGThermo.H" @@ -69,7 +70,7 @@ class thermoSingleLayer : public kinematicSingleLayer { - // Private member functions + // Private Member Functions //- No copy construct thermoSingleLayer(const thermoSingleLayer&) = delete; @@ -83,7 +84,17 @@ class thermoSingleLayer protected: - // Protected data + // Protected Data + + //- Enumerated limiter type + enum limitType : unsigned + { + CLAMP_NONE = 0, //!< No limit + CLAMP_MIN = 0x1, //!< Clamp minimum value + CLAMP_MAX = 0x2, //!< Clamp maximum value + CLAMP_RANGE = (CLAMP_MIN | CLAMP_MAX) //!< Clamp min/max + }; + // Thermo properties @@ -184,14 +195,14 @@ protected: // Limits - //- Minimum temperature limit (optional) - scalar Tmin_; + //- Limiting type + limitType withTbounds_; - //- Maximum temperature limit (optional) - scalar Tmax_; + //- Temperature limits (optional) + scalarMinMax Tbounds_; - // Protected member functions + // Protected Member Functions //- Read control parameters from dictionary virtual bool read(); diff --git a/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayerI.H b/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayerI.H index 1da7e294d1..2cfefdc521 100644 --- a/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayerI.H +++ b/src/regionModels/surfaceFilmModels/thermoSingleLayer/thermoSingleLayerI.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -102,8 +103,18 @@ inline tmp thermoSingleLayer::T ) ); - tT.ref().min(Tmax_); - tT.ref().max(Tmin_); + if (limitType::CLAMP_MIN == withTbounds_) + { + tT.ref().clamp_min(Tbounds_.min()); + } + else if (limitType::CLAMP_MAX == withTbounds_) + { + tT.ref().clamp_max(Tbounds_.max()); + } + else if (limitType::CLAMP_RANGE == withTbounds_) + { + tT.ref().clamp_range(Tbounds_); + } return tT; } diff --git a/src/thermophysicalModels/chemistryModel/functionObjects/BilgerMixtureFraction/BilgerMixtureFraction.C b/src/thermophysicalModels/chemistryModel/functionObjects/BilgerMixtureFraction/BilgerMixtureFraction.C index dae741f81e..2db2a51f07 100644 --- a/src/thermophysicalModels/chemistryModel/functionObjects/BilgerMixtureFraction/BilgerMixtureFraction.C +++ b/src/thermophysicalModels/chemistryModel/functionObjects/BilgerMixtureFraction/BilgerMixtureFraction.C @@ -89,11 +89,7 @@ void Foam::functionObjects::BilgerMixtureFraction::calcBilgerMixtureFraction() /thermo_.W(i); } f_Bilger /= o2RequiredFuelOx_; - f_Bilger.clip - ( - dimensionedScalar(dimless, 0), - dimensionedScalar(dimless, 1) - ); + f_Bilger.clamp_range(zero_one{}); } From 6f68ce5239fca6628bf2c9c9047d05abbe45ef81 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 19 Jan 2023 09:40:26 +0100 Subject: [PATCH 03/11] ENH: update field function macros and 'reuse' field handling - clearer, more consistent parameter naming, which helps when maintaining different field function types (eg, DimensionedFields, GeometricFields) - provide reuseTmpGeometricField::New taking a reference (not a tmp), with forwarding. This helps centralise naming and acquisition etc - split binary function macros into transform/interface for easier support of different transform loops. - initial field macros for looping over ternaries --- .../DimensionedFieldFunctions.C | 416 ++++++------ .../DimensionedFieldFunctions.H | 96 +-- .../DimensionedFieldFunctionsM.C | 534 ++++++++-------- .../DimensionedFieldFunctionsM.H | 209 ++++--- .../DimensionedFieldReuseFunctions.H | 149 +++-- .../FieldField/FieldFieldFunctions.C | 245 +++----- .../FieldField/FieldFieldFunctions.H | 2 +- .../FieldField/FieldFieldFunctionsM.C | 207 +++--- .../FieldField/FieldFieldFunctionsM.H | 61 +- .../FieldField/FieldFieldReuseFunctions.H | 30 +- .../fields/Fields/Field/FieldFunctions.C | 460 +++++++------- .../fields/Fields/Field/FieldFunctionsM.C | 188 +++--- .../fields/Fields/Field/FieldFunctionsM.H | 130 ++-- src/OpenFOAM/fields/Fields/Field/FieldM.H | 113 +++- .../fields/Fields/Field/FieldReuseFunctions.H | 21 +- .../Fields/Field/undefFieldFunctionsM.H | 27 +- .../GeometricField/GeometricFieldFunctions.C | 592 ++++++++---------- .../GeometricField/GeometricFieldFunctions.H | 151 ++--- .../GeometricField/GeometricFieldFunctionsM.C | 533 +++++++--------- .../GeometricField/GeometricFieldFunctionsM.H | 207 +++--- .../GeometricFieldReuseFunctions.H | 154 +++-- 21 files changed, 2292 insertions(+), 2233 deletions(-) diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C index 487c655226..841324d1f2 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; \ } @@ -347,7 +322,7 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clip) -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -363,32 +338,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 +366,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 +475,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 +550,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..3adb4ececb 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) @@ -140,7 +140,7 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clip) -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -156,102 +156,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..e8ee293203 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) \ diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H index d7484d1729..a3157242f2 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 \ ); 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/FieldFieldFunctions.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C index 9be878df3d..abfeab9928 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; } @@ -676,7 +633,7 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) -/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ +/* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */ UNARY_OPERATOR(Type, Type, -, negate) @@ -692,7 +649,7 @@ BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define PRODUCT_OPERATOR(product, op, opFunc) \ +#define PRODUCT_OPERATOR(product, Op, OpFunc) \ \ template \ < \ @@ -701,7 +658,7 @@ template \ class Type1, \ class Type2 \ > \ -void opFunc \ +void OpFunc \ ( \ FieldField::type>& f, \ const FieldField& f1, \ @@ -712,7 +669,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 +681,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 +716,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 +737,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 +758,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 +784,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 +808,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 +829,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 +850,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 +874,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 +895,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..b1b0501e95 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H @@ -290,7 +290,7 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax, clamp) -/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ +/* * * * * * * * * * * * * * * * 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..d2dc88ce0b 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,5 @@ tmp> operator Op \ BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) + // ************************************************************************* // diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.H index 1771f2365a..1e3b0501e8 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 \ ); \ 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/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index d3576ac210..f3e136c2e9 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 ( @@ -683,30 +700,7 @@ void clamp } } -template -tmp> clamp -( - const UList& f1, - const MinMax& range -) -{ - auto tres = tmp>::New(f1.size()); - clamp(tres.ref(), f1, range); - return tres; -} - -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(Type, Type, Type, max) @@ -743,21 +737,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; \ } \ @@ -766,8 +760,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; \ @@ -777,8 +771,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; \ @@ -788,8 +782,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(); \ @@ -799,22 +793,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; \ } \ @@ -827,8 +821,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; \ @@ -837,22 +831,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; \ } \ @@ -864,8 +858,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/FieldFunctionsM.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C index 59b7a1fd24..e82f2e6345 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 \ diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.H index f975bffa52..1730ad22ba 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 \ ); \ 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/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C index f6eb4fafd5..0c686d3be2 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,7 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -564,64 +496,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 +559,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 +589,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 +619,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 +695,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 +741,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 +799,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 +844,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..9b91dc3c07 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) @@ -273,7 +274,7 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) -// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) @@ -289,16 +290,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 +309,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 +322,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 +335,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 +348,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 +371,9 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const dimensioned& dvs \ ); \ \ @@ -389,9 +390,9 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const GeometricField& gf1, \ + const GeometricField& f1, \ const VectorSpace& vs \ ); \ \ @@ -402,9 +403,9 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ - const tmp>& tgf1, \ + const tmp>& tf1, \ const dimensioned& dvs \ ); \ \ @@ -421,20 +422,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 +445,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ); \ \ template \ @@ -463,10 +464,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const VectorSpace& vs, \ - const GeometricField& gf1 \ + const GeometricField& f2 \ ); \ \ template \ @@ -476,10 +477,10 @@ tmp \ GeometricField \ ::type, PatchField, GeoMesh> \ > \ -operator op \ +operator Op \ ( \ const dimensioned& dvs, \ - const tmp>& tgf1 \ + const tmp>& tf2 \ ); \ \ template \ @@ -495,10 +496,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..97b916586a 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); \ } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.H index 83109528dd..0af9f5159d 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 \ ); 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 From ab10b4a05cfdba1a27b0abedb3c6c033e5a80c1b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sat, 21 Jan 2023 22:30:33 +0100 Subject: [PATCH 04/11] EHN: add FieldFunction interface for 0/1 clamping - enables clamp(field, zero_one{}) returning a tmp Field --- applications/test/minMax2/Test-minMax2.C | 6 +- .../DimensionedFieldFunctions.C | 67 +++++++++++++++++- .../DimensionedFieldFunctions.H | 31 ++++++++- .../FieldField/FieldFieldFunctions.C | 1 + .../FieldField/FieldFieldFunctions.H | 1 + .../fields/Fields/Field/FieldFunctions.C | 26 +++++++ .../fields/Fields/Field/FieldFunctions.H | 1 + .../GeometricField/GeometricFieldFunctions.C | 68 +++++++++++++++++++ .../GeometricField/GeometricFieldFunctions.H | 30 ++++++++ .../primitives/ranges/MinMax/MinMax.H | 3 +- 10 files changed, 227 insertions(+), 7 deletions(-) diff --git a/applications/test/minMax2/Test-minMax2.C b/applications/test/minMax2/Test-minMax2.C index 531235e6f5..136681d75c 100644 --- a/applications/test/minMax2/Test-minMax2.C +++ b/applications/test/minMax2/Test-minMax2.C @@ -152,13 +152,13 @@ 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; diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C index 841324d1f2..c2217d2fd1 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C @@ -319,7 +319,72 @@ 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; +} + + +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) // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H index 3adb4ececb..537c736624 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H @@ -137,7 +137,36 @@ 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 * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C index abfeab9928..dfda7e3602 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C @@ -630,6 +630,7 @@ 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) diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H index b1b0501e95..9776c63c37 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H @@ -287,6 +287,7 @@ 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) diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index f3e136c2e9..4a4e8d1177 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -700,7 +700,33 @@ void clamp } } +template +void clamp +( + Field& result, + const UList& f1, + const Foam::zero_one& // Note: macros generate a const reference +) +{ + 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{}) + ); + } +} + BINARY_FUNCTION_INTERFACE_FS(Type, Type, MinMax, clamp) +BINARY_FUNCTION_INTERFACE_FS(Type, Type, Foam::zero_one, clamp) BINARY_FUNCTION(Type, Type, Type, max) diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H index 57a0c5db18..9307b9d155 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H @@ -314,6 +314,7 @@ 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 diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C index 0c686d3be2..a62fd98b54 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C @@ -480,6 +480,74 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) +// ------------------------------------------------------------------------- // + +// 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) + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // UNARY_OPERATOR(Type, Type, -, negate, transform) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H index 9b91dc3c07..937a07e443 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H @@ -273,6 +273,36 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) +// ------------------------------------------------------------------------- // + +// 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) + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // 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