turbulenceIntensity.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "turbulenceIntensity.H"
27 #include "turbulenceModel.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(turbulenceIntensity, 0);
37 
39  (
40  functionObject,
41  turbulenceIntensity,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::functionObjects::turbulenceIntensity::writeFileHeader(const label i)
51 {
52  writeHeader(file(), "I ()");
53  writeCommented(file(), "Time");
54  writeTabbed(file(), "min");
55  writeTabbed(file(), "max");
56  writeTabbed(file(), "average");
57  file() << endl;
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
63 Foam::functionObjects::turbulenceIntensity::turbulenceIntensity
64 (
65  const word& name,
66  const Time& runTime,
67  const dictionary& dict
68 )
69 :
70  fvMeshFunctionObject(name, runTime, dict),
71  logFiles(obr_, name),
72  writeLocalObjects(obr_, log)
73 {
74  read(dict);
75  resetName(typeName);
76  resetLocalObjectName("I");
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 
83 {}
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
89 {
92 
93  return true;
94 }
95 
96 
98 {
99  if (mesh_.foundObject<turbulenceModel>(turbulenceModel::propertiesName))
100  {
101  const turbulenceModel& turbModel = mesh_.lookupObject<turbulenceModel>
102  (
104  );
105 
106  volScalarField uPrime(sqrt((2.0/3.0)*turbModel.k()));
107 
108  word name("I");
109 
110  return
111  store
112  (
113  name,
114  uPrime
115  /max
116  (
117  max(uPrime, mag(turbModel.U())),
118  dimensionedScalar("small", dimVelocity, small)
119  )
120  );
121  }
122  else
123  {
125  << "Unable to find turbulence model in the "
126  << "database" << exit(FatalError);
127 
128  return false;
129  }
130 }
131 
132 
134 {
135  Log << type() << " " << name() << " write:" << nl;
136 
138 
139  logFiles::write();
140 
142  mesh_.lookupObject<volScalarField>("I");
143 
144  const scalar minTurbulenceIntensity = min(turbulenceIntensity).value();
145  const scalar maxTurbulenceIntensity = max(turbulenceIntensity).value();
146  const scalar avgTurbulenceIntensity = turbulenceIntensity.average().value();
147 
148  if (Pstream::master())
149  {
150  Log << " I : min = " << minTurbulenceIntensity
151  << ", max = " << maxTurbulenceIntensity
152  << ", average = " << avgTurbulenceIntensity << nl;
153 
154  writeTime(file());
155  file()
156  << tab << minTurbulenceIntensity
157  << tab << maxTurbulenceIntensity
158  << tab << avgTurbulenceIntensity
159  << endl;
160  }
161 
162  Log << endl;
163 
164  return true;
165 }
166 
167 
168 // ************************************************************************* //
virtual bool write()
Write function.
virtual bool write()
Write function.
Definition: logFiles.C:180
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool write()
Write the turbulenceIntensity field.
const volVectorField & U() const
Access function to velocity field.
static const char tab
Definition: Ostream.H:264
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:421
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
Abstract base class for turbulence models (RAS, LES and laminar).
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
virtual tmp< volScalarField > k() const =0
Return the turbulence kinetic energy.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
static const word propertiesName
Default name of the turbulence properties dictionary.
virtual bool execute()
Calculate the turbulenceIntensity field.
A class for handling words, derived from string.
Definition: word.H:59
Evaluates and writes the turbulence intensity field &#39;I&#39;.
static const char nl
Definition: Ostream.H:265
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dimensioned< Type > average() const
Calculate and return arithmetic average.
virtual bool read(const dictionary &)
Read the turbulenceIntensity data.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
FunctionObject base class for managing a list of objects on behalf of the inheriting function object...
virtual bool read(const dictionary &)
Read the list of objects to be written.
#define Log
Report write to Foam::Info if the local log switch is true.
dimensioned< scalar > mag(const dimensioned< Type > &)
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, add, dictionary)
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57
const dimensionSet dimVelocity