diff --git a/etc/caseDicts/postProcessing/fields/turbulenceIntensity b/etc/caseDicts/postProcessing/fields/turbulenceIntensity new file mode 100644 index 0000000000..9cd4300f9e --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/turbulenceIntensity @@ -0,0 +1,19 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Web: www.OpenFOAM.org + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculates and writes the turbulence intensity field I. + +\*---------------------------------------------------------------------------*/ + +type turbulenceIntensity; +libs ("libfieldFunctionObjects.so"); + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index d40d9aa8bd..d6c6716661 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -48,6 +48,7 @@ MachNo/MachNo.C turbulenceFields/turbulenceFields.C yPlus/yPlus.C +turbulenceIntensity/turbulenceIntensity.C wallShearStress/wallShearStress.C wallHeatFlux/wallHeatFlux.C wallHeatTransferCoeff/wallHeatTransferCoeff.C diff --git a/src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.C b/src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.C new file mode 100644 index 0000000000..f764db6462 --- /dev/null +++ b/src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.C @@ -0,0 +1,183 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 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 . + +\*---------------------------------------------------------------------------*/ + +#include "turbulenceIntensity.H" +#include "turbulenceModel.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(turbulenceIntensity, 0); + + addToRunTimeSelectionTable + ( + functionObject, + turbulenceIntensity, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::turbulenceIntensity::writeFileHeader(const label i) +{ + writeHeader(file(), "I ()"); + writeCommented(file(), "Time"); + writeTabbed(file(), "min"); + writeTabbed(file(), "max"); + writeTabbed(file(), "average"); + file() << endl; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::turbulenceIntensity::turbulenceIntensity +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + logFiles(obr_, name), + writeLocalObjects(obr_, log) +{ + volScalarField* turbulenceIntensityPtr + ( + new volScalarField + ( + IOobject + ( + "I", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("0", dimless, 0.0) + ) + ); + + mesh_.objectRegistry::store(turbulenceIntensityPtr); + + read(dict); + resetName(typeName); + resetLocalObjectName("I"); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::turbulenceIntensity::~turbulenceIntensity() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::turbulenceIntensity::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + writeLocalObjects::read(dict); + + return true; +} + + +bool Foam::functionObjects::turbulenceIntensity::execute() +{ + volScalarField& turbulenceIntensity = + mesh_.lookupObjectRef("I"); + + if (mesh_.foundObject(turbulenceModel::propertiesName)) + { + const turbulenceModel& turbModel = mesh_.lookupObject + ( + turbulenceModel::propertiesName + ); + + volScalarField uPrime(sqrt((2.0/3.0)*turbModel.k())); + turbulenceIntensity = + uPrime + /max + ( + max(uPrime, mag(turbModel.U())), + dimensionedScalar("small", dimVelocity, small) + ); + } + else + { + FatalErrorInFunction + << "Unable to find turbulence model in the " + << "database" << exit(FatalError); + } + + return true; +} + + +bool Foam::functionObjects::turbulenceIntensity::write() +{ + Log << type() << " " << name() << " write:" << nl; + + writeLocalObjects::write(); + + logFiles::write(); + + const volScalarField& turbulenceIntensity = + mesh_.lookupObject("I"); + + const scalar minTurbulenceIntensity = min(turbulenceIntensity).value(); + const scalar maxTurbulenceIntensity = max(turbulenceIntensity).value(); + const scalar avgTurbulenceIntensity = turbulenceIntensity.average().value(); + + if (Pstream::master()) + { + Log << " I : min = " << minTurbulenceIntensity + << ", max = " << maxTurbulenceIntensity + << ", average = " << avgTurbulenceIntensity << nl; + + writeTime(file()); + file() + << tab << minTurbulenceIntensity + << tab << maxTurbulenceIntensity + << tab << avgTurbulenceIntensity + << endl; + } + + Log << endl; + + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.H b/src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.H new file mode 100644 index 0000000000..5681278363 --- /dev/null +++ b/src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.H @@ -0,0 +1,164 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 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 . + +Class + Foam::functionObjects::turbulenceIntensity + +Group + grpFieldFunctionObjects + +Description + Evaluates and writes the turbulence intensity field 'I'. + + The turbulence intensity field 'I' is the root-mean-square of the turbulent + velocity fluctuations normalised by the local velocity magnitude: + \f[ + I \equiv \frac{\sqrt{\frac{2}{3}\, k}}{U} + \f] + To avoid spurious extrema and division by 0 I is limited to 1 where the + velocity magnitude is less than the turbulent velocity fluctuations. + + Example of function object specification: + \verbatim + functions + { + . + . + . + turbulenceIntensity + { + type turbulenceIntensity; + libs ("libfieldFunctionObjects.so"); + } + . + . + . + } + \endverbatim + + or using the standard configuration file: + \verbatim + functions + { + . + . + . + #includeFunc turbulenceIntensity + . + . + . + } + \endverbatim + +See also + Foam::functionObject + Foam::functionObjects::fvMeshFunctionObject + Foam::functionObjects::logFiles + Foam::functionObjects::writeLocalObjects + Foam::functionObjects::timeControl + +SourceFiles + turbulenceIntensity.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_turbulenceIntensity_H +#define functionObjects_turbulenceIntensity_H + +#include "fvMeshFunctionObject.H" +#include "logFiles.H" +#include "writeLocalObjects.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class turbulenceIntensity Declaration +\*---------------------------------------------------------------------------*/ + +class turbulenceIntensity +: + public fvMeshFunctionObject, + public logFiles, + public writeLocalObjects +{ + // Private Member Functions + + //- File header information + virtual void writeFileHeader(const label i); + + //- Disallow default bitwise copy construct + turbulenceIntensity(const turbulenceIntensity&); + + //- Disallow default bitwise assignment + void operator=(const turbulenceIntensity&); + + +public: + + //- Runtime type information + TypeName("turbulenceIntensity"); + + + // Constructors + + //- Construct from Time and dictionary + turbulenceIntensity + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + + //- Destructor + virtual ~turbulenceIntensity(); + + + // Member Functions + + //- Read the turbulenceIntensity data + virtual bool read(const dictionary&); + + //- Calculate the turbulenceIntensity field + virtual bool execute(); + + //- Write the turbulenceIntensity field + virtual bool write(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //