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-2021 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class Thermo, class ThermoConstructTable>
34 typename ThermoConstructTable::mapped_type
35 Foam::basicThermo::getThermoOrDie
36 (
37  const dictionary& thermoTypeDict,
38  ThermoConstructTable& thermoTable,
39  const word& thermoTypeName,
40  const wordList& cmptNames
41 )
42 {
43  // Lookup the thermo package
44 
45  auto ctorIter = thermoTable.cfind(thermoTypeName);
46 
47  // Print error message if package not found in the table
48  if (!ctorIter.found())
49  {
51  (
52  thermoTypeDict,
53  Thermo::typeName,
54  word::null, // Suppress long name? Just output dictionary (above)
55  thermoTable
56  );
57 
59  (
61  cmptNames,
62  thermoTable.sortedToc()
63  ) << exit(FatalIOError);
64 
65  // return nullptr;
66  }
67 
68  return ctorIter.val();
69 }
70 
71 
72 template<class Thermo, class ThermoConstructTable>
73 typename ThermoConstructTable::mapped_type
74 Foam::basicThermo::getThermoOrDie
75 (
76  const dictionary& thermoDict,
77  ThermoConstructTable& thermoTable
78 )
79 {
80  const dictionary* dictptr = thermoDict.findDict("thermoType");
81 
82  if (dictptr)
83  {
84  const auto& thermoTypeDict = *dictptr;
85 
86  const wordList* cmptHeaderPtr = &(wordList::null());
87 
88  // Thermo package name, constructed from components
89  const word thermoTypeName
90  (
91  basicThermo::makeThermoName(thermoTypeDict, cmptHeaderPtr)
92  );
93 
94  Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
95 
96  return getThermoOrDie<Thermo, ThermoConstructTable>
97  (
98  thermoTypeDict,
99  thermoTable,
100  thermoTypeName,
101  *cmptHeaderPtr
102  );
103  }
104  else
105  {
106  const word thermoTypeName(thermoDict.get<word>("thermoType"));
107 
108  Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
109 
110  auto ctorIter = thermoTable.cfind(thermoTypeName);
111 
112  if (!ctorIter.found())
113  {
115  (
116  thermoDict,
117  Thermo::typeName,
118  thermoTypeName,
119  thermoTable
120  ) << exit(FatalIOError);
121  }
122 
123  return ctorIter.val();
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
129 
130 template<class Thermo>
132 (
133  const fvMesh& mesh,
134  const word& phaseName
135 )
136 {
138  (
139  IOobject
140  (
141  phasePropertyName(dictName, phaseName),
142  mesh.time().constant(),
143  mesh,
146  false
147  )
148  );
149 
150  auto* ctorPtr = getThermoOrDie<Thermo>
151  (
152  thermoDict,
153  *(Thermo::fvMeshConstructorTablePtr_)
154  );
155 
156  return autoPtr<Thermo>(ctorPtr(mesh, phaseName));
157 }
158 
159 
160 template<class Thermo>
162 (
163  const fvMesh& mesh,
164  const dictionary& dict,
165  const word& phaseName
166 )
167 {
168  auto* ctorPtr = getThermoOrDie<Thermo>
169  (
170  dict,
171  *(Thermo::dictionaryConstructorTablePtr_)
172  );
173 
174  return autoPtr<Thermo>(ctorPtr(mesh, dict, phaseName));
175 }
176 
177 
178 template<class Thermo>
180 (
181  const fvMesh& mesh,
182  const word& phaseName,
183  const word& dictName
184 )
185 {
187  (
188  IOobject
189  (
190  dictName,
191  mesh.time().constant(),
192  mesh,
195  false
196  )
197  );
198 
199  auto* ctorPtr = getThermoOrDie<Thermo>
200  (
201  thermoDict,
202  *(Thermo::fvMeshDictPhaseConstructorTablePtr_)
203  );
204 
205  return autoPtr<Thermo>(ctorPtr(mesh, phaseName, dictName));
206 }
207 
208 
209 // ************************************************************************* //
Foam::dictionary::findDict
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionaryI.H:127
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
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:169
basicThermo.H
Foam::List< word >::null
static const List< word > & null()
Return a null List.
Definition: ListI.H:109
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
dictName
const word dictName("faMeshDefinition")
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::basicThermo::printThermoNames
static Ostream & printThermoNames(Ostream &os, const wordList &cmptNames, const wordList &thermoNames)
Print (filtered) table of thermo names, splits on " ,<>".
Definition: basicThermo.C:75
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:123
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:85
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::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96