turbulenceFields.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "turbulenceFields.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
40  defineTypeNameAndDebug(turbulenceFields, 0);
41  addToRunTimeSelectionTable(functionObject, turbulenceFields, dictionary);
42 }
43 }
44 
45 const Foam::Enum
46 <
48 >
50 ({
51  { compressibleField::cfK, "k" },
52  { compressibleField::cfEpsilon, "epsilon" },
53  { compressibleField::cfOmega, "omega" },
54  { compressibleField::cfNuTilda, "nuTilda" },
55  { compressibleField::cfMut, "mut" },
56  { compressibleField::cfMuEff, "muEff" },
57  { compressibleField::cfAlphat, "alphat" },
58  { compressibleField::cfAlphaEff, "alphaEff" },
59  { compressibleField::cfR, "R" },
60  { compressibleField::cfDevRhoReff, "devRhoReff" },
61  { compressibleField::cfL, "L" },
62  { compressibleField::cfI, "I" },
63 });
64 
65 
66 const Foam::Enum
67 <
69 >
71 ({
72  { incompressibleField::ifK, "k" },
73  { incompressibleField::ifEpsilon, "epsilon" },
74  { incompressibleField::ifOmega, "omega" },
75  { incompressibleField::ifNuTilda, "nuTilda" },
76  { incompressibleField::ifNut, "nut" },
77  { incompressibleField::ifNuEff, "nuEff" },
78  { incompressibleField::ifR, "R" },
79  { incompressibleField::ifDevReff, "devReff" },
80  { incompressibleField::ifL, "L" },
81  { incompressibleField::ifI, "I" },
82 });
83 
84 
86 (
88 );
89 
90 
91 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
92 
94 {
95  for (const word& f : fieldSet_)
96  {
97  const word localName(IOobject::scopedName(prefix_, f));
98 
99  if (obr_.found(localName))
100  {
102  << "Cannot store turbulence field " << localName
103  << " since an object with that name already exists"
104  << nl << endl;
105 
106  fieldSet_.unset(f);
107  }
108  }
109 
110  initialised_ = true;
111 }
112 
113 
115 {
116  if (obr_.foundObject<compressible::turbulenceModel>(modelName_))
117  {
118  return true;
119  }
120  else if (obr_.foundObject<incompressible::turbulenceModel>(modelName_))
121  {
122  return false;
123  }
124 
126  << "Turbulence model not found in database, deactivating"
127  << exit(FatalError);
128 
129  return false;
130 }
131 
132 
133 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
134 
136 (
137  const word& name,
138  const Time& runTime,
139  const dictionary& dict
140 )
141 :
143  initialised_(false),
144  prefix_(dict.getOrDefault<word>("prefix", "turbulenceProperties")),
145  fieldSet_()
146 {
147  read(dict);
148 }
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
154 {
156  {
157  dict.readIfPresent("prefix", prefix_);
158 
159  if (dict.found("field"))
160  {
161  fieldSet_.insert(dict.get<word>("field"));
162  }
163  else
164  {
165  fieldSet_.insert(dict.get<wordList>("fields"));
166  }
167 
168  Info<< type() << " " << name() << ": ";
169  if (fieldSet_.size())
170  {
171  Info<< "storing fields:" << nl;
172  for (const word& f : fieldSet_)
173  {
174  Info<< " " << IOobject::scopedName(prefix_, f) << nl;
175  }
176  Info<< endl;
177  }
178  else
179  {
180  Info<< "no fields requested to be stored" << nl << endl;
181  }
182 
183  initialised_ = false;
184 
185  return true;
186  }
187 
188  return false;
189 }
190 
191 
193 {
194  if (!initialised_)
195  {
196  initialise();
197  }
198 
199  const bool comp = compressible();
200 
201  if (comp)
202  {
203  const auto& model =
204  obr_.lookupObject<compressible::turbulenceModel>(modelName_);
205 
206  for (const word& f : fieldSet_)
207  {
208  switch (compressibleFieldNames_[f])
209  {
210  case cfK:
211  {
212  processField<scalar>(f, model.k());
213  break;
214  }
215  case cfEpsilon:
216  {
217  processField<scalar>(f, model.epsilon());
218  break;
219  }
220  case cfOmega:
221  {
222  processField<scalar>(f, model.omega());
223  break;
224  }
225  case cfNuTilda:
226  {
227  processField<scalar>(f, nuTilda(model));
228  break;
229  }
230  case cfMut:
231  {
232  processField<scalar>(f, model.mut());
233  break;
234  }
235  case cfMuEff:
236  {
237  processField<scalar>(f, model.muEff());
238  break;
239  }
240  case cfAlphat:
241  {
242  processField<scalar>(f, model.alphat());
243  break;
244  }
245  case cfAlphaEff:
246  {
247  processField<scalar>(f, model.alphaEff());
248  break;
249  }
250  case cfR:
251  {
252  processField<symmTensor>(f, model.R());
253  break;
254  }
255  case cfDevRhoReff:
256  {
257  processField<symmTensor>(f, model.devRhoReff());
258  break;
259  }
260  case cfL:
261  {
262  processField<scalar>(f, L(model));
263  break;
264  }
265  case cfI:
266  {
267  processField<scalar>(f, I(model));
268  break;
269  }
270  default:
271  {
273  << "Invalid field selection" << abort(FatalError);
274  }
275  }
276  }
277  }
278  else
279  {
280  const auto& model =
281  obr_.lookupObject<incompressible::turbulenceModel>(modelName_);
282 
283  for (const word& f : fieldSet_)
284  {
285  switch (incompressibleFieldNames_[f])
286  {
287  case ifK:
288  {
289  processField<scalar>(f, model.k());
290  break;
291  }
292  case ifEpsilon:
293  {
294  processField<scalar>(f, model.epsilon());
295  break;
296  }
297  case ifOmega:
298  {
299  processField<scalar>(f, model.omega());
300  break;
301  }
302  case ifNuTilda:
303  {
304  processField<scalar>(f, nuTilda(model));
305  break;
306  }
307  case ifNut:
308  {
309  processField<scalar>(f, model.nut());
310  break;
311  }
312  case ifNuEff:
313  {
314  processField<scalar>(f, model.nuEff());
315  break;
316  }
317  case ifR:
318  {
319  processField<symmTensor>(f, model.R());
320  break;
321  }
322  case ifDevReff:
323  {
324  processField<symmTensor>(f, model.devReff());
325  break;
326  }
327  case ifL:
328  {
329  processField<scalar>(f, L(model));
330  break;
331  }
332  case ifI:
333  {
334  processField<scalar>(f, I(model));
335  break;
336  }
337  default:
338  {
340  << "Invalid field selection" << abort(FatalError);
341  }
342  }
343  }
344  }
345 
346  return true;
347 }
348 
349 
351 {
352  for (const word& f : fieldSet_)
353  {
354  const word localName(IOobject::scopedName(prefix_, f));
355 
356  writeObject(localName);
357  }
358  Info<< endl;
359 
360  return true;
361 }
362 
363 
364 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::turbulenceFields::initialise
void initialise()
Unset duplicate fields already registered by other function objects.
Definition: turbulenceFields.C:93
L
const vector L(dict.get< vector >("L"))
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:102
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::turbulenceFields::incompressibleFieldNames_
static const Enum< incompressibleField > incompressibleFieldNames_
Names for incompressibleField turbulence fields.
Definition: turbulenceFields.H:258
Foam::functionObjects::turbulenceFields::modelName_
static const word modelName_
Name of the turbulence properties dictionary.
Definition: turbulenceFields.H:261
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::turbulenceFields::compressibleField
compressibleField
Options for the turbulence fields (compressible)
Definition: turbulenceFields.H:223
turbulentTransportModel.H
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
Foam::functionObjects::turbulenceFields::turbulenceFields
turbulenceFields(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: turbulenceFields.C:136
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::turbulenceFields::prefix_
word prefix_
Name of output-field prefix.
Definition: turbulenceFields.H:272
Foam::functionObjects::turbulenceFields::fieldSet_
wordHashSet fieldSet_
Fields to load.
Definition: turbulenceFields.H:275
Foam::functionObjects::turbulenceFields::write
virtual bool write()
Do nothing.
Definition: turbulenceFields.C:350
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::HashSet::unset
bool unset(const Key &key)
Unset the specified key - same as erase.
Definition: HashSet.H:204
compressible
bool compressible
Definition: pEqn.H:2
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::objectRegistry::found
bool found(const word &name, const bool recursive=false) const
Can the regIOobject object be found (by name).
Definition: objectRegistry.C:432
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::functionObjects::turbulenceFields::read
virtual bool read(const dictionary &)
Read the controls.
Definition: turbulenceFields.C:153
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::functionObjects::turbulenceFields::compressibleFieldNames_
static const Enum< compressibleField > compressibleFieldNames_
Names for compressibleField turbulence fields.
Definition: turbulenceFields.H:240
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::turbulenceFields::incompressibleField
incompressibleField
Options for the turbulence fields (incompressible)
Definition: turbulenceFields.H:243
f
labelList f(nPoints)
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:47
Foam::List< word >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
turbulenceFields.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::turbulenceFields::initialised_
bool initialised_
Flag to track initialisation.
Definition: turbulenceFields.H:269
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:55
Foam::IOobject::scopedName
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
Foam::functionObjects::turbulenceFields::compressible
bool compressible()
Return true if compressible turbulence model is identified.
Definition: turbulenceFields.C:114
Foam::functionObjects::turbulenceFields::execute
virtual bool execute()
Calculate turbulence fields.
Definition: turbulenceFields.C:192
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
turbulentFluidThermoModel.H
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95