basicThermo.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) 2011-2025 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 "basicThermo.H"
33 #include "fixedJumpFvPatchFields.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
43 }
44 
45 
46 // * * * * * * * * * * * Private Static Member Functions * * * * * * * * * * //
47 
49 (
50  const Foam::dictionary& thermoTypeDict
51 )
52 {
53  return
54  thermoTypeDict.lookup<Foam::word>("mixture")
55  .replace("multiComponent", "multicomponent");
56 }
57 
58 
59 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
60 
62 (
63  const fvMesh& mesh,
64  const char* name
65 )
66 {
67  if (!mesh.objectRegistry::foundObject<volScalarField>(name))
68  {
69  volScalarField* fPtr
70  (
71  new volScalarField
72  (
73  IOobject
74  (
75  name,
76  mesh.time().name(),
77  mesh,
80  ),
81  mesh
82  )
83  );
84 
85  // Transfer ownership of this object to the objectRegistry
86  fPtr->store(fPtr);
87  }
88 
89  return mesh.objectRegistry::lookupObjectRef<volScalarField>(name);
90 }
91 
92 
94 (
95  const word& thermoName,
96  const int nCmpt
97 )
98 {
99  wordList cmpts(nCmpt);
100 
101  string::size_type beg=0, end=0, endb=0, endc=0;
102  int i = 0;
103 
104  while
105  (
106  (endb = thermoName.find('<', beg)) != string::npos
107  || (endc = thermoName.find(',', beg)) != string::npos
108  )
109  {
110  if (endb == string::npos)
111  {
112  end = endc;
113  }
114  else if ((endc = thermoName.find(',', beg)) != string::npos)
115  {
116  end = min(endb, endc);
117  }
118  else
119  {
120  end = endb;
121  }
122 
123  if (beg < end)
124  {
125  cmpts[i] = thermoName.substr(beg, end-beg);
126  cmpts[i++].replaceAll(">","");
127 
128  // If the number of number of components in the name
129  // is greater than nCmpt return an empty list
130  if (i == nCmpt)
131  {
132  return wordList();
133  }
134  }
135  beg = end + 1;
136  }
137 
138  // If the number of number of components in the name is not equal to nCmpt
139  // return an empty list
140  if (i + 1 != nCmpt)
141  {
142  return wordList();
143  }
144 
145  if (beg < thermoName.size())
146  {
147  cmpts[i] = thermoName.substr(beg, string::npos);
148  cmpts[i].replaceAll(">","");
149  }
150 
151  return cmpts;
152 }
153 
154 
156 (
157  const word& thermoName
158 )
159 {
160  const wordList components(splitThermoName(thermoName, 5));
161 
162  return List<Pair<word>>
163  {
164  {"transport", components[0]},
165  {"thermo", components[1]},
166  {"equationOfState", components[2]},
167  {"specie", components[3]},
168  {"energy", components[4]}
169  };
170 }
171 
172 
173 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
174 
176 {
177  const volScalarField::Boundary& tbf = T().boundaryField();
178 
179  wordList hbt(tbf.size(), word::null);
180 
181  forAll(tbf, patchi)
182  {
183  if (tbf[patchi].overridesConstraint())
184  {
185  hbt[patchi] = tbf[patchi].patch().type();
186  }
187  }
188 
189  return hbt;
190 }
191 
192 
194 {
195  const volScalarField::Boundary& tbf = T().boundaryField();
196 
197  wordList hbt = tbf.types();
198 
199  forAll(tbf, patchi)
200  {
201  if (isA<fixedValueFvPatchScalarField>(tbf[patchi]))
202  {
204  }
205  else if
206  (
207  isA<zeroGradientFvPatchScalarField>(tbf[patchi])
208  || isA<fixedGradientFvPatchScalarField>(tbf[patchi])
209  || isA<gradientEnergyCalculatedTemperatureFvPatchScalarField>
210  (
211  tbf[patchi]
212  )
213  )
214  {
216  }
217  else if
218  (
219  isA<mixedFvPatchScalarField>(tbf[patchi])
220  || isA<mixedEnergyCalculatedTemperatureFvPatchScalarField>
221  (
222  tbf[patchi]
223  )
224  )
225  {
227  }
228  else if (isA<jumpCyclicFvPatchScalarField>(tbf[patchi]))
229  {
231  }
232  }
233 
234  return hbt;
235 }
236 
237 
239 {
240  const HashTable<word> tst = T().sources().types();
241 
242  HashTable<word> hst;
243  forAllConstIter(typename HashTable<word>, tst, iter)
244  {
245  hst.set(iter.key(), energyFvScalarFieldSource::typeName);
246  }
247 
248  return hst;
249 }
250 
251 
252 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
253 
255 (
256  const dictionary& dict,
257  const fvMesh& mesh,
258  const word& phaseName
259 )
260 :
261  mesh_(mesh),
262 
263  phaseName_(phaseName),
264 
265  T_
266  (
267  IOobject
268  (
269  phasePropertyName("T", phaseName),
270  mesh.time().name(),
271  mesh,
272  IOobject::MUST_READ,
273  IOobject::AUTO_WRITE
274  ),
275  mesh
276  ),
277 
278  kappa_
279  (
280  IOobject
281  (
282  phasePropertyName("kappa", phaseName),
283  mesh.time().name(),
284  mesh,
285  IOobject::READ_IF_PRESENT,
286  IOobject::NO_WRITE
287  ),
288  mesh,
290  ),
291 
292  dpdt_(dict.lookupOrDefault<Switch>("dpdt", true))
293 {}
294 
295 
296 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
297 
299 (
300  const fvMesh& mesh,
301  const word& phaseName
302 )
303 {
304  return New<basicThermo>(mesh, phaseName);
305 }
306 
307 
308 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
309 
311 {}
312 
313 
315 {}
316 
317 
318 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
319 
321 (
322  const string& app,
323  const word& a
324 ) const
325 {
326  if (!(he().name() == phasePropertyName(a)))
327  {
329  << "Supported energy type is " << phasePropertyName(a)
330  << ", thermodynamics package provides " << he().name()
331  << exit(FatalError);
332  }
333 }
334 
335 
337 (
338  const string& app,
339  const word& a,
340  const word& b
341 ) const
342 {
343  if
344  (
345  !(
346  he().name() == phasePropertyName(a)
347  || he().name() == phasePropertyName(b)
348  )
349  )
350  {
352  << "Supported energy types are " << phasePropertyName(a)
353  << " and " << phasePropertyName(b)
354  << ", thermodynamics package provides " << he().name()
355  << exit(FatalError);
356  }
357 }
358 
359 
361 {
362  return volScalarField::New(phasePropertyName("gamma"), Cp()/Cv());
363 }
364 
365 
367 (
368  const scalarField& T,
369  const label patchi
370 ) const
371 {
372  return Cp(T, patchi)/Cv(T, patchi);
373 }
374 
375 
377 {
378  return T_;
379 }
380 
381 
383 {
384  return T_;
385 }
386 
387 
389 {
390  return kappa_;
391 }
392 
393 
395 {}
396 
397 
398 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Generic GeometricBoundaryField class.
wordList types() const
Return a list of the patch field types.
Generic GeometricField class.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:307
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
virtual const volScalarField & T() const
Temperature [K].
Definition: basicThermo.C:376
virtual const volScalarField & kappa() const
Thermal conductivity of mixture [W/m/K].
Definition: basicThermo.C:388
virtual ~implementation()
Destructor.
Definition: basicThermo.C:314
implementation(const dictionary &, const fvMesh &, const word &)
Construct from dictionary, mesh and phase name.
Definition: basicThermo.C:255
virtual void read(const dictionary &)
Read thermophysical properties dictionary.
Definition: basicThermo.C:394
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
virtual word mixtureName() const =0
Name of the mixture.
virtual const volScalarField & Cv() const =0
Heat capacity at constant volume [J/kg/K].
static List< Pair< word > > thermoNameComponents(const word &thermoName)
Split name of thermo package into a list of named components names.
Definition: basicThermo.C:156
wordList heBoundaryTypes()
Enthalpy/internal energy field boundary types.
Definition: basicThermo.C:193
HashTable< word > heSourcesTypes()
Enthalpy/internal energy field sources types.
Definition: basicThermo.C:238
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:151
wordList heBoundaryBaseTypes()
Enthalpy/internal energy field boundary base types.
Definition: basicThermo.C:175
static wordList splitThermoName(const word &thermoName, const int nCmpt)
Split name of thermo package into a list of the components names.
Definition: basicThermo.C:94
virtual const fvMesh & mesh() const =0
Return const access to the mesh.
virtual const volScalarField & T() const =0
Temperature [K].
virtual const volScalarField & Cp() const =0
Heat capacity at constant pressure [J/kg/K].
virtual const word & phaseName() const =0
Phase name.
tmp< volScalarField > gamma() const
Gamma = Cp/Cv [].
Definition: basicThermo.C:360
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:321
virtual ~basicThermo()
Destructor.
Definition: basicThermo.C:310
virtual const volScalarField & he() const =0
Enthalpy/Internal energy [J/kg].
static volScalarField & lookupOrConstruct(const fvMesh &mesh, const char *name)
Lookup and the named field, or construct it as MUST-READ if it is.
Definition: basicThermo.C:62
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
const word & name() const
Return const reference to name.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:40
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
volScalarField & b
Definition: createFields.H:27
const dimensionSet time
Namespace for OpenFOAM.
const dimensionSet & dimThermalConductivity
Definition: dimensions.C:175
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
List< word > wordList
A List of words.
Definition: fileName.H:54
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
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
defineRunTimeSelectionTable(fvConstraint, dictionary)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
dictionary dict