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 | Copyright (C) 2012-2015 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& thermoDict,
34  Table* tablePtr
35 )
36 {
37  word thermoTypeName;
38 
39  if (thermoDict.isDict("thermoType"))
40  {
41  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
42 
43  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
44 
45  const int nCmpt = 7;
46  const char* cmptNames[nCmpt] =
47  {
48  "type",
49  "mixture",
50  "transport",
51  "thermo",
52  "equationOfState",
53  "specie",
54  "energy"
55  };
56 
57  // Construct the name of the thermo package from the components
58  thermoTypeName =
59  word(thermoTypeDict.lookup("type")) + '<'
60  + word(thermoTypeDict.lookup("mixture")) + '<'
61  + word(thermoTypeDict.lookup("transport")) + '<'
62  + word(thermoTypeDict.lookup("thermo")) + '<'
63  + word(thermoTypeDict.lookup("equationOfState")) + '<'
64  + word(thermoTypeDict.lookup("specie")) + ">>,"
65  + word(thermoTypeDict.lookup("energy")) + ">>>";
66 
67  // Lookup the thermo package
68  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
69 
70  // Print error message if package not found in the table
71  if (cstrIter == tablePtr->end())
72  {
74  << "Unknown " << Thermo::typeName << " type " << nl
75  << "thermoType" << thermoTypeDict << nl << nl
76  << "Valid " << Thermo::typeName << " types are:" << nl << nl;
77 
78  // Get the list of all the suitable thermo packages available
79  wordList validThermoTypeNames
80  (
81  tablePtr->sortedToc()
82  );
83 
84  // Build a table of the thermo packages constituent parts
85  // Note: row-0 contains the names of constituent parts
86  List<wordList> validThermoTypeNameCmpts
87  (
88  validThermoTypeNames.size() + 1
89  );
90 
91  validThermoTypeNameCmpts[0].setSize(nCmpt);
92  forAll(validThermoTypeNameCmpts[0], j)
93  {
94  validThermoTypeNameCmpts[0][j] = cmptNames[j];
95  }
96 
97  // Split the thermo package names into their constituent parts
98  forAll(validThermoTypeNames, i)
99  {
100  validThermoTypeNameCmpts[i+1] =
101  Thermo::splitThermoName(validThermoTypeNames[i], nCmpt);
102  }
103 
104  // Print the table of available packages
105  // in terms of their constituent parts
106  printTable(validThermoTypeNameCmpts, FatalError);
107 
109  }
110 
111  return cstrIter;
112  }
113  else
114  {
115  thermoTypeName = word(thermoDict.lookup("thermoType"));
116 
117  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
118 
119  typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
120 
121  if (cstrIter == tablePtr->end())
122  {
124  << "Unknown " << Thermo::typeName << " type "
125  << thermoTypeName << nl << nl
126  << "Valid " << Thermo::typeName << " types are:" << nl
127  << tablePtr->sortedToc() << nl
128  << exit(FatalError);
129  }
130 
131  return cstrIter;
132  }
133 }
134 
135 
136 template<class Thermo>
138 (
139  const fvMesh& mesh,
140  const word& phaseName
141 )
142 {
143  IOdictionary thermoDict
144  (
145  IOobject
146  (
147  phasePropertyName(dictName, phaseName),
148  mesh.time().constant(),
149  mesh,
150  IOobject::MUST_READ_IF_MODIFIED,
151  IOobject::NO_WRITE,
152  false
153  )
154  );
155 
156  typename Thermo::fvMeshConstructorTable::iterator cstrIter =
157  lookupThermo<Thermo, typename Thermo::fvMeshConstructorTable>
158  (
159  thermoDict,
160  Thermo::fvMeshConstructorTablePtr_
161  );
162 
163  return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
164 }
165 
166 
167 template<class Thermo>
169 (
170  const fvMesh& mesh,
171  const dictionary& dict,
172  const word& phaseName
173 )
174 {
175  typename Thermo::dictionaryConstructorTable::iterator cstrIter =
176  lookupThermo<Thermo, typename Thermo::dictionaryConstructorTable>
177  (
178  dict,
179  Thermo::dictionaryConstructorTablePtr_
180  );
181 
182  return autoPtr<Thermo>(cstrIter()(mesh, dict, phaseName));
183 }
184 
185 
186 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:602
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
static Table::iterator lookupThermo(const dictionary &thermoDict, Table *tablePtr)
Generic lookup for each of the related thermodynamics packages.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
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
static const char nl
Definition: Ostream.H:262
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
void setSize(const label)
Reset size of List.
Definition: List.C:295
word dictName("noiseDict")
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:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451