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-2023 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 template<>
49 const char* Foam::NamedEnum
50 <
52  8
53 >::names[] =
54 {
55  "k",
56  "epsilon",
57  "omega",
58  "nut",
59  "nuEff",
60  "kappaEff",
61  "R",
62  "devTau"
63 };
64 
65 const Foam::NamedEnum
66 <
68  8
70 
71 template<>
72 const char* Foam::NamedEnum
73 <
75  7
76 >::names[] =
77 {
78  "k",
79  "epsilon",
80  "omega",
81  "nut",
82  "nuEff",
83  "R",
84  "devSigma"
85 };
86 
87 const Foam::NamedEnum
88 <
90  7
92 
93 
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 
97 (
98  const word& name,
99  const Time& runTime,
100  const dictionary& dict
101 )
102 :
103  fvMeshFunctionObject(name, runTime, dict),
104  fieldSet_(),
105  phaseName_(dict.lookupOrDefault<word>("phase", word::null))
106 {
107  read(dict);
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
112 
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 {
121  if (dict.found("field"))
122  {
123  fieldSet_.insert(word(dict.lookup("field")));
124  }
125  else
126  {
127  fieldSet_.insert(wordList(dict.lookup("fields")));
128  }
129 
130  if (dict.lookupOrDefault<Switch>("prefix", false))
131  {
132  prefix_ = momentumTransportModel::typeName + ':';
133  }
134  else
135  {
136  prefix_ = word::null;
137  }
138 
139  Info<< type() << " " << name() << ": ";
140  if (fieldSet_.size())
141  {
142  Info<< "storing fields:" << nl;
143  forAllConstIter(wordHashSet, fieldSet_, iter)
144  {
145  Info<< " "
146  << IOobject::groupName(prefix_ + iter.key(), phaseName_) << nl;
147  }
148  Info<< endl;
149  }
150  else
151  {
152  Info<< "no fields requested to be stored" << nl << endl;
153  }
154 
155  return true;
156 }
157 
158 
160 {
161  if (obr_.foundType<fluidThermophysicalTransportModel>(phaseName_))
162  {
164  obr_.lookupType<fluidThermophysicalTransportModel>(phaseName_);
165 
167  ttm.momentumTransport();
168 
169  forAllConstIter(wordHashSet, fieldSet_, iter)
170  {
171  const word& f = iter.key();
172  switch (compressibleFieldNames_[f])
173  {
175  {
176  processField<scalar>(f, model.k());
177  break;
178  }
180  {
181  processField<scalar>(f, model.epsilon());
182  break;
183  }
185  {
186  processField<scalar>(f, model.omega());
187  break;
188  }
190  {
191  processField<scalar>(f, model.nut());
192  break;
193  }
195  {
196  processField<scalar>(f, model.nuEff());
197  break;
198  }
199  case compressibleField::kappaEff:
200  {
201  processField<scalar>(f, ttm.kappaEff());
202  break;
203  }
205  {
206  processField<symmTensor>(f, model.sigma());
207  break;
208  }
209  case compressibleField::devTau:
210  {
211  processField<symmTensor>(f, model.devTau());
212  break;
213  }
214  default:
215  {
217  << "Invalid field selection" << exit(FatalError);
218  }
219  }
220  }
221  }
222  else if (obr_.foundType<compressibleMomentumTransportModel>(phaseName_))
223  {
225  obr_.lookupType<compressibleMomentumTransportModel>(phaseName_);
226 
227  forAllConstIter(wordHashSet, fieldSet_, iter)
228  {
229  const word& f = iter.key();
230  switch (compressibleFieldNames_[f])
231  {
233  {
234  processField<scalar>(f, model.k());
235  break;
236  }
238  {
239  processField<scalar>(f, model.epsilon());
240  break;
241  }
243  {
244  processField<scalar>(f, model.omega());
245  break;
246  }
248  {
249  processField<scalar>(f, model.nut());
250  break;
251  }
253  {
254  processField<scalar>(f, model.nuEff());
255  break;
256  }
258  {
259  processField<symmTensor>(f, model.sigma());
260  break;
261  }
262  case compressibleField::devTau:
263  {
264  processField<symmTensor>(f, model.devTau());
265  break;
266  }
267  default:
268  {
270  << "Invalid field selection" << exit(FatalError);
271  }
272  }
273  }
274  }
275  else if
276  (
277  obr_.foundType<incompressible::momentumTransportModel>(phaseName_)
278  )
279  {
281  obr_.lookupType<incompressible::momentumTransportModel>(phaseName_);
282 
283  forAllConstIter(wordHashSet, fieldSet_, iter)
284  {
285  const word& f = iter.key();
286  switch (incompressibleFieldNames_[f])
287  {
289  {
290  processField<scalar>(f, model.k());
291  break;
292  }
294  {
295  processField<scalar>(f, model.epsilon());
296  break;
297  }
299  {
300  processField<scalar>(f, model.omega());
301  break;
302  }
304  {
305  processField<scalar>(f, model.nut());
306  break;
307  }
309  {
310  processField<scalar>(f, model.nuEff());
311  break;
312  }
314  {
315  processField<symmTensor>(f, model.sigma());
316  break;
317  }
318  case incompressibleField::devSigma:
319  {
320  processField<symmTensor>(f, model.devSigma());
321  break;
322  }
323  default:
324  {
326  << "Invalid field selection" << exit(FatalError);
327  }
328  }
329  }
330  }
331  else
332  {
334  << "Turbulence model not found in database, deactivating"
335  << exit(FatalError);
336  }
337 
338  return true;
339 }
340 
341 
343 {
344  forAllConstIter(wordHashSet, fieldSet_, iter)
345  {
346  const word fieldName
347  (
348  IOobject::groupName(prefix_ + iter.key(), phaseName_)
349  );
350  writeObject(fieldName);
351  }
352 
353  return true;
354 }
355 
356 
357 // ************************************************************************* //
label k
#define R(A, B, C, D, E, F, K, M)
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
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:54
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 turbulence models.
virtual tmp< volSymmTensorField > devTau() const =0
Return the effective stress tensor including the laminar stress.
A list of keyword definitions, which are a keyword followed by any number of values (e....
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< compressibleField, 8 > compressibleFieldNames_
static const NamedEnum< incompressibleField, 7 > incompressibleFieldNames_
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 turbulence models.
virtual tmp< volSymmTensorField > devSigma() const
Return the effective stress tensor.
virtual tmp< volScalarField > nut() const =0
Return the turbulence viscosity.
virtual tmp< volScalarField > k() const =0
Return the turbulence kinetic energy.
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< volSymmTensorField > sigma() const =0
Return the stress tensor [m^2/s^2].
virtual tmp< volScalarField > kappaEff() const =0
Effective thermal turbulent conductivity.
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
#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
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, 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 & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
error FatalError
static const char nl
Definition: Ostream.H:266
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
labelList f(nPoints)
dictionary dict