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-2022 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  (
59  && !dynamicCode::resolveTemplate(Thermo::typeName).empty()
60  )
61  {
63  (
64  Thermo::typeName,
65  thermoTypeName,
67  {
68  {"type", thermoTypeDict.lookup("type")},
69  {"mixture", mixtureName(thermoTypeDict)},
70  {"transport", thermoTypeDict.lookup("transport")},
71  {"thermo", thermoTypeDict.lookup("thermo")},
72  {
73  "equationOfState",
74  thermoTypeDict.lookup("equationOfState")
75  },
76  {"specie", thermoTypeDict.lookup("specie")},
77  {"energy", thermoTypeDict.lookup("energy")}
78  }
79  );
80  cstrIter = tablePtr->find(thermoTypeName);
81 
82  if (cstrIter == tablePtr->end())
83  {
85  << "Compilation and linkage of "
86  << Thermo::typeName << " type " << nl
87  << "thermoType" << thermoTypeDict << nl << nl
88  << "failed." << nl << nl
89  << "Valid " << Thermo::typeName << " types are:"
90  << nl << nl;
91  }
92  }
93  else
94  {
95  // Print error message if package not found in the table
97  << "Unknown " << Thermo::typeName << " type " << nl
98  << "thermoType" << thermoTypeDict << nl << nl
99  << "Valid " << Thermo::typeName << " types are:"
100  << nl << nl;
101  }
102 
103  if (cstrIter == tablePtr->end())
104  {
105  // Get the list of all the suitable thermo packages available
106  wordList validThermoTypeNames(tablePtr->sortedToc());
107 
108  // Build a table of the thermo packages constituent parts
109  DynamicList<wordList> validThermoTypeNameCmpts;
110 
111  // Set row zero to the column headers
112  validThermoTypeNameCmpts.append(wordList(nCmpt));
113  forAll(validThermoTypeNameCmpts[0], i)
114  {
115  validThermoTypeNameCmpts[0][i] = cmptNames[i];
116  }
117 
118  // Split the thermo package names into their constituent parts and
119  // add them to the table, removing any incompatible entries from the
120  // list
121  forAll(validThermoTypeNames, i)
122  {
123  const wordList names
124  (
125  Thermo::splitThermoName(validThermoTypeNames[i], nCmpt)
126  );
127 
128  if (names.size())
129  {
130  validThermoTypeNameCmpts.append(names);
131  }
132  }
133 
134  // Print the table of available packages
135  printTable(validThermoTypeNameCmpts, FatalError);
136 
138  }
139  }
140 
141  return cstrIter;
142 }
143 
144 
145 template<class Thermo, class Table>
146 typename Table::iterator Foam::basicThermo::lookupCstrIter
147 (
148  const dictionary& thermoDict,
149  Table* tablePtr
150 )
151 {
152  if (thermoDict.isDict("thermoType"))
153  {
154  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
155 
156  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
157 
158  if (thermoTypeDict.found("properties"))
159  {
160  const int nCmpt = 4;
161  const char* cmptNames[nCmpt] =
162  {
163  "type",
164  "mixture",
165  "properties",
166  "energy"
167  };
168 
169  // Construct the name of the thermo package from the components
170  const word thermoTypeName
171  (
172  word(thermoTypeDict.lookup("type")) + '<'
173  + word(mixtureName(thermoTypeDict)) + '<'
174  + word(thermoTypeDict.lookup("properties")) + ','
175  + word(thermoTypeDict.lookup("energy")) + ">>"
176  );
177 
178  return lookupCstrIter<Thermo, Table>
179  (
180  thermoTypeDict,
181  tablePtr,
182  nCmpt,
183  cmptNames,
184  thermoTypeName
185  );
186  }
187  else
188  {
189  const int nCmpt = 7;
190  const char* cmptNames[nCmpt] =
191  {
192  "type",
193  "mixture",
194  "transport",
195  "thermo",
196  "equationOfState",
197  "specie",
198  "energy"
199  };
200 
201  // Construct the name of the thermo package from the components
202  const word thermoTypeName
203  (
204  word(thermoTypeDict.lookup("type")) + '<'
205  + word(mixtureName(thermoTypeDict)) + '<'
206  + word(thermoTypeDict.lookup("transport")) + '<'
207  + word(thermoTypeDict.lookup("thermo")) + '<'
208  + word(thermoTypeDict.lookup("equationOfState")) + '<'
209  + word(thermoTypeDict.lookup("specie")) + ">>,"
210  + word(thermoTypeDict.lookup("energy")) + ">>>"
211  );
212 
213  return lookupCstrIter<Thermo, Table>
214  (
215  thermoTypeDict,
216  tablePtr,
217  nCmpt,
218  cmptNames,
219  thermoTypeName
220  );
221  }
222  }
223  else
224  {
225  const word thermoTypeName(thermoDict.lookup("thermoType"));
226 
227  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
228 
229  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
230 
231  if (cstrIter == tablePtr->end())
232  {
234  << "Unknown " << Thermo::typeName << " type "
235  << thermoTypeName << nl << nl
236  << "Valid " << Thermo::typeName << " types are:" << nl
237  << tablePtr->sortedToc() << nl
238  << exit(FatalError);
239  }
240 
241  return cstrIter;
242  }
243 }
244 
245 
246 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
247 
248 template<class Thermo>
250 (
251  const fvMesh& mesh,
252  const word& phaseName
253 )
254 {
255  const IOdictionary thermoDict
256  (
257  physicalProperties::findModelDict(mesh, phaseName)
258  );
259 
260  typename Thermo::fvMeshConstructorTable::iterator cstrIter =
261  lookupCstrIter<Thermo, typename Thermo::fvMeshConstructorTable>
262  (
263  thermoDict,
264  Thermo::fvMeshConstructorTablePtr_
265  );
266 
267  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
268 }
269 
270 
271 // ************************************************************************* //
#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
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
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:160
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:952
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:998
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:659
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:101
static IOobject findModelDict(const objectRegistry &obr, const word &group, bool registerObject=false)
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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:251
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:260
fluidMulticomponentThermo & thermo
Definition: createFields.H:31