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-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 "basicThermo.H"
27 #include "wordIOList.H"
28 #include "compileTemplate.H"
29 
30 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
31 
32 // Convert multiComponent -> multicomponent for backward-compatibility
33 inline Foam::word mixtureName(const Foam::dictionary& thermoTypeDict)
34 {
35  return
36  thermoTypeDict.lookup<Foam::word>("mixture")
37  .replace("multiComponent", "multicomponent");
38 }
39 
40 
41 template<class Thermo, class Table>
42 typename Table::iterator Foam::basicThermo::lookupCstrIter
43 (
44  const dictionary& thermoTypeDict,
45  Table* tablePtr,
46  const int nCmpt,
47  const char* cmptNames[],
48  const word& thermoTypeName
49 )
50 {
51  // Lookup the thermo package
52  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
53 
54  if (cstrIter == tablePtr->end())
55  {
56  if
57  (
58  nCmpt == 7
60  && !dynamicCode::resolveTemplate(Thermo::typeName).empty()
61  )
62  {
64  (
65  Thermo::typeName,
66  thermoTypeName,
68  {
69  {"type", thermoTypeDict.lookup("type")},
70  {"mixture", mixtureName(thermoTypeDict)},
71  {"transport", thermoTypeDict.lookup("transport")},
72  {"thermo", thermoTypeDict.lookup("thermo")},
73  {
74  "equationOfState",
75  thermoTypeDict.lookup("equationOfState")
76  },
77  {"specie", thermoTypeDict.lookup("specie")},
78  {"energy", thermoTypeDict.lookup("energy")}
79  }
80  );
81  cstrIter = tablePtr->find(thermoTypeName);
82 
83  if (cstrIter == tablePtr->end())
84  {
86  << "Compilation and linkage of "
87  << Thermo::typeName << " type " << nl
88  << "thermoType" << thermoTypeDict << nl << nl
89  << "failed." << nl << nl
90  << "Valid " << Thermo::typeName << " types are:"
91  << nl << nl;
92  }
93  }
94  else
95  {
96  // Print error message if package not found in the table
98  << "Unknown " << Thermo::typeName << " type " << nl
99  << "thermoType" << thermoTypeDict << nl << nl
100  << "Valid " << Thermo::typeName << " types are:"
101  << nl << nl;
102  }
103 
104  if (cstrIter == tablePtr->end())
105  {
106  // Get the list of all the suitable thermo packages available
107  wordList validThermoTypeNames(tablePtr->sortedToc());
108 
109  // Build a table of the thermo packages constituent parts
110  DynamicList<wordList> validThermoTypeNameCmpts;
111 
112  // Set row zero to the column headers
113  validThermoTypeNameCmpts.append(wordList(nCmpt));
114  forAll(validThermoTypeNameCmpts[0], i)
115  {
116  validThermoTypeNameCmpts[0][i] = cmptNames[i];
117  }
118 
119  // Split the thermo package names into their constituent parts and
120  // add them to the table, removing any incompatible entries from the
121  // list
122  forAll(validThermoTypeNames, i)
123  {
124  const wordList names
125  (
126  Thermo::splitThermoName(validThermoTypeNames[i], nCmpt)
127  );
128 
129  if (names.size())
130  {
131  validThermoTypeNameCmpts.append(names);
132  }
133  }
134 
135  // Print the table of available packages
136  printTable(validThermoTypeNameCmpts, FatalError);
137 
139  }
140  }
141 
142  return cstrIter;
143 }
144 
145 
146 template<class Thermo, class Table>
147 typename Table::iterator Foam::basicThermo::lookupCstrIter
148 (
149  const dictionary& thermoDict,
150  Table* tablePtr
151 )
152 {
153  if (thermoDict.isDict("thermoType"))
154  {
155  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
156 
157  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
158 
159  if (thermoTypeDict.found("properties"))
160  {
161  const int nCmpt = 4;
162  const char* cmptNames[nCmpt] =
163  {
164  "type",
165  "mixture",
166  "properties",
167  "energy"
168  };
169 
170  // Construct the name of the thermo package from the components
171  const word thermoTypeName
172  (
173  word(thermoTypeDict.lookup("type")) + '<'
174  + word(mixtureName(thermoTypeDict)) + '<'
175  + word(thermoTypeDict.lookup("properties")) + ','
176  + word(thermoTypeDict.lookup("energy")) + ">>"
177  );
178 
179  return lookupCstrIter<Thermo, Table>
180  (
181  thermoTypeDict,
182  tablePtr,
183  nCmpt,
184  cmptNames,
185  thermoTypeName
186  );
187  }
188  else
189  {
190  const int nCmpt = 7;
191  const char* cmptNames[nCmpt] =
192  {
193  "type",
194  "mixture",
195  "transport",
196  "thermo",
197  "equationOfState",
198  "specie",
199  "energy"
200  };
201 
202  // Construct the name of the thermo package from the components
203  const word thermoTypeName
204  (
205  word(thermoTypeDict.lookup("type")) + '<'
206  + word(mixtureName(thermoTypeDict)) + '<'
207  + word(thermoTypeDict.lookup("transport")) + '<'
208  + word(thermoTypeDict.lookup("thermo")) + '<'
209  + word(thermoTypeDict.lookup("equationOfState")) + '<'
210  + word(thermoTypeDict.lookup("specie")) + ">>,"
211  + word(thermoTypeDict.lookup("energy")) + ">>>"
212  );
213 
214  return lookupCstrIter<Thermo, Table>
215  (
216  thermoTypeDict,
217  tablePtr,
218  nCmpt,
219  cmptNames,
220  thermoTypeName
221  );
222  }
223  }
224  else
225  {
226  const word thermoTypeName(thermoDict.lookup("thermoType"));
227 
228  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
229 
230  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
231 
232  if (cstrIter == tablePtr->end())
233  {
235  << "Unknown " << Thermo::typeName << " type "
236  << thermoTypeName << nl << nl
237  << "Valid " << Thermo::typeName << " types are:" << nl
238  << tablePtr->sortedToc() << nl
239  << exit(FatalError);
240  }
241 
242  return cstrIter;
243  }
244 }
245 
246 
247 template<class FieldType>
249 (
250  const FieldType& f
251 )
252 {
253  const word& name = physicalProperties::typeName;
254 
255  if (f.db().template foundObject<basicThermo>(name))
256  {
257  return f.db().template lookupObject<basicThermo>(name);
258  }
259  else
260  {
262  f.db().template lookupClass<basicThermo>();
263 
264  for
265  (
267  iter != thermos.end();
268  ++iter
269  )
270  {
271  if (&(iter()->he().internalField()) == &(f.internalField()))
272  {
273  return *iter();
274  }
275  }
276  }
277 
278  return f.db().template lookupObject<basicThermo>(name);
279 }
280 
281 
282 
283 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
284 
285 template<class Thermo>
287 (
288  const fvMesh& mesh,
289  const word& phaseName
290 )
291 {
292  const IOdictionary thermoDict
293  (
294  physicalProperties::findModelDict(mesh, phaseName)
295  );
296 
297  typename Thermo::fvMeshConstructorTable::iterator cstrIter =
298  lookupCstrIter<Thermo, typename Thermo::fvMeshConstructorTable>
299  (
300  thermoDict,
301  Thermo::fvMeshConstructorTablePtr_
302  );
303 
304  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
305 }
306 
307 
308 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Foam::word mixtureName(const Foam::dictionary &thermoTypeDict)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
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:411
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
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
static const basicThermo & lookupThermo(const FieldType &f)
Lookup the thermo associated with the given field.
static Table::iterator lookupCstrIter(const dictionary &thermoTypeDict, Table *tablePtr, const int nCmpt, const char *cmptNames[], const word &thermoTypeName)
Get the constructor iterator for the given thermo dictionary and.
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
A list of keyword definitions, which are a keyword followed by any number of values (e....
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:710
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:797
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:156
static fileName resolveTemplate(const fileName &templateName)
Resolve code-template via the codeTemplateEnvName.
Definition: dynamicCode.C:143
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
static IOobject findModelDict(const objectRegistry &obr, const word &group, bool registerObject=false)
Find the physicalProperties dictionary and return the IOobject.
A class for handling words, derived from string.
Definition: word.H:62
#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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:43
error FatalError
static const char nl
Definition: Ostream.H:266
thermo he()
labelList f(nPoints)
fluidMulticomponentThermo & thermo
Definition: createFields.H:31
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112