basicThermoTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "basicThermo.H"
30 
31 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
32 
33 template<class Thermo, class Table>
34 typename Table::iterator Foam::basicThermo::lookupThermo
35 (
36  const dictionary& thermoTypeDict,
37  Table* tablePtr,
38  std::initializer_list<const char*> cmptNames,
39  const word& thermoTypeName
40 )
41 {
42  // Lookup the thermo package
43 
44  // Table iterator, not const_iterator
45  auto cstrIter = tablePtr->find(thermoTypeName);
46 
47  // Print error message if package not found in the table
48  if (!cstrIter.found())
49  {
50  const int nCmpt = cmptNames.size();
51 
52  // Build a table of the thermo packages constituent parts
53  // Note: row-0 contains the names of constituent parts
54  List<wordList> validCmpts(tablePtr->size()+1);
55 
56  // Header (row 0)
57  validCmpts[0].resize(nCmpt);
58  std::copy(cmptNames.begin(), cmptNames.end(), validCmpts[0].begin());
59 
60  // Split the thermo package names into their constituent parts
61  // Removing incompatible entries from the list
62  label rowi = 1;
63  for (const word& validName : tablePtr->sortedToc())
64  {
65  validCmpts[rowi] = Thermo::splitThermoName(validName, nCmpt);
66 
67  if (validCmpts[rowi].size())
68  {
69  ++rowi;
70  }
71  }
72  validCmpts.resize(rowi);
73 
74 
76  (
77  thermoTypeDict,
78  Thermo::typeName,
79  word::null, // Suppress long name? Just output dictionary (above)
80  *tablePtr
81  );
82 
83  // Table of available packages (as constituent parts)
84  printTable(validCmpts, FatalIOError)
85  << exit(FatalIOError);
86  }
87 
88  return cstrIter;
89 }
90 
91 
92 template<class Thermo, class Table>
93 typename Table::iterator Foam::basicThermo::lookupThermo
94 (
95  const dictionary& thermoDict,
96  Table* tablePtr
97 )
98 {
99  if (thermoDict.isDict("thermoType"))
100  {
101  const dictionary& thermoTypeDict = thermoDict.subDict("thermoType");
102 
103  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
104 
105  if (thermoTypeDict.found("properties"))
106  {
107  std::initializer_list<const char*> cmptNames
108  {
109  "type",
110  "mixture",
111  "properties",
112  "energy"
113  };
114 
115  // Construct the name of the thermo package from the components
116  const word thermoTypeName
117  (
118  thermoTypeDict.get<word>("type") + '<'
119  + thermoTypeDict.get<word>("mixture") + '<'
120  + thermoTypeDict.get<word>("properties") + ','
121  + thermoTypeDict.get<word>("energy") + ">>"
122  );
123 
124  return lookupThermo<Thermo, Table>
125  (
126  thermoTypeDict,
127  tablePtr,
128  cmptNames,
129  thermoTypeName
130  );
131  }
132  else
133  {
134  std::initializer_list<const char*> cmptNames
135  {
136  "type",
137  "mixture",
138  "transport",
139  "thermo",
140  "equationOfState",
141  "specie",
142  "energy"
143  };
144 
145  // Construct the name of the thermo package from the components
146  const word thermoTypeName
147  (
148  thermoTypeDict.get<word>("type") + '<'
149  + thermoTypeDict.get<word>("mixture") + '<'
150  + thermoTypeDict.get<word>("transport") + '<'
151  + thermoTypeDict.get<word>("thermo") + '<'
152  + thermoTypeDict.get<word>("equationOfState") + '<'
153  + thermoTypeDict.get<word>("specie") + ">>,"
154  + thermoTypeDict.get<word>("energy") + ">>>"
155  );
156 
157  return lookupThermo<Thermo, Table>
158  (
159  thermoTypeDict,
160  tablePtr,
161  cmptNames,
162  thermoTypeName
163  );
164  }
165  }
166  else
167  {
168  const word thermoTypeName(thermoDict.get<word>("thermoType"));
169 
170  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
171 
172  // Table iterator, not const_iterator
173  auto cstrIter = tablePtr->find(thermoTypeName);
174 
175  if (!cstrIter.found())
176  {
178  (
179  thermoDict,
180  Thermo::typeName,
181  thermoTypeName,
182  *tablePtr
183  ) << exit(FatalIOError);
184  }
185 
186  return cstrIter;
187  }
188 }
189 
190 
191 template<class Thermo>
193 (
194  const fvMesh& mesh,
195  const word& phaseName
196 )
197 {
199  (
200  IOobject
201  (
202  phasePropertyName(dictName, phaseName),
203  mesh.time().constant(),
204  mesh,
205  IOobject::MUST_READ_IF_MODIFIED,
206  IOobject::NO_WRITE,
207  false
208  )
209  );
210 
211  auto cstrIter =
212  lookupThermo<Thermo, typename Thermo::fvMeshConstructorTable>
213  (
214  thermoDict,
215  Thermo::fvMeshConstructorTablePtr_
216  );
217 
218  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
219 }
220 
221 
222 template<class Thermo>
224 (
225  const fvMesh& mesh,
226  const dictionary& dict,
227  const word& phaseName
228 )
229 {
230  auto cstrIter =
231  lookupThermo<Thermo, typename Thermo::dictionaryConstructorTable>
232  (
233  dict,
234  Thermo::dictionaryConstructorTablePtr_
235  );
236 
237  return autoPtr<Thermo>(cstrIter()(mesh, dict, phaseName));
238 }
239 
240 
241 template<class Thermo>
243 (
244  const fvMesh& mesh,
245  const word& phaseName,
246  const word& dictName
247 )
248 {
250  (
251  IOobject
252  (
253  dictName,
254  mesh.time().constant(),
255  mesh,
256  IOobject::MUST_READ_IF_MODIFIED,
257  IOobject::NO_WRITE,
258  false
259  )
260  );
261 
262  auto cstrIter =
263  lookupThermo<Thermo, typename Thermo::fvMeshDictPhaseConstructorTable>
264  (
265  thermoDict,
266  Thermo::fvMeshDictPhaseConstructorTablePtr_
267  );
268 
269  return autoPtr<Thermo>(cstrIter()(mesh, phaseName, dictName));
270 }
271 
272 
273 
274 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
basicThermo.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:364
dictName
const word dictName("blockMeshDict")
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:406
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::printTable
Ostream & printTable(const UList< wordList > &tbl, List< std::string::size_type > &columnWidths, Ostream &os, bool headerSeparator=true)
Print a List of wordList as a table.
Definition: wordIOList.C:47
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::basicThermo::New
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
thermoDict
const dictionary & thermoDict
Definition: EEqn.H:16
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::basicThermo::lookupThermo
static Table::iterator lookupThermo(const dictionary &thermoTypeDict, Table *tablePtr, std::initializer_list< const char * > cmptNames, const word &thermoTypeName)
Generic lookup for thermodynamics package thermoTypeName.
Definition: basicThermoTemplates.C:35