basicThermoTemplates.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) 2012-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 "basicThermo.H"
27 #include "wordIOList.H"
28 #include "compileTemplate.H"
29 
30 // * * * * * * * * * * * Private Static Member Functions * * * * * * * * * * //
31 
32 template<class Thermo, class Table>
33 typename Table::iterator Foam::basicThermo::lookupCstrIter
34 (
35  const dictionary& thermoTypeDict,
36  Table* tablePtr,
37  const int nCmpt,
38  const char* cmptNames[],
39  const word& thermoTypeName
40 )
41 {
42  // Lookup the thermo package
43  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
44 
45  if (cstrIter == tablePtr->end())
46  {
47  if
48  (
49  nCmpt == 7
52  )
53  {
54  compileTemplate thermo
55  (
57  thermoTypeName,
58  List<Pair<word>>
59  {
60  {"type", thermoTypeDict.lookup("type")},
61  {"mixture", mixtureName(thermoTypeDict)},
62  {"transport", thermoTypeDict.lookup("transport")},
63  {"thermo", thermoTypeDict.lookup("thermo")},
64  {
65  "equationOfState",
66  thermoTypeDict.lookup("equationOfState")
67  },
68  {"specie", thermoTypeDict.lookup("specie")},
69  {"energy", thermoTypeDict.lookup("energy")}
70  }
71  );
72  cstrIter = tablePtr->find(thermoTypeName);
73 
74  if (cstrIter == tablePtr->end())
75  {
77  << "Compilation and linkage of "
78  << Thermo::typeName << " type " << nl
79  << "thermoType" << thermoTypeDict << nl << nl
80  << "failed." << nl << nl
81  << "Valid " << Thermo::typeName << " types are:"
82  << nl << nl;
83  }
84  }
85  else
86  {
87  // Print error message if package not found in the table
89  << "Unknown " << Thermo::typeName << " type " << nl
90  << "thermoType" << thermoTypeDict << nl << nl
91  << "Valid " << Thermo::typeName << " types are:"
92  << nl << nl;
93  }
94 
95  if (cstrIter == tablePtr->end())
96  {
97  // Get the list of all the suitable thermo packages available
98  wordList validThermoTypeNames(tablePtr->sortedToc());
99 
100  // Build a table of the thermo packages constituent parts
101  DynamicList<wordList> validThermoTypeNameCmpts;
102 
103  // Set row zero to the column headers
104  validThermoTypeNameCmpts.append(wordList(nCmpt));
105  forAll(validThermoTypeNameCmpts[0], i)
106  {
107  validThermoTypeNameCmpts[0][i] = cmptNames[i];
108  }
109 
110  // Split the thermo package names into their constituent parts and
111  // add them to the table, removing any incompatible entries from the
112  // list
113  forAll(validThermoTypeNames, i)
114  {
115  const wordList names
116  (
117  splitThermoName(validThermoTypeNames[i], nCmpt)
118  );
119 
120  if (names.size())
121  {
122  validThermoTypeNameCmpts.append(names);
123  }
124  }
125 
126  // Print the table of available packages
127  printTable(validThermoTypeNameCmpts, FatalError);
128 
130  }
131  }
132 
133  return cstrIter;
134 }
135 
136 
137 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
138 
139 template<class Thermo, class Table>
140 typename Table::iterator Foam::basicThermo::lookupCstrIter
141 (
142  const dictionary& thermoDict,
143  Table* tablePtr
144 )
145 {
146  if (thermoDict.isDict("thermoType"))
147  {
148  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
149 
150  Info<< indentOrNl
151  << "Selecting thermodynamics package " << thermoTypeDict;
152 
153  if (thermoTypeDict.found("properties"))
154  {
155  const int nCmpt = 4;
156  const char* cmptNames[nCmpt] =
157  {
158  "type",
159  "mixture",
160  "properties",
161  "energy"
162  };
163 
164  // Construct the name of the thermo package from the components
165  const word thermoTypeName
166  (
167  word(thermoTypeDict.lookup("type")) + '<'
168  + word(mixtureName(thermoTypeDict)) + '<'
169  + word(thermoTypeDict.lookup("properties")) + ','
170  + word(thermoTypeDict.lookup("energy")) + ">>"
171  );
172 
173  return lookupCstrIter<Thermo, Table>
174  (
175  thermoTypeDict,
176  tablePtr,
177  nCmpt,
178  cmptNames,
179  thermoTypeName
180  );
181  }
182  else
183  {
184  const int nCmpt = 7;
185  const char* cmptNames[nCmpt] =
186  {
187  "type",
188  "mixture",
189  "transport",
190  "thermo",
191  "equationOfState",
192  "specie",
193  "energy"
194  };
195 
196  // Construct the name of the thermo package from the components
197  const word thermoTypeName
198  (
199  word(thermoTypeDict.lookup("type")) + '<'
200  + word(mixtureName(thermoTypeDict)) + '<'
201  + word(thermoTypeDict.lookup("transport")) + '<'
202  + word(thermoTypeDict.lookup("thermo")) + '<'
203  + word(thermoTypeDict.lookup("equationOfState")) + '<'
204  + word(thermoTypeDict.lookup("specie")) + ">>,"
205  + word(thermoTypeDict.lookup("energy")) + ">>>"
206  );
207 
208  return lookupCstrIter<Thermo, Table>
209  (
210  thermoTypeDict,
211  tablePtr,
212  nCmpt,
213  cmptNames,
214  thermoTypeName
215  );
216  }
217  }
218  else
219  {
220  const word thermoTypeName(thermoDict.lookup("thermoType"));
221 
222  Info<< indentOrNl
223  << "Selecting thermodynamics package " << thermoTypeName << endl;
224 
225  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
226 
227  if (cstrIter == tablePtr->end())
228  {
230  << "Unknown " << Thermo::typeName << " type "
231  << thermoTypeName << nl << nl
232  << "Valid " << Thermo::typeName << " types are:" << nl
233  << tablePtr->sortedToc() << nl
234  << exit(FatalError);
235  }
236 
237  return cstrIter;
238  }
239 }
240 
241 
242 template<class FieldType>
244 (
245  const FieldType& f
246 )
247 {
249 
250  if (f.db().template foundObject<basicThermo>(name))
251  {
252  return f.db().template lookupObject<basicThermo>(name);
253  }
254  else
255  {
257  f.db().template lookupClass<basicThermo>();
258 
259  for
260  (
262  iter != thermos.end();
263  ++iter
264  )
265  {
266  if (&(iter()->he().internalField()) == &(f.internalField()))
267  {
268  return *iter();
269  }
270  }
271  }
272 
273  return f.db().template lookupObject<basicThermo>(name);
274 }
275 
276 
277 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
278 
279 template<class Thermo>
281 (
282  const fvMesh& mesh,
283  const word& phaseName
284 )
285 {
286  const IOdictionary thermoDict
287  (
289  );
290 
291  typename Thermo::fvMeshConstructorTable::iterator cstrIter =
292  lookupCstrIter<Thermo, typename Thermo::fvMeshConstructorTable>
293  (
294  thermoDict,
295  Thermo::fvMeshConstructorTablePtr_
296  );
297 
298  printDictionary print(thermoDict.dictionary::name());
299 
300  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
301 }
302 
303 
304 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
An STL-conforming iterator.
Definition: HashTable.H:443
An STL-conforming hash table.
Definition: HashTable.H:127
iterator begin()
Iterator set to the beginning of the HashTable.
Definition: HashTableI.H:395
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
virtual word mixtureName() const =0
Name of the mixture.
static const basicThermo & lookupThermo(const FieldType &f)
Lookup the thermo associated with the given field.
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
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
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:732
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:778
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:468
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:188
static fileName resolveTemplate(const fileName &templateName)
Resolve code-template via Foam::findConfigFile.
Definition: dynamicCode.C:481
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
static IOobject findModelDict(const objectRegistry &obr, const word &group, bool registerObject=false)
Find the physicalProperties dictionary and return the IOobject.
Motion of the mesh specified as a list of pointMeshMovers.
Enables the printing of a dictionary and subsequently looked-up defaulted entries.
A class for handling words, derived from string.
Definition: word.H:63
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
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:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:43
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & indentOrNl(Ostream &os)
Indent stream or add newline if indent level == 0.
Definition: Ostream.H:250
error FatalError
static const char nl
Definition: Ostream.H:297
labelList f(nPoints)
fluidMulticomponentThermo & thermo
Definition: createFields.H:15
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112