functionObjects::subtract: From the first field subtract the remaining fields in the list
The operation can be applied to any volume or surface fields generating a
volume or surface scalar field.
Example of function object specification:
\verbatim
Tdiff
{
type subtract;
libs ("libfieldFunctionObjects.so");
fields (T Tmean);
result Tdiff;
executeControl writeTime;
writeControl writeTime;
}
\endverbatim
This commit is contained in:
9
src/functionObjects/field/subtract/*grep*
Normal file
9
src/functionObjects/field/subtract/*grep*
Normal file
@ -0,0 +1,9 @@
|
||||
-*- mode: grep; default-directory: "~/OpenFOAM/OpenFOAM-dev/src/functionObjects/field/subtract/" -*-
|
||||
Grep started at Fri Nov 18 21:41:56
|
||||
|
||||
grep --color -nH -e nitude *
|
||||
subtract.H:31: Calculates the subtract of a field.
|
||||
subtract.H:66: //- Calculate the subtract of the field and register the result
|
||||
subtract.H:70: //- Calculate the subtract of the field and return true if successful
|
||||
|
||||
Grep finished (matches found) at Fri Nov 18 21:41:56
|
||||
86
src/functionObjects/field/subtract/subtract.C
Normal file
86
src/functionObjects/field/subtract/subtract.C
Normal file
@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 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 "subtract.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(subtract, 0);
|
||||
addToRunTimeSelectionTable(functionObject, subtract, dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::subtract::calc()
|
||||
{
|
||||
bool processed = false;
|
||||
|
||||
processed = processed || calcSubtract<scalar>();
|
||||
processed = processed || calcSubtract<vector>();
|
||||
processed = processed || calcSubtract<sphericalTensor>();
|
||||
processed = processed || calcSubtract<symmTensor>();
|
||||
processed = processed || calcSubtract<tensor>();
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::subtract::subtract
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fieldsExpression(name, runTime, dict)
|
||||
{
|
||||
read(dict);
|
||||
|
||||
if (fieldNames_.size() < 2)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< type() << " requires at least 2 fields only "
|
||||
<< fieldNames_.size() << " provided: " << fieldNames_
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::subtract::~subtract()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
130
src/functionObjects/field/subtract/subtract.H
Normal file
130
src/functionObjects/field/subtract/subtract.H
Normal file
@ -0,0 +1,130 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 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::subtract
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
From the first field subtract the remaining fields in the list.
|
||||
|
||||
The operation can be applied to any volume or surface fields generating a
|
||||
volume or surface scalar field.
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
Tdiff
|
||||
{
|
||||
type subtract;
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
fields (T Tmean);
|
||||
result Tdiff;
|
||||
executeControl writeTime;
|
||||
writeControl writeTime;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
See also
|
||||
Foam::functionObjects::fieldsExpression
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
|
||||
SourceFiles
|
||||
subtract.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_subtract_H
|
||||
#define functionObjects_subtract_H
|
||||
|
||||
#include "fieldsExpression.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class subtract Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class subtract
|
||||
:
|
||||
public fieldsExpression
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Subtract the list of fields of the specified type
|
||||
// and return the result
|
||||
template<class GeoFieldType>
|
||||
tmp<GeoFieldType> subtractFields() const;
|
||||
|
||||
//- Subtract the list of fields and register the result
|
||||
template<class Type>
|
||||
bool calcSubtract();
|
||||
|
||||
//- Subtract the list of fields and return true if successful
|
||||
virtual bool calc();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("subtract");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
subtract
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~subtract();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "subtractTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
79
src/functionObjects/field/subtract/subtractTemplates.C
Normal file
79
src/functionObjects/field/subtract/subtractTemplates.C
Normal file
@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 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 "volFields.H"
|
||||
#include "surfaceFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class GeoFieldType>
|
||||
Foam::tmp<GeoFieldType>
|
||||
Foam::functionObjects::subtract::subtractFields() const
|
||||
{
|
||||
tmp<GeoFieldType> tresult
|
||||
(
|
||||
lookupObject<GeoFieldType>(fieldNames_[0])
|
||||
- lookupObject<GeoFieldType>(fieldNames_[1])
|
||||
);
|
||||
|
||||
for (label i=2; i<fieldNames_.size(); i++)
|
||||
{
|
||||
tresult = tresult - lookupObject<GeoFieldType>(fieldNames_[i]);
|
||||
}
|
||||
|
||||
return tresult;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::subtract::calcSubtract()
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
||||
|
||||
if (foundObject<VolFieldType>(fieldNames_[0]))
|
||||
{
|
||||
return store
|
||||
(
|
||||
resultName_,
|
||||
subtractFields<VolFieldType>()
|
||||
);
|
||||
}
|
||||
else if (foundObject<SurfaceFieldType>(fieldNames_[0]))
|
||||
{
|
||||
return store
|
||||
(
|
||||
resultName_,
|
||||
subtractFields<SurfaceFieldType>()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user