turbulenceFields.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) 2013-2026 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 "turbulenceFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
38 
40  (
44  );
45 }
46 }
47 
48 const Foam::NamedEnum
49 <
51  7
53 {
54  "k",
55  "epsilon",
56  "omega",
57  "nut",
58  "nuEff",
59  "kappaEff",
60  "R"
61 };
62 
63 const Foam::NamedEnum
64 <
66  6
68 {
69  "k",
70  "epsilon",
71  "omega",
72  "nut",
73  "nuEff",
74  "R"
75 };
76 
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
81 (
82  const word& name,
83  const Time& runTime,
84  const dictionary& dict
85 )
86 :
87  fvMeshFunctionObject(name, runTime, dict),
88  fieldSet_(),
89  phaseName_(dict.lookupOrDefault<word>("phase", word::null))
90 {
91  read(dict);
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
96 
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
104 {
105  if (dict.found("field"))
106  {
107  fieldSet_.insert(word(dict.lookup("field")));
108  }
109  else
110  {
111  fieldSet_.insert(wordList(dict.lookup("fields")));
112  }
113 
114  if (dict.lookupOrDefault<Switch>("prefix", false))
115  {
116  prefix_ = momentumTransportModel::typeName + ':';
117  }
118  else
119  {
120  prefix_ = word::null;
121  }
122 
123  if (fieldSet_.size())
124  {
125  Info<< indent << "storing fields:" << nl;
126  Info<< incrIndent;
127  forAllConstIter(wordHashSet, fieldSet_, iter)
128  {
129  Info<< indent
130  << IOobject::groupName(prefix_ + iter.key(), phaseName_)
131  << endl;
132  }
133  Info<< decrIndent;
134  }
135  else
136  {
137  Info<< indent << "no fields requested to be stored" << endl;
138  }
139 
140  return true;
141 }
142 
143 
145 {
146  if (obr_.foundType<fluidThermophysicalTransportModel>(phaseName_))
147  {
149  obr_.lookupType<fluidThermophysicalTransportModel>(phaseName_);
150 
152  ttm.momentumTransport();
153 
154  forAllConstIter(wordHashSet, fieldSet_, iter)
155  {
156  const word& f = iter.key();
157  switch (compressibleFieldNames_[f])
158  {
160  {
161  processField<scalar>(f, model.k());
162  break;
163  }
165  {
166  processField<scalar>(f, model.epsilon());
167  break;
168  }
170  {
171  processField<scalar>(f, model.omega());
172  break;
173  }
175  {
176  processField<scalar>(f, model.nut());
177  break;
178  }
180  {
181  processField<scalar>(f, model.nuEff());
182  break;
183  }
184  case compressibleField::kappaEff:
185  {
186  processField<scalar>(f, ttm.kappaEff());
187  break;
188  }
190  {
191  processField<symmTensor>(f, model.R());
192  break;
193  }
194  default:
195  {
197  << "Invalid field selection" << exit(FatalError);
198  }
199  }
200  }
201  }
202  else if (obr_.foundType<compressibleMomentumTransportModel>(phaseName_))
203  {
205  obr_.lookupType<compressibleMomentumTransportModel>(phaseName_);
206 
207  forAllConstIter(wordHashSet, fieldSet_, iter)
208  {
209  const word& f = iter.key();
210  switch (compressibleFieldNames_[f])
211  {
213  {
214  processField<scalar>(f, model.k());
215  break;
216  }
218  {
219  processField<scalar>(f, model.epsilon());
220  break;
221  }
223  {
224  processField<scalar>(f, model.omega());
225  break;
226  }
228  {
229  processField<scalar>(f, model.nut());
230  break;
231  }
233  {
234  processField<scalar>(f, model.nuEff());
235  break;
236  }
238  {
239  processField<symmTensor>(f, model.R());
240  break;
241  }
242  default:
243  {
245  << "Invalid field selection" << exit(FatalError);
246  }
247  }
248  }
249  }
250  else if
251  (
252  obr_.foundType<incompressible::momentumTransportModel>(phaseName_)
253  )
254  {
256  obr_.lookupType<incompressible::momentumTransportModel>(phaseName_);
257 
258  forAllConstIter(wordHashSet, fieldSet_, iter)
259  {
260  const word& f = iter.key();
261  switch (incompressibleFieldNames_[f])
262  {
264  {
265  processField<scalar>(f, model.k());
266  break;
267  }
269  {
270  processField<scalar>(f, model.epsilon());
271  break;
272  }
274  {
275  processField<scalar>(f, model.omega());
276  break;
277  }
279  {
280  processField<scalar>(f, model.nut());
281  break;
282  }
284  {
285  processField<scalar>(f, model.nuEff());
286  break;
287  }
289  {
290  processField<symmTensor>(f, model.R());
291  break;
292  }
293  default:
294  {
296  << "Invalid field selection" << exit(FatalError);
297  }
298  }
299  }
300  }
301  else
302  {
304  << "Turbulence model not found in database, deactivating"
305  << exit(FatalError);
306  }
307 
308  return true;
309 }
310 
311 
313 {
314  forAllConstIter(wordHashSet, fieldSet_, iter)
315  {
316  const word fieldName
317  (
318  IOobject::groupName(prefix_ + iter.key(), phaseName_)
319  );
320  writeObject(fieldName);
321  }
322 
323  return true;
324 }
325 
326 
327 // ************************************************************************* //
label k
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
A HashTable with keys but without contents.
Definition: HashSet.H:62
static word groupName(Name name, const word &group)
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
Base class for single-phase compressible momentum transport models.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for fluid thermophysical transport models RAS, LES and laminar.
const compressibleMomentumTransportModel & momentumTransport() const
Access function to momentum transport model.
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Stores derived turbulence fields on the mesh database for further manipulation.
turbulenceFields(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
static const NamedEnum< incompressibleField, 6 > incompressibleFieldNames_
static const NamedEnum< compressibleField, 7 > compressibleFieldNames_
virtual bool execute()
Calculate turbulence fields.
virtual bool write()
Write the turbulence fields.
virtual bool read(const dictionary &)
Read the controls.
Base class for single-phase incompressible momentum transport models.
virtual tmp< volScalarField > nut() const =0
Return the turbulence viscosity.
virtual tmp< volScalarField > k() const =0
Return the turbulence kinetic energy.
virtual tmp< volSymmTensorField > R() const =0
Return the Reynolds stress tensor [m^2/s^2].
virtual tmp< volScalarField > omega() const =0
Return the turbulence specific dissipation rate.
virtual tmp< volScalarField > epsilon() const =0
Return the turbulence kinetic energy dissipation rate.
virtual tmp< volScalarField > nuEff() const =0
Return the effective viscosity.
virtual tmp< volScalarField > kappaEff() const =0
Effective thermal turbulent conductivity.
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const scalar omega
const scalar nut
const scalar nuEff
const scalar epsilon
const volSymmTensorField R(IOobject("R", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), turbulence->R())
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:272
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:265
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
static const char nl
Definition: Ostream.H:297
labelList f(nPoints)
dictionary dict