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-------------------------------------------------------------------------------
11License
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
36namespace Foam
37{
38namespace functionObjects
39{
42}
43}
44
45const 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
66const 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
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
bool unset(const Key &key)
Unset the specified key - same as erase.
Definition: HashSet.H:204
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
Templated abstract base class for single-phase incompressible turbulence models.
virtual bool read()
Re-read model coefficients if they have changed.
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
Watches for presence of the named trigger file in the case directory and signals a simulation stop (o...
Definition: abort.H:128
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const objectRegistry & obr_
Reference to the region objectRegistry.
Computes various turbulence-related quantities that are not typically output during calculations,...
static const word modelName_
Name of the turbulence properties dictionary.
word prefix_
Name of output-field prefix.
void initialise()
Unset duplicate fields already registered by other function objects.
bool compressible()
Return true if compressible turbulence model is identified.
bool initialised_
Flag to track initialisation.
static const Enum< incompressibleField > incompressibleFieldNames_
Names for incompressibleField turbulence fields.
compressibleField
Options for the turbulence fields (compressible)
incompressibleField
Options for the turbulence fields (incompressible)
wordHashSet fieldSet_
Fields to load.
virtual bool execute()
Calculate turbulence fields.
static const Enum< compressibleField > compressibleFieldNames_
Names for compressibleField turbulence fields.
virtual bool read(const dictionary &)
Read the controls.
bool found(const word &name, const bool recursive=false) const
Can the regIOobject object be found (by name).
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
bool compressible
Definition: pEqn.H:2
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static const Identity< scalar > I
Definition: Identity.H:94
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)
dictionary dict
const vector L(dict.get< vector >("L"))