combustionModelTemplates.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 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 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
30 
31 template<class CombustionModel>
33 (
36  const word& combustionProperties
37 )
38 {
39  IOobject combIO
40  (
41  thermo.phasePropertyName(combustionProperties),
42  thermo.db().time().constant(),
43  thermo.db(),
44  IOobject::MUST_READ,
45  IOobject::NO_WRITE,
46  false
47  );
48 
49  word combModelName("none");
50  if (combIO.typeHeaderOk<IOdictionary>(false))
51  {
52  IOdictionary(combIO).readEntry("combustionModel", combModelName);
53  }
54  else
55  {
56  Info<< "Combustion model not active: "
57  << thermo.phasePropertyName(combustionProperties)
58  << " not found" << endl;
59  }
60 
61  Info<< "Selecting combustion model " << combModelName << endl;
62 
63  const wordList cmpts2(basicThermo::splitThermoName(combModelName, 2));
64  const wordList cmpts3(basicThermo::splitThermoName(combModelName, 3));
65  if (cmpts2.size() == 2 || cmpts3.size() == 3)
66  {
67  combModelName = cmpts2.size() ? cmpts2[0] : cmpts3[0];
68 
70  << "Template parameters are no longer required when selecting a "
71  << combustionModel::typeName << ". This information is now "
72  << "obtained directly from the thermodynamics. Actually selecting "
73  << "combustion model " << combModelName << "." << endl;
74  }
75 
76  typedef typename CombustionModel::dictionaryConstructorTable cstrTableType;
77  cstrTableType* cstrTable = CombustionModel::dictionaryConstructorTablePtr_;
78 
79  const word compCombModelName
80  (
81  combModelName + '<' + CombustionModel::reactionThermo::typeName + '>'
82  );
83 
84  const word thermoCombModelName
85  (
86  combModelName + '<' + CombustionModel::reactionThermo::typeName + ','
87  + thermo.thermoName() + '>'
88  );
89 
90  auto compCstrIter = cstrTable->cfind(compCombModelName);
91 
92  auto thermoCstrIter = cstrTable->cfind(thermoCombModelName);
93 
94  if (!compCstrIter.found() && !thermoCstrIter.found())
95  {
96  wordList thisCmpts;
97  thisCmpts.append(word::null);
98  thisCmpts.append(CombustionModel::reactionThermo::typeName);
99  thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5));
100 
101  wordList validNames;
102 
103  List<wordList> validCmpts2;
104  validCmpts2.append
105  (
106  // Header
107  wordList
108  ({
109  word::null,
110  combustionModel::typeName,
111  "reactionThermo"
112  })
113  );
114 
115  List<wordList> validCmpts7;
116  validCmpts7.append
117  (
118  // Header
119  wordList
120  ({
121  word::null,
122  combustionModel::typeName,
123  "reactionThermo",
124  "transport",
125  "thermo",
126  "equationOfState",
127  "specie",
128  "energy"
129  })
130  );
131 
132  for (const word& validName : cstrTable->sortedToc())
133  {
134  wordList cmpts(basicThermo::splitThermoName(validName, 2));
135 
136  if (cmpts.size() == 2)
137  {
138  validCmpts2.append(cmpts);
139  }
140  else
141  {
142  cmpts = basicThermo::splitThermoName(validName, 7);
143  if (cmpts.size() == 7)
144  {
145  validCmpts7.append(cmpts);
146  }
147  }
148 
149  bool isValid = true;
150  for (label i = 1; i < cmpts.size() && isValid; ++i)
151  {
152  isValid = isValid && cmpts[i] == thisCmpts[i];
153  }
154 
155  if (isValid)
156  {
157  validNames.append(cmpts[0]);
158  }
159  }
160 
161 
163  (
164  combustionModel::typeName,
165  combModelName,
166  *cstrTable
167  )
168  << "All " << validCmpts2[0][0] << '/' << validCmpts2[0][1]
169  << " combinations are:" << nl << nl;
170 
171  printTable(validCmpts2, FatalErrorInFunction)
172  << nl;
173 
175  << "All " << validCmpts7[0][0] << '/' << validCmpts7[0][1]
176  << "/thermoPhysics combinations are:" << nl << nl;
177 
178  printTable(validCmpts7, FatalErrorInFunction)
179  << exit(FatalError);
180  }
181 
183  (
184  thermoCstrIter.found()
185  ? thermoCstrIter()(combModelName, thermo, turb, combustionProperties)
186  : compCstrIter()(combModelName, thermo, turb, combustionProperties)
187  );
188 }
189 
190 
191 // ************************************************************************* //
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
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::CombustionModel::reactionThermo
ReactionThermo reactionThermo
Thermo type.
Definition: CombustionModel.H:71
thermo
psiReactionThermo & thermo
Definition: createFields.H:28
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
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::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::FatalError
error FatalError
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:385
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
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::combustionModel::New
static autoPtr< CombustionModel > New(typename CombustionModel::reactionThermo &thermo, const compressibleTurbulenceModel &turb, const word &combustionProperties)
Generic New for each of the related chemistry model.
Foam::List< word >
turb
compressible::turbulenceModel & turb
Definition: setRegionFluidFields.H:10
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::compressibleTurbulenceModel
Abstract base class for turbulence models (RAS, LES and laminar).
Definition: compressibleTurbulenceModel.H:54