diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index ebda106c1a..284ebd4e34 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -61,4 +61,7 @@ writeCellVolumes/writeCellVolumes.C XiReactionRate/XiReactionRate.C streamFunction/streamFunction.C +fieldsExpression/fieldsExpression.C +subtract/subtract.C + LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects diff --git a/src/functionObjects/field/fieldExpression/fieldExpression.C b/src/functionObjects/field/fieldExpression/fieldExpression.C index d56bff0bde..42f308cd20 100644 --- a/src/functionObjects/field/fieldExpression/fieldExpression.C +++ b/src/functionObjects/field/fieldExpression/fieldExpression.C @@ -39,13 +39,6 @@ namespace functionObjects // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // -bool Foam::functionObjects::fieldExpression::calc() -{ - NotImplemented; - return false; -} - - void Foam::functionObjects::fieldExpression::setResultName ( const word& typeName, diff --git a/src/functionObjects/field/fieldExpression/fieldExpression.H b/src/functionObjects/field/fieldExpression/fieldExpression.H index 3c8647c033..fa84ade8bf 100644 --- a/src/functionObjects/field/fieldExpression/fieldExpression.H +++ b/src/functionObjects/field/fieldExpression/fieldExpression.H @@ -71,7 +71,7 @@ protected: // Protected member functions - virtual bool calc(); + virtual bool calc() = 0; void setResultName(const word& typeName, const word& defaultArg); diff --git a/src/functionObjects/field/fieldsExpression/fieldsExpression.C b/src/functionObjects/field/fieldsExpression/fieldsExpression.C new file mode 100644 index 0000000000..bf61140b14 --- /dev/null +++ b/src/functionObjects/field/fieldsExpression/fieldsExpression.C @@ -0,0 +1,149 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +\*---------------------------------------------------------------------------*/ + +#include "fieldsExpression.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(fieldsExpression, 0); +} +} + + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +void Foam::functionObjects::fieldsExpression::setResultName +( + const word& typeName, + const wordList& defaultArgs +) +{ + if (fieldNames_.empty()) + { + fieldNames_ = defaultArgs; + } + + if (resultName_.empty()) + { + if (fieldNames_ != defaultArgs) + { + resultName_ = typeName + '('; + forAll(fieldNames_, i) + { + resultName_ += fieldNames_[i]; + } + resultName_ += ')'; + } + else + { + resultName_ = typeName; + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::fieldsExpression::fieldsExpression +( + const word& name, + const Time& runTime, + const dictionary& dict, + const wordList& fieldNames, + const word& resultName +) +: + fvMeshFunctionObject(name, runTime, dict), + fieldNames_(fieldNames), + resultName_(resultName) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::fieldsExpression::~fieldsExpression() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::fieldsExpression::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + + if (fieldNames_.empty() || dict.found("fields")) + { + dict.lookup("fields") >> fieldNames_; + } + + if (dict.found("result")) + { + dict.lookup("result") >> resultName_; + } + + return true; +} + + +bool Foam::functionObjects::fieldsExpression::execute() +{ + if (!calc()) + { + Warning + << " functionObjects::" << type() << " " << name() + << " cannot find required fields " << fieldNames_ << endl; + + // Clear the result fields from the objectRegistry if present + clear(); + + return false; + } + else + { + return true; + } +} + + +bool Foam::functionObjects::fieldsExpression::write() +{ + return writeObject(resultName_); +} + + +bool Foam::functionObjects::fieldsExpression::clear() +{ + return clearObject(resultName_); +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/fieldsExpression/fieldsExpression.H b/src/functionObjects/field/fieldsExpression/fieldsExpression.H new file mode 100644 index 0000000000..175f527e94 --- /dev/null +++ b/src/functionObjects/field/fieldsExpression/fieldsExpression.H @@ -0,0 +1,138 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012-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 . + +Class + Foam::functionObjects::fieldsExpression + +Group + grpFieldFunctionObjects + +Description + +See also + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + fieldsExpression.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_fieldsExpression_H +#define functionObjects_fieldsExpression_H + +#include "fvMeshFunctionObject.H" +#include "volFieldsFwd.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class fieldsExpression Declaration +\*---------------------------------------------------------------------------*/ + +class fieldsExpression +: + public fvMeshFunctionObject +{ +protected: + + // Protected member data + + //- Names of fields to process + wordList fieldNames_; + + //- Name of result fields + word resultName_; + + + // Protected member functions + + virtual bool calc() = 0; + + void setResultName(const word& typeName, const wordList& defaultArg); + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + fieldsExpression(const fieldsExpression&); + + //- Disallow default bitwise assignment + void operator=(const fieldsExpression&); + + +public: + + //- Runtime type information + TypeName("fieldsExpression"); + + + // Constructors + + //- Construct from Time and dictionary + fieldsExpression + ( + const word& name, + const Time& runTime, + const dictionary& dict, + const wordList& fieldNames = wordList::null(), + const word& resultName = word::null + ); + + + //- Destructor + virtual ~fieldsExpression(); + + + // Member Functions + + //- Read the fieldsExpression data + virtual bool read(const dictionary&); + + //- Calculate the result fields + virtual bool execute(); + + //- Write the result fields + virtual bool write(); + + //- Clear the result fields from the objectRegistry + virtual bool clear(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/subtract/*grep* b/src/functionObjects/field/subtract/*grep* new file mode 100644 index 0000000000..8dbdf91b64 --- /dev/null +++ b/src/functionObjects/field/subtract/*grep* @@ -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 diff --git a/src/functionObjects/field/subtract/subtract.C b/src/functionObjects/field/subtract/subtract.C new file mode 100644 index 0000000000..592ba5941d --- /dev/null +++ b/src/functionObjects/field/subtract/subtract.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#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(); + processed = processed || calcSubtract(); + processed = processed || calcSubtract(); + processed = processed || calcSubtract(); + processed = processed || calcSubtract(); + + 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() +{} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/subtract/subtract.H b/src/functionObjects/field/subtract/subtract.H new file mode 100644 index 0000000000..31fae7285a --- /dev/null +++ b/src/functionObjects/field/subtract/subtract.H @@ -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 . + +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 + tmp subtractFields() const; + + //- Subtract the list of fields and register the result + template + 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 + +// ************************************************************************* // diff --git a/src/functionObjects/field/subtract/subtractTemplates.C b/src/functionObjects/field/subtract/subtractTemplates.C new file mode 100644 index 0000000000..6368f29e4d --- /dev/null +++ b/src/functionObjects/field/subtract/subtractTemplates.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::tmp +Foam::functionObjects::subtract::subtractFields() const +{ + tmp tresult + ( + lookupObject(fieldNames_[0]) + - lookupObject(fieldNames_[1]) + ); + + for (label i=2; i(fieldNames_[i]); + } + + return tresult; +} + + +template +bool Foam::functionObjects::subtract::calcSubtract() +{ + typedef GeometricField VolFieldType; + typedef GeometricField SurfaceFieldType; + + if (foundObject(fieldNames_[0])) + { + return store + ( + resultName_, + subtractFields() + ); + } + else if (foundObject(fieldNames_[0])) + { + return store + ( + resultName_, + subtractFields() + ); + } + else + { + return false; + } +} + + +// ************************************************************************* //