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-2018 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 
28 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
29 
30 template<class Thermo, class Table>
31 typename Table::iterator Foam::basicThermo::lookupThermo
32 (
33  const dictionary& thermoTypeDict,
34  Table* tablePtr,
35  const int nCmpt,
36  const char* cmptNames[],
37  const word& thermoTypeName
38 )
39 {
40  // Lookup the thermo package
41  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
42 
43  // Print error message if package not found in the table
44  if (cstrIter == tablePtr->end())
45  {
47  << "Unknown " << Thermo::typeName << " type " << nl
48  << "thermoType" << thermoTypeDict << nl << nl
49  << "Valid " << Thermo::typeName << " types are:"
50  << nl << nl;
51 
52  // Get the list of all the suitable thermo packages available
53  wordList validThermoTypeNames
54  (
55  tablePtr->sortedToc()
56  );
57 
58  // Build a table of the thermo packages constituent parts
59  // Note: row-0 contains the names of constituent parts
60  List<wordList> validThermoTypeNameCmpts
61  (
62  validThermoTypeNames.size() + 1
63  );
64 
65  validThermoTypeNameCmpts[0].setSize(nCmpt);
66  forAll(validThermoTypeNameCmpts[0], j)
67  {
68  validThermoTypeNameCmpts[0][j] = cmptNames[j];
69  }
70 
71  // Split the thermo package names into their constituent parts
72  // Removing incompatible entries from the list
73  label j = 0;
74  forAll(validThermoTypeNames, i)
75  {
76  wordList names
77  (
78  Thermo::splitThermoName(validThermoTypeNames[i], nCmpt)
79  );
80 
81  if (names.size())
82  {
83  validThermoTypeNameCmpts[j++] = names;
84  }
85  }
86  validThermoTypeNameCmpts.setSize(j);
87 
88  // Print the table of available packages
89  // in terms of their constituent parts
90  printTable(validThermoTypeNameCmpts, FatalError);
91 
93  }
94 
95  return cstrIter;
96 }
97 
98 
99 template<class Thermo, class Table>
100 typename Table::iterator Foam::basicThermo::lookupThermo
101 (
102  const dictionary& thermoDict,
103  Table* tablePtr
104 )
105 {
106  if (thermoDict.isDict("thermoType"))
107  {
108  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
109 
110  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
111 
112  if (thermoTypeDict.found("properties"))
113  {
114  const int nCmpt = 4;
115  const char* cmptNames[nCmpt] =
116  {
117  "type",
118  "mixture",
119  "properties",
120  "energy"
121  };
122 
123  // Construct the name of the thermo package from the components
124  const word thermoTypeName
125  (
126  word(thermoTypeDict.lookup("type")) + '<'
127  + word(thermoTypeDict.lookup("mixture")) + '<'
128  + word(thermoTypeDict.lookup("properties")) + ','
129  + word(thermoTypeDict.lookup("energy")) + ">>"
130  );
131 
132  return lookupThermo<Thermo, Table>
133  (
134  thermoTypeDict,
135  tablePtr,
136  nCmpt,
137  cmptNames,
138  thermoTypeName
139  );
140  }
141  else
142  {
143  const int nCmpt = 7;
144  const char* cmptNames[nCmpt] =
145  {
146  "type",
147  "mixture",
148  "transport",
149  "thermo",
150  "equationOfState",
151  "specie",
152  "energy"
153  };
154 
155  // Construct the name of the thermo package from the components
156  const word thermoTypeName
157  (
158  word(thermoTypeDict.lookup("type")) + '<'
159  + word(thermoTypeDict.lookup("mixture")) + '<'
160  + word(thermoTypeDict.lookup("transport")) + '<'
161  + word(thermoTypeDict.lookup("thermo")) + '<'
162  + word(thermoTypeDict.lookup("equationOfState")) + '<'
163  + word(thermoTypeDict.lookup("specie")) + ">>,"
164  + word(thermoTypeDict.lookup("energy")) + ">>>"
165  );
166 
167  return lookupThermo<Thermo, Table>
168  (
169  thermoTypeDict,
170  tablePtr,
171  nCmpt,
172  cmptNames,
173  thermoTypeName
174  );
175  }
176  }
177  else
178  {
179  const word thermoTypeName(thermoDict.lookup("thermoType"));
180 
181  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
182 
183  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
184 
185  if (cstrIter == tablePtr->end())
186  {
188  << "Unknown " << Thermo::typeName << " type "
189  << thermoTypeName << nl << nl
190  << "Valid " << Thermo::typeName << " types are:" << nl
191  << tablePtr->sortedToc() << nl
192  << exit(FatalError);
193  }
194 
195  return cstrIter;
196  }
197 }
198 
199 
200 template<class Thermo>
202 (
203  const fvMesh& mesh,
204  const word& phaseName
205 )
206 {
207  IOdictionary thermoDict
208  (
209  IOobject
210  (
211  phasePropertyName(dictName, phaseName),
212  mesh.time().constant(),
213  mesh,
214  IOobject::MUST_READ_IF_MODIFIED,
215  IOobject::NO_WRITE,
216  false
217  )
218  );
219 
220  typename Thermo::fvMeshConstructorTable::iterator cstrIter =
221  lookupThermo<Thermo, typename Thermo::fvMeshConstructorTable>
222  (
223  thermoDict,
224  Thermo::fvMeshConstructorTablePtr_
225  );
226 
227  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
228 }
229 
230 
231 template<class Thermo>
233 (
234  const fvMesh& mesh,
235  const dictionary& dict,
236  const word& phaseName
237 )
238 {
239  typename Thermo::dictionaryConstructorTable::iterator cstrIter =
240  lookupThermo<Thermo, typename Thermo::dictionaryConstructorTable>
241  (
242  dict,
243  Thermo::dictionaryConstructorTablePtr_
244  );
245 
246  return autoPtr<Thermo>(cstrIter()(mesh, dict, phaseName));
247 }
248 
249 
250 // ************************************************************************* //
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
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:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
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:646
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:692
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
const word dictName("particleTrackDict")
static const char nl
Definition: Ostream.H:265
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
static Table::iterator lookupThermo(const dictionary &thermoTypeDict, Table *tablePtr, const int nCmpt, const char *cmptNames[], const word &thermoTypeName)
Generic lookup for thermodynamics package thermoTypeName.
void setSize(const label)
Reset size of List.
Definition: List.C:281
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576