diff --git a/etc/caseDicts/postProcessing/fields/divide b/etc/caseDicts/postProcessing/fields/divide new file mode 100644 index 0000000000..080be24cca --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/divide @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + From the first field divide the remaining fields in the list. + +\*---------------------------------------------------------------------------*/ + +type divide; +libs ("libfieldFunctionObjects.so"); + +fields (); + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/etc/caseDicts/postProcessing/fields/multiply b/etc/caseDicts/postProcessing/fields/multiply new file mode 100644 index 0000000000..e60510e66b --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/multiply @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Multiply a list of fields. + +\*---------------------------------------------------------------------------*/ + +type multiply; +libs ("libfieldFunctionObjects.so"); + +fields (); + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/etc/caseDicts/postProcessing/fields/uniform b/etc/caseDicts/postProcessing/fields/uniform new file mode 100644 index 0000000000..a0bcf77189 --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/uniform @@ -0,0 +1,24 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Create a uniform field. + +\*---------------------------------------------------------------------------*/ + +type uniform; +libs ("libfieldFunctionObjects.so"); + +fieldType ; +name ; +dimensions ; +value ; + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 69f939e24a..c2eab6aea2 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -68,6 +68,8 @@ streamFunction/streamFunction.C fieldsExpression/fieldsExpression.C add/add.C subtract/subtract.C +multiply/multiply.C +divide/divide.C interfaceHeight/interfaceHeight.C @@ -77,4 +79,6 @@ comfort/comfort.C cylindrical/cylindricalFunctionObject.C +uniform/uniform.C + LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects diff --git a/src/functionObjects/field/add/add.C b/src/functionObjects/field/add/add.C index 7b9f68e82f..47f6d6229b 100644 --- a/src/functionObjects/field/add/add.C +++ b/src/functionObjects/field/add/add.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "add.H" +#include "ops.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -38,11 +39,28 @@ namespace functionObjects } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +< + class A, + class B, + class R = decltype(std::declval() + std::declval()) +> +struct plusOpAuto +{ + R operator()(const A& a, const B& b) + { + return a + b; + } +}; + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // bool Foam::functionObjects::add::calc() { - return calcAllTypes(*this); + return calcOp(); } diff --git a/src/functionObjects/field/add/add.H b/src/functionObjects/field/add/add.H index b1f3c81ead..2f72d782f7 100644 --- a/src/functionObjects/field/add/add.H +++ b/src/functionObjects/field/add/add.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,20 +74,12 @@ class add { // Private Member Functions - //- Add the list of fields of the specified type - // and return the result - template - tmp calcFieldType() const; - //- Add the list of fields and return true if successful virtual bool calc(); public: - friend class fieldsExpression; - - //- Runtime type information TypeName("add"); @@ -115,12 +107,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "addTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/functionObjects/field/divide/divide.C b/src/functionObjects/field/divide/divide.C new file mode 100644 index 0000000000..ea6c17287d --- /dev/null +++ b/src/functionObjects/field/divide/divide.C @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +// There is some include hell going on with regards to the scalar-divided-by- +// sphericalTensor operation. This rather odd include sequence resolves it. + +#include "Field.H" +#include "sphericalTensorFieldField.H" +#include "divide.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(divide, 0); + addToRunTimeSelectionTable(functionObject, divide, dictionary); +} +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +< + class A, + class B, + class R = decltype(std::declval()/std::declval()) +> +struct divideOpAuto +{ + R operator()(const A& a, const B& b) + { + return a/b; + } +}; + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::divide::calc() +{ + return calcOp(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::divide::divide +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fieldsExpression(name, runTime, dict) +{ + setResultName("divide"); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::divide::~divide() +{} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/divide/divide.H b/src/functionObjects/field/divide/divide.H new file mode 100644 index 0000000000..d85ff510ff --- /dev/null +++ b/src/functionObjects/field/divide/divide.H @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::divide + +Description + Divide a list of fields. + + The numerator can be any volume or surface field and the denominators can + be scalar volume or surface fields. + + Example of function object specification: + \verbatim + Ttot + { + type divide; + libs ("libfieldFunctionObjects.so"); + fields (rho p); + result psi; + executeControl writeTime; + writeControl writeTime; + } + \endverbatim + +See also + Foam::functionObjects::fieldsExpression + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + divide.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_divide_H +#define functionObjects_divide_H + +#include "fieldsExpression.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class divide Declaration +\*---------------------------------------------------------------------------*/ + +class divide +: + public fieldsExpression +{ + // Private Member Functions + + //- Multiply the list of fields and return true if successful + virtual bool calc(); + + +public: + + //- Runtime type information + TypeName("divide"); + + + // Constructors + + //- Construct from Time and dictionary + divide + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + + //- Destructor + virtual ~divide(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/fieldsExpression/fieldsExpression.C b/src/functionObjects/field/fieldsExpression/fieldsExpression.C index 6a5f56eadd..c82c4262ec 100644 --- a/src/functionObjects/field/fieldsExpression/fieldsExpression.C +++ b/src/functionObjects/field/fieldsExpression/fieldsExpression.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -127,9 +127,38 @@ bool Foam::functionObjects::fieldsExpression::execute() { if (!calc()) { - Warning - << " functionObjects::" << type() << " " << name() - << " cannot find required fields " << fieldNames_ << endl; + DynamicList notFoundFieldNames; + forAll(fieldNames_, i) + { + bool found = false; + + #define findFieldType(Type, GeoField) \ + found = \ + found \ + || mesh_.foundObject>(fieldNames_[i]); + FOR_ALL_FIELD_TYPES(findFieldType, VolField); + FOR_ALL_FIELD_TYPES(findFieldType, SurfaceField); + #undef findFieldType + + if (!found) + { + notFoundFieldNames.append(fieldNames_[i]); + } + } + + if (!notFoundFieldNames.empty()) + { + Warning + << "functionObjects::" << type() << " " << name() + << " cannot find fields " << notFoundFieldNames << endl; + } + else + { + Warning + << "functionObjects::" << type() << " " << name() + << " fields are not compatible with the " << type() + << " function" << endl; + } // Clear the result fields from the objectRegistry if present clear(); diff --git a/src/functionObjects/field/fieldsExpression/fieldsExpression.H b/src/functionObjects/field/fieldsExpression/fieldsExpression.H index dc06d9cab6..88546ff6ee 100644 --- a/src/functionObjects/field/fieldsExpression/fieldsExpression.H +++ b/src/functionObjects/field/fieldsExpression/fieldsExpression.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -68,26 +68,74 @@ protected: // Protected member functions + //- Set the result name void setResultName ( const word& functionName, const wordList& defaultFieldNames = wordList::null() ); - //- Call 'calcFieldType' for the given functionObject - // for 'volField' and 'surfaceField' field types - template - bool calcFieldTypes(FOType& fo); + //- Operate on the fields and store the result. Supported overload. + template + < + template class GeoField, + template class Op, + class TypeA, + class TypeB, + class Enable = Op + > + bool opAndStore + ( + const GeoField& a, + const GeoField& b + ); - //- Call 'calcFieldTypes' for the given 'Type' and functionObject - template - bool calcType(FOType& fo); + //- Operate on the fields and store the result. Not-supported overload. + template + < + template class GeoField, + template class Op, + class ... Args + > + bool opAndStore(const Args& ...); - //- Call 'calcType' for the given functionObject - // for each primitive type - template - bool calcAllTypes(FOType& fo); + //- Fold the fields expression up one place + template + < + template class GeoField, + template class Op, + class TypeA, + class TypeB + > + bool foldAB(const label i); + //- Fold the fields expression up one place + template + < + template class GeoField, + template class Op, + class TypeA + > + bool foldA(const label i); + + //- Fold the fields expression up one place + template + < + template class GeoField, + template class Op + > + bool fold(const label i); + + //- Calculate and store the fields expression for the given geometric + // field type and operation + template class GeoField, template class Op> + bool calcGeoFieldOp(); + + //- Calculate and store the fields expression for the given operation + template class Op> + bool calcOp(); + + //- Perform calculation on the list of fields and return success virtual bool calc() = 0; diff --git a/src/functionObjects/field/fieldsExpression/fieldsExpressionTemplates.C b/src/functionObjects/field/fieldsExpression/fieldsExpressionTemplates.C index 2eb0b182e6..705f8aab6e 100644 --- a/src/functionObjects/field/fieldsExpression/fieldsExpressionTemplates.C +++ b/src/functionObjects/field/fieldsExpression/fieldsExpressionTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,57 +23,142 @@ License \*---------------------------------------------------------------------------*/ +#include "fieldsExpression.H" #include "volFields.H" #include "surfaceFields.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -template -bool Foam::functionObjects::fieldsExpression::calcFieldTypes(FOType& fo) +template +< + template class GeoField, + template class Op, + class TypeA, + class TypeB, + class Enable +> +bool Foam::functionObjects::fieldsExpression::opAndStore +( + const GeoField& a, + const GeoField& b +) { - typedef GeometricField VolFieldType; - typedef GeometricField SurfaceFieldType; - - if (foundObject(fieldNames_[0])) - { - return store - ( - resultName_, - fo.template calcFieldType() - ); - } - else if (foundObject(fieldNames_[0])) - { - return store - ( - resultName_, - fo.template calcFieldType() - ); - } - else - { - return false; - } + return store(resultName_, Op, GeoField>()(a, b)); } -template -bool Foam::functionObjects::fieldsExpression::calcType(FOType& fo) +template +< + template class GeoField, + template class Op, + class ... Args +> +bool Foam::functionObjects::fieldsExpression::opAndStore +( + const Args& ... +) { - return calcFieldTypes(fo); + return false; } -template -bool Foam::functionObjects::fieldsExpression::calcAllTypes(FOType& fo) +template +< + template class GeoField, + template class Op, + class TypeA, + class TypeB +> +bool Foam::functionObjects::fieldsExpression::foldAB(const label i) { - bool processed = false; + if + ( + i == 0 + && foundObject>(fieldNames_[0]) + ) + { + clearObject(resultName_); + return store + ( + resultName_, + lookupObject>(fieldNames_[0]).clone() + ); + } - #define processType(fieldType, none) \ - processed = processed || fo.template calcType(fo); - FOR_ALL_FIELD_TYPES(processType) + if + ( + i > 0 + && foundObject>(resultName_) + && foundObject>(fieldNames_[i]) + ) + { + tmp> a = + lookupObject>(resultName_).clone(); + const GeoField& b = + lookupObject>(fieldNames_[i]); - return processed; + clearObject(resultName_); + return opAndStore(a(), b); + } + + return false; +} + + +template +< + template class GeoField, + template class Op, + class TypeA +> +bool Foam::functionObjects::fieldsExpression::foldA(const label i) +{ + bool success = false; + + #define processType(Type, none) \ + success = success || foldAB(i); + FOR_ALL_FIELD_TYPES(processType); + #undef processType + + return success; +} + + +template class GeoField, template class Op> +bool Foam::functionObjects::fieldsExpression::fold(const label i) +{ + bool success = false; + + #define processType(Type, none) \ + success = success || foldA(i); + FOR_ALL_FIELD_TYPES(processType); + #undef processType + + return success; +} + + +template class GeoField, template class Op> +bool Foam::functionObjects::fieldsExpression::calcGeoFieldOp() +{ + forAll(fieldNames_, i) + { + if (!fold(i)) + { + return false; + } + } + + return true; +} + + +template class Op> +bool Foam::functionObjects::fieldsExpression::calcOp() +{ + return + calcGeoFieldOp() + || calcGeoFieldOp(); } diff --git a/src/functionObjects/field/add/addTemplates.C b/src/functionObjects/field/multiply/multiply.C similarity index 53% rename from src/functionObjects/field/add/addTemplates.C rename to src/functionObjects/field/multiply/multiply.C index 25332c19dc..387096ec36 100644 --- a/src/functionObjects/field/add/addTemplates.C +++ b/src/functionObjects/field/multiply/multiply.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,25 +23,65 @@ License \*---------------------------------------------------------------------------*/ -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +#include "multiply.H" +#include "addToRunTimeSelectionTable.H" -template -Foam::tmp -Foam::functionObjects::add::calcFieldType() const +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam { - tmp tresult - ( - lookupObject(fieldNames_[0]) - + lookupObject(fieldNames_[1]) - ); - - for (label i=2; i(fieldNames_[i]); - } - - return tresult; +namespace functionObjects +{ + defineTypeNameAndDebug(multiply, 0); + addToRunTimeSelectionTable(functionObject, multiply, dictionary); +} } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +< + class A, + class B, + class R = decltype(std::declval()*std::declval()) +> +struct multiplyOpAuto +{ + R operator()(const A& a, const B& b) + { + return a*b; + } +}; + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::multiply::calc() +{ + return calcOp(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::multiply::multiply +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fieldsExpression(name, runTime, dict) +{ + setResultName("multiply"); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::multiply::~multiply() +{} + + // ************************************************************************* // diff --git a/src/functionObjects/field/multiply/multiply.H b/src/functionObjects/field/multiply/multiply.H new file mode 100644 index 0000000000..5e93b745b3 --- /dev/null +++ b/src/functionObjects/field/multiply/multiply.H @@ -0,0 +1,113 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::multiply + +Description + Multiply a list of fields. + + The operation can be applied to any volume or surface fields provided that + the resulting multiplication does not produce a tensor of rank greater than + two. + + Example of function object specification: + \verbatim + Ttot + { + type multiply; + libs ("libfieldFunctionObjects.so"); + fields (rho U); + result rhoU; + executeControl writeTime; + writeControl writeTime; + } + \endverbatim + +See also + Foam::functionObjects::fieldsExpression + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + multiply.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_multiply_H +#define functionObjects_multiply_H + +#include "fieldsExpression.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class multiply Declaration +\*---------------------------------------------------------------------------*/ + +class multiply +: + public fieldsExpression +{ + // Private Member Functions + + //- Multiply the list of fields and return true if successful + virtual bool calc(); + + +public: + + //- Runtime type information + TypeName("multiply"); + + + // Constructors + + //- Construct from Time and dictionary + multiply + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + + //- Destructor + virtual ~multiply(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/subtract/subtract.C b/src/functionObjects/field/subtract/subtract.C index 42d3fadc2d..01831712de 100644 --- a/src/functionObjects/field/subtract/subtract.C +++ b/src/functionObjects/field/subtract/subtract.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,11 +38,28 @@ namespace functionObjects } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +< + class A, + class B, + class R = decltype(std::declval() - std::declval()) +> +struct minusOpAuto +{ + R operator()(const A& a, const B& b) + { + return a - b; + } +}; + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // bool Foam::functionObjects::subtract::calc() { - return calcAllTypes(*this); + return calcOp(); } diff --git a/src/functionObjects/field/subtract/subtract.H b/src/functionObjects/field/subtract/subtract.H index 759670fdf4..52194d8b79 100644 --- a/src/functionObjects/field/subtract/subtract.H +++ b/src/functionObjects/field/subtract/subtract.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,20 +74,12 @@ class subtract { // Private Member Functions - //- Subtract the list of fields of the specified type - // and return the result - template - tmp calcFieldType() const; - //- Subtract the list of fields and return true if successful virtual bool calc(); public: - friend class fieldsExpression; - - //- Runtime type information TypeName("subtract"); @@ -115,12 +107,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "subtractTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/functionObjects/field/subtract/subtractTemplates.C b/src/functionObjects/field/subtract/subtractTemplates.C deleted file mode 100644 index 89b50d7f5c..0000000000 --- a/src/functionObjects/field/subtract/subtractTemplates.C +++ /dev/null @@ -1,47 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -Foam::tmp -Foam::functionObjects::subtract::calcFieldType() const -{ - tmp tresult - ( - lookupObject(fieldNames_[0]) - - lookupObject(fieldNames_[1]) - ); - - for (label i=2; i(fieldNames_[i]); - } - - return tresult; -} - - -// ************************************************************************* // diff --git a/src/functionObjects/field/uniform/uniform.C b/src/functionObjects/field/uniform/uniform.C new file mode 100644 index 0000000000..c0c7fec111 --- /dev/null +++ b/src/functionObjects/field/uniform/uniform.C @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "uniform.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(uniform, 0); + addToRunTimeSelectionTable(functionObject, uniform, dictionary); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::uniform::uniform +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + fieldType_(word::null), + name_(word::null), + dimensions_(dimless) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::uniform::~uniform() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::uniform::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + + fieldType_ = dict.lookup("fieldType"); + name_ = dict.lookup("name"); + dimensions_.reset(dict.lookup("dimensions")); + + bool ok = false; + #define readValueType(Type, GeoField) \ + if (GeoField::typeName == fieldType_) \ + { \ + ok = true; \ + Type##Value_ = dict.lookup("value"); \ + } + FOR_ALL_FIELD_TYPES(readValueType, VolField); + FOR_ALL_FIELD_TYPES(readValueType, SurfaceField); + #undef readValueType + + if (!ok) + { + FatalErrorInFunction + << "Field type " << fieldType_ << " not recognised" << endl << endl; + + DynamicList fieldTypes; + #define getFieldType(Type, GeoField) \ + fieldTypes.append(GeoField::typeName); + FOR_ALL_FIELD_TYPES(getFieldType, VolField); + FOR_ALL_FIELD_TYPES(getFieldType, SurfaceField); + #undef getFieldType + + FatalErrorInFunction + << "Available field types are : " << endl + << fieldTypes + << exit(FatalError); + } + + return true; +} + + +bool Foam::functionObjects::uniform::execute() +{ + #define calcType(Type, GeoField) \ + if (GeoField::typeName == fieldType_) \ + { \ + store \ + ( \ + name_, \ + GeoField::New \ + ( \ + name_, \ + mesh_, \ + dimensioned(dimensions_, Type##Value_) \ + ) \ + ); \ + } + FOR_ALL_FIELD_TYPES(calcType, VolField); + FOR_ALL_FIELD_TYPES(calcType, SurfaceField); + #undef calcType + + return true; +} + + +bool Foam::functionObjects::uniform::write() +{ + return writeObject(name_); +} + + +bool Foam::functionObjects::uniform::clear() +{ + return clearObject(name_); +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/uniform/uniform.H b/src/functionObjects/field/uniform/uniform.H new file mode 100644 index 0000000000..3e521a1282 --- /dev/null +++ b/src/functionObjects/field/uniform/uniform.H @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::uniform + +Description + Generate a uniform field + +See also + Foam::functionObjects::fieldExpression + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + uniform.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_uniform_H +#define functionObjects_uniform_H + +#include "fvMeshFunctionObject.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class uniform Declaration +\*---------------------------------------------------------------------------*/ + +class uniform +: + public fvMeshFunctionObject +{ + // Private Data + + //- The type of the field to be written + word fieldType_; + + //- The field's name + word name_; + + //- The field's dimensions + dimensionSet dimensions_; + + //- The field's value + #define valueType(Type, none) Type Type##Value_; + FOR_ALL_FIELD_TYPES(valueType); + #undef valueType + + +public: + + //- Runtime type information + TypeName("uniform"); + + + // Constructors + + //- Construct from Time and dictionary + uniform + ( + const word& name, + const Time&, + const dictionary& + ); + + + //- Destructor + virtual ~uniform(); + + + // Member Functions + + //- Read the uniform data + virtual bool read(const dictionary&); + + //- Calculate the field + virtual bool execute(); + + //- Write the field + virtual bool write(); + + //- Clear the field from the objectRegistry + virtual bool clear(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //