From c2835a450b2990a8d2d496ad3507f81ba743ea08 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 5 Nov 2017 10:58:07 +0000 Subject: [PATCH] functionObjects::ddt: New functionObject which calculates and writes the Eulerian time derivative of a field Based on patch contributed by Tobias Holzmann Resolves feature-request https://bugs.openfoam.org/view.php?id=2525 --- etc/caseDicts/postProcessing/fields/ddt | 21 ++++ src/functionObjects/field/Make/files | 1 + src/functionObjects/field/ddt/ddt.C | 87 ++++++++++++++ src/functionObjects/field/ddt/ddt.H | 112 +++++++++++++++++++ src/functionObjects/field/ddt/ddtTemplates.C | 50 +++++++++ 5 files changed, 271 insertions(+) create mode 100644 etc/caseDicts/postProcessing/fields/ddt create mode 100644 src/functionObjects/field/ddt/ddt.C create mode 100644 src/functionObjects/field/ddt/ddt.H create mode 100644 src/functionObjects/field/ddt/ddtTemplates.C diff --git a/etc/caseDicts/postProcessing/fields/ddt b/etc/caseDicts/postProcessing/fields/ddt new file mode 100644 index 000000000..ba585fad7 --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/ddt @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Web: www.OpenFOAM.org + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculates the Eulerian time derivative of a field. + +\*---------------------------------------------------------------------------*/ + +type ddt; +libs ("libfieldFunctionObjects.so"); + +field ; + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 4b9864d6d..52687a2bf 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -32,6 +32,7 @@ components/components.C randomise/randomise.C div/div.C grad/grad.C +ddt/ddt.C mag/mag.C magSqr/magSqr.C vorticity/vorticity.C diff --git a/src/functionObjects/field/ddt/ddt.C b/src/functionObjects/field/ddt/ddt.C new file mode 100644 index 000000000..aa4e40564 --- /dev/null +++ b/src/functionObjects/field/ddt/ddt.C @@ -0,0 +1,87 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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 "ddt.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(ddt, 0); + addToRunTimeSelectionTable(functionObject, ddt, dictionary); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::ddt::calc() +{ + if (functionObject::postProcess) + { + WarningInFunction + << "ddt is not supported with the postProcess utility" + << endl; + + return false; + } + + bool processed = false; + + processed = processed || calcDdt(); + processed = processed || calcDdt(); + processed = processed || calcDdt(); + processed = processed || calcDdt(); + processed = processed || calcDdt(); + + return processed; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::ddt::ddt +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fieldExpression(name, runTime, dict) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::ddt::~ddt() +{} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/ddt/ddt.H b/src/functionObjects/field/ddt/ddt.H new file mode 100644 index 000000000..bb7c0c34b --- /dev/null +++ b/src/functionObjects/field/ddt/ddt.H @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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::ddt + +Group + grpFieldFunctionObjects + +Description + Calculates the Eulerian time derivative of a field. + + The operation can be applied to any volume field generating a field of the + same type. + +See also + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + ddt.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_ddt_H +#define functionObjects_ddt_H + +#include "fieldExpression.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class ddt Declaration +\*---------------------------------------------------------------------------*/ + +class ddt +: + public fieldExpression +{ + // Private Member Functions + + //- Calculate the magnitude of the field and register the result + template + bool calcDdt(); + + //- Calculate the time derivative of the field and return + // true if successful + virtual bool calc(); + + +public: + + //- Runtime type information + TypeName("ddt"); + + + // Constructors + + //- Construct from Time and dictionary + ddt + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + + //- Destructor + virtual ~ddt(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "ddtTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/ddt/ddtTemplates.C b/src/functionObjects/field/ddt/ddtTemplates.C new file mode 100644 index 000000000..4f7c3d6f1 --- /dev/null +++ b/src/functionObjects/field/ddt/ddtTemplates.C @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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 "fvcDdt.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +bool Foam::functionObjects::ddt::calcDdt() +{ + typedef GeometricField VolFieldType; + + if (foundObject(fieldName_)) + { + return store + ( + resultName_, + fvc::ddt(lookupObject(fieldName_)) + ); + } + else + { + return false; + } +} + + +// ************************************************************************* //