functionObjects: fieldsExpression: Type flexibility and new operations

The fieldsExpression function has been generalised to work with a
general operator. Existing functions "add" and "subtract" have been made
to use this system, and two new operations, "multiply" and "divide",
have been added.

The functions can now handle multiple types in both input and output. A
multiply (outer product) operation on two vectors and a scalar will
result in a tensor. If the operation chain is not supported (e.g.,
division by a vector) then a warning will be generated.

In addition, a "uniform" function has been added, which will create a
uniform geometric field of a given type with specified dimensions and
calculated boundary conditions. This is mostly useful for testing
purposes and for conveniently creating simple input fields for the
operation functions described above. The function can be called by
postProcess as follows:

    postProcess -func "uniform(fieldType=volScalarField, name=length, dimensions=[m], value=2)"
This commit is contained in:
Will Bainbridge
2021-07-08 13:49:21 +01:00
parent 056cc20f34
commit 0b68176c60
18 changed files with 968 additions and 150 deletions

View File

@ -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 (<fieldNames>);
executeControl writeTime;
writeControl writeTime;
// ************************************************************************* //

View File

@ -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 (<fieldNames>);
executeControl writeTime;
writeControl writeTime;
// ************************************************************************* //

View File

@ -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 <fieldType>;
name <name>;
dimensions <dimensions>;
value <value>;
executeControl writeTime;
writeControl writeTime;
// ************************************************************************* //

View File

@ -68,6 +68,8 @@ streamFunction/streamFunction.C
fieldsExpression/fieldsExpression.C fieldsExpression/fieldsExpression.C
add/add.C add/add.C
subtract/subtract.C subtract/subtract.C
multiply/multiply.C
divide/divide.C
interfaceHeight/interfaceHeight.C interfaceHeight/interfaceHeight.C
@ -77,4 +79,6 @@ comfort/comfort.C
cylindrical/cylindricalFunctionObject.C cylindrical/cylindricalFunctionObject.C
uniform/uniform.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "add.H" #include "add.H"
#include "ops.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -38,11 +39,28 @@ namespace functionObjects
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
<
class A,
class B,
class R = decltype(std::declval<A>() + std::declval<B>())
>
struct plusOpAuto
{
R operator()(const A& a, const B& b)
{
return a + b;
}
};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::add::calc() bool Foam::functionObjects::add::calc()
{ {
return calcAllTypes(*this); return calcOp<plusOpAuto>();
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -74,20 +74,12 @@ class add
{ {
// Private Member Functions // Private Member Functions
//- Add the list of fields of the specified type
// and return the result
template<class GeoFieldType>
tmp<GeoFieldType> calcFieldType() const;
//- Add the list of fields and return true if successful //- Add the list of fields and return true if successful
virtual bool calc(); virtual bool calc();
public: public:
friend class fieldsExpression;
//- Runtime type information //- Runtime type information
TypeName("add"); TypeName("add");
@ -115,12 +107,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "addTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// 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<A>()/std::declval<B>())
>
struct divideOpAuto
{
R operator()(const A& a, const B& b)
{
return a/b;
}
};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::divide::calc()
{
return calcOp<divideOpAuto>();
}
// * * * * * * * * * * * * * * * * 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()
{}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -126,10 +126,39 @@ bool Foam::functionObjects::fieldsExpression::read(const dictionary& dict)
bool Foam::functionObjects::fieldsExpression::execute() bool Foam::functionObjects::fieldsExpression::execute()
{ {
if (!calc()) if (!calc())
{
DynamicList<word> notFoundFieldNames;
forAll(fieldNames_, i)
{
bool found = false;
#define findFieldType(Type, GeoField) \
found = \
found \
|| mesh_.foundObject<GeoField<Type>>(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 Warning
<< " functionObjects::" << type() << " " << name() << "functionObjects::" << type() << " " << name()
<< " cannot find required fields " << fieldNames_ << endl; << " 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 the result fields from the objectRegistry if present
clear(); clear();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -68,26 +68,74 @@ protected:
// Protected member functions // Protected member functions
//- Set the result name
void setResultName void setResultName
( (
const word& functionName, const word& functionName,
const wordList& defaultFieldNames = wordList::null() const wordList& defaultFieldNames = wordList::null()
); );
//- Call 'calcFieldType' for the given functionObject //- Operate on the fields and store the result. Supported overload.
// for 'volField' and 'surfaceField' field types template
template<class Type, class FOType> <
bool calcFieldTypes(FOType& fo); template<class> class GeoField,
template<class ...> class Op,
class TypeA,
class TypeB,
class Enable = Op<TypeA, TypeB>
>
bool opAndStore
(
const GeoField<TypeA>& a,
const GeoField<TypeB>& b
);
//- Call 'calcFieldTypes' for the given 'Type' and functionObject //- Operate on the fields and store the result. Not-supported overload.
template<class Type, class FOType> template
bool calcType(FOType& fo); <
template<class> class GeoField,
template<class ...> class Op,
class ... Args
>
bool opAndStore(const Args& ...);
//- Call 'calcType' for the given functionObject //- Fold the fields expression up one place
// for each primitive type template
template<class FOType> <
bool calcAllTypes(FOType& fo); template<class> class GeoField,
template<class ...> class Op,
class TypeA,
class TypeB
>
bool foldAB(const label i);
//- Fold the fields expression up one place
template
<
template<class> class GeoField,
template<class ...> class Op,
class TypeA
>
bool foldA(const label i);
//- Fold the fields expression up one place
template
<
template<class> class GeoField,
template<class ...> class Op
>
bool fold(const label i);
//- Calculate and store the fields expression for the given geometric
// field type and operation
template<template<class> class GeoField, template<class ...> class Op>
bool calcGeoFieldOp();
//- Calculate and store the fields expression for the given operation
template<template<class ...> class Op>
bool calcOp();
//- Perform calculation on the list of fields and return success
virtual bool calc() = 0; virtual bool calc() = 0;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,57 +23,142 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fieldsExpression.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type, class FOType> template
bool Foam::functionObjects::fieldsExpression::calcFieldTypes(FOType& fo) <
template<class> class GeoField,
template<class ...> class Op,
class TypeA,
class TypeB,
class Enable
>
bool Foam::functionObjects::fieldsExpression::opAndStore
(
const GeoField<TypeA>& a,
const GeoField<TypeB>& b
)
{ {
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType; return store(resultName_, Op<GeoField<TypeA>, GeoField<TypeB>>()(a, b));
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType; }
if (foundObject<VolFieldType>(fieldNames_[0]))
template
<
template<class> class GeoField,
template<class ...> class Op,
class ... Args
>
bool Foam::functionObjects::fieldsExpression::opAndStore
(
const Args& ...
)
{
return false;
}
template
<
template<class> class GeoField,
template<class ...> class Op,
class TypeA,
class TypeB
>
bool Foam::functionObjects::fieldsExpression::foldAB(const label i)
{
if
(
i == 0
&& foundObject<GeoField<TypeA>>(fieldNames_[0])
)
{ {
clearObject(resultName_);
return store return store
( (
resultName_, resultName_,
fo.template calcFieldType<VolFieldType>() lookupObject<GeoField<TypeA>>(fieldNames_[0]).clone()
); );
} }
else if (foundObject<SurfaceFieldType>(fieldNames_[0]))
{ if
return store
( (
resultName_, i > 0
fo.template calcFieldType<SurfaceFieldType>() && foundObject<GeoField<TypeA>>(resultName_)
); && foundObject<GeoField<TypeB>>(fieldNames_[i])
)
{
tmp<GeoField<TypeA>> a =
lookupObject<GeoField<TypeA>>(resultName_).clone();
const GeoField<TypeB>& b =
lookupObject<GeoField<TypeB>>(fieldNames_[i]);
clearObject(resultName_);
return opAndStore<GeoField, Op>(a(), b);
} }
else
return false;
}
template
<
template<class> class GeoField,
template<class ...> class Op,
class TypeA
>
bool Foam::functionObjects::fieldsExpression::foldA(const label i)
{
bool success = false;
#define processType(Type, none) \
success = success || foldAB<GeoField, Op, TypeA, Type>(i);
FOR_ALL_FIELD_TYPES(processType);
#undef processType
return success;
}
template<template<class> class GeoField, template<class ...> class Op>
bool Foam::functionObjects::fieldsExpression::fold(const label i)
{
bool success = false;
#define processType(Type, none) \
success = success || foldA<GeoField, Op, Type>(i);
FOR_ALL_FIELD_TYPES(processType);
#undef processType
return success;
}
template<template<class> class GeoField, template<class ...> class Op>
bool Foam::functionObjects::fieldsExpression::calcGeoFieldOp()
{
forAll(fieldNames_, i)
{
if (!fold<GeoField, Op>(i))
{ {
return false; return false;
} }
}
return true;
} }
template<class Type, class FOType> template<template<class ...> class Op>
bool Foam::functionObjects::fieldsExpression::calcType(FOType& fo) bool Foam::functionObjects::fieldsExpression::calcOp()
{ {
return calcFieldTypes<Type>(fo); return
} calcGeoFieldOp<VolField, Op>()
|| calcGeoFieldOp<SurfaceField, Op>();
template<class FOType>
bool Foam::functionObjects::fieldsExpression::calcAllTypes(FOType& fo)
{
bool processed = false;
#define processType(fieldType, none) \
processed = processed || fo.template calcType<fieldType>(fo);
FOR_ALL_FIELD_TYPES(processType)
return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,25 +23,65 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // #include "multiply.H"
#include "addToRunTimeSelectionTable.H"
template<class GeoFieldType> // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::tmp<GeoFieldType>
Foam::functionObjects::add::calcFieldType() const namespace Foam
{ {
tmp<GeoFieldType> tresult namespace functionObjects
( {
lookupObject<GeoFieldType>(fieldNames_[0]) defineTypeNameAndDebug(multiply, 0);
+ lookupObject<GeoFieldType>(fieldNames_[1]) addToRunTimeSelectionTable(functionObject, multiply, dictionary);
); }
for (label i=2; i<fieldNames_.size(); i++)
{
tresult.ref() += lookupObject<GeoFieldType>(fieldNames_[i]);
}
return tresult;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
<
class A,
class B,
class R = decltype(std::declval<A>()*std::declval<B>())
>
struct multiplyOpAuto
{
R operator()(const A& a, const B& b)
{
return a*b;
}
};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::multiply::calc()
{
return calcOp<multiplyOpAuto>();
}
// * * * * * * * * * * * * * * * * 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()
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -38,11 +38,28 @@ namespace functionObjects
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
<
class A,
class B,
class R = decltype(std::declval<A>() - std::declval<B>())
>
struct minusOpAuto
{
R operator()(const A& a, const B& b)
{
return a - b;
}
};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::subtract::calc() bool Foam::functionObjects::subtract::calc()
{ {
return calcAllTypes(*this); return calcOp<minusOpAuto>();
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -74,20 +74,12 @@ class subtract
{ {
// Private Member Functions // Private Member Functions
//- Subtract the list of fields of the specified type
// and return the result
template<class GeoFieldType>
tmp<GeoFieldType> calcFieldType() const;
//- Subtract the list of fields and return true if successful //- Subtract the list of fields and return true if successful
virtual bool calc(); virtual bool calc();
public: public:
friend class fieldsExpression;
//- Runtime type information //- Runtime type information
TypeName("subtract"); TypeName("subtract");
@ -115,12 +107,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "subtractTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class GeoFieldType>
Foam::tmp<GeoFieldType>
Foam::functionObjects::subtract::calcFieldType() const
{
tmp<GeoFieldType> tresult
(
lookupObject<GeoFieldType>(fieldNames_[0])
- lookupObject<GeoFieldType>(fieldNames_[1])
);
for (label i=2; i<fieldNames_.size(); i++)
{
tresult.ref() -= lookupObject<GeoFieldType>(fieldNames_[i]);
}
return tresult;
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<word>("fieldType");
name_ = dict.lookup<word>("name");
dimensions_.reset(dict.lookup<dimensionSet>("dimensions"));
bool ok = false;
#define readValueType(Type, GeoField) \
if (GeoField<Type>::typeName == fieldType_) \
{ \
ok = true; \
Type##Value_ = dict.lookup<Type>("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<word> fieldTypes;
#define getFieldType(Type, GeoField) \
fieldTypes.append(GeoField<Type>::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<Type>::typeName == fieldType_) \
{ \
store \
( \
name_, \
GeoField<Type>::New \
( \
name_, \
mesh_, \
dimensioned<Type>(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_);
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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
// ************************************************************************* //