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-2021 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 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  dynamicCode::allowSystemOperations
50  && !dynamicCode::resolveTemplate(Thermo::typeName).empty()
51  )
52  {
54  (
55  Thermo::typeName,
56  thermoTypeName,
58  {
59  {"type", thermoTypeDict.lookup("type")},
60  {"mixture", thermoTypeDict.lookup("mixture")},
61  {"transport", thermoTypeDict.lookup("transport")},
62  {"thermo", thermoTypeDict.lookup("thermo")},
63  {
64  "equationOfState",
65  thermoTypeDict.lookup("equationOfState")
66  },
67  {"specie", thermoTypeDict.lookup("specie")},
68  {"energy", thermoTypeDict.lookup("energy")}
69  }
70  );
71  cstrIter = tablePtr->find(thermoTypeName);
72 
73  if (cstrIter == tablePtr->end())
74  {
76  << "Compilation and linkage of "
77  << Thermo::typeName << " type " << nl
78  << "thermoType" << thermoTypeDict << nl << nl
79  << "failed." << nl << nl
80  << "Valid " << Thermo::typeName << " types are:"
81  << nl << nl;
82  }
83  }
84  else
85  {
86  // Print error message if package not found in the table
88  << "Unknown " << Thermo::typeName << " type " << nl
89  << "thermoType" << thermoTypeDict << nl << nl
90  << "Valid " << Thermo::typeName << " types are:"
91  << nl << nl;
92  }
93 
94  if (cstrIter == tablePtr->end())
95  {
96  // Get the list of all the suitable thermo packages available
97  wordList validThermoTypeNames(tablePtr->sortedToc());
98 
99  // Build a table of the thermo packages constituent parts
100  DynamicList<wordList> validThermoTypeNameCmpts;
101 
102  // Set row zero to the column headers
103  validThermoTypeNameCmpts.append(wordList(nCmpt));
104  forAll(validThermoTypeNameCmpts[0], i)
105  {
106  validThermoTypeNameCmpts[0][i] = cmptNames[i];
107  }
108 
109  // Split the thermo package names into their constituent parts and
110  // add them to the table, removing any incompatible entries from the
111  // list
112  forAll(validThermoTypeNames, i)
113  {
114  const wordList names
115  (
116  Thermo::splitThermoName(validThermoTypeNames[i], nCmpt)
117  );
118 
119  if (names.size())
120  {
121  validThermoTypeNameCmpts.append(names);
122  }
123  }
124 
125  // Print the table of available packages
126  printTable(validThermoTypeNameCmpts, FatalError);
127 
129  }
130  }
131 
132  return cstrIter;
133 }
134 
135 
136 template<class Thermo, class Table>
137 typename Table::iterator Foam::basicThermo::lookupCstrIter
138 (
139  const dictionary& thermoDict,
140  Table* tablePtr
141 )
142 {
143  if (thermoDict.isDict("thermoType"))
144  {
145  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
146 
147  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
148 
149  if (thermoTypeDict.found("properties"))
150  {
151  const int nCmpt = 4;
152  const char* cmptNames[nCmpt] =
153  {
154  "type",
155  "mixture",
156  "properties",
157  "energy"
158  };
159 
160  // Construct the name of the thermo package from the components
161  const word thermoTypeName
162  (
163  word(thermoTypeDict.lookup("type")) + '<'
164  + word(thermoTypeDict.lookup("mixture")) + '<'
165  + word(thermoTypeDict.lookup("properties")) + ','
166  + word(thermoTypeDict.lookup("energy")) + ">>"
167  );
168 
169  return lookupCstrIter<Thermo, Table>
170  (
171  thermoTypeDict,
172  tablePtr,
173  nCmpt,
174  cmptNames,
175  thermoTypeName
176  );
177  }
178  else
179  {
180  const int nCmpt = 7;
181  const char* cmptNames[nCmpt] =
182  {
183  "type",
184  "mixture",
185  "transport",
186  "thermo",
187  "equationOfState",
188  "specie",
189  "energy"
190  };
191 
192  // Construct the name of the thermo package from the components
193  const word thermoTypeName
194  (
195  word(thermoTypeDict.lookup("type")) + '<'
196  + word(thermoTypeDict.lookup("mixture")) + '<'
197  + word(thermoTypeDict.lookup("transport")) + '<'
198  + word(thermoTypeDict.lookup("thermo")) + '<'
199  + word(thermoTypeDict.lookup("equationOfState")) + '<'
200  + word(thermoTypeDict.lookup("specie")) + ">>,"
201  + word(thermoTypeDict.lookup("energy")) + ">>>"
202  );
203 
204  return lookupCstrIter<Thermo, Table>
205  (
206  thermoTypeDict,
207  tablePtr,
208  nCmpt,
209  cmptNames,
210  thermoTypeName
211  );
212  }
213  }
214  else
215  {
216  const word thermoTypeName(thermoDict.lookup("thermoType"));
217 
218  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
219 
220  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
221 
222  if (cstrIter == tablePtr->end())
223  {
225  << "Unknown " << Thermo::typeName << " type "
226  << thermoTypeName << nl << nl
227  << "Valid " << Thermo::typeName << " types are:" << nl
228  << tablePtr->sortedToc() << nl
229  << exit(FatalError);
230  }
231 
232  return cstrIter;
233  }
234 }
235 
236 
237 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
238 
239 template<class Thermo>
241 (
242  const fvMesh& mesh,
243  const word& phaseName
244 )
245 {
246  const IOdictionary thermoDict
247  (
248  physicalProperties::findModelDict(mesh, phaseName)
249  );
250 
251  typename Thermo::fvMeshConstructorTable::iterator cstrIter =
252  lookupCstrIter<Thermo, typename Thermo::fvMeshConstructorTable>
253  (
254  thermoDict,
255  Thermo::fvMeshConstructorTablePtr_
256  );
257 
258  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
259 }
260 
261 
262 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:663
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
fluidReactionThermo & thermo
Definition: createFields.H:28
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
fvMesh & mesh
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:956
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:1002
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A class for handling words, derived from string.
Definition: word.H:59
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
static const char nl
Definition: Ostream.H:260
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
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.
List< word > wordList
A List of words.
Definition: fileName.H:54
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864