combustionModelTemplates.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) 2011-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 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
27 
28 template<class CombustionModel>
30 (
31  typename CombustionModel::reactionThermo& thermo,
32  const compressibleTurbulenceModel& turb,
33  const word& combustionProperties
34 )
35 {
36  IOobject combIO
37  (
38  IOobject
39  (
40  thermo.phasePropertyName(combustionProperties),
41  thermo.db().time().constant(),
42  thermo.db(),
43  IOobject::MUST_READ,
44  IOobject::NO_WRITE,
45  false
46  )
47  );
48 
49  word combModelName("none");
50  if (combIO.typeHeaderOk<IOdictionary>(false))
51  {
52  IOdictionary(combIO).lookup("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  combModelName + '<' + CombustionModel::reactionThermo::typeName + '>';
81 
82  const word thermoCombModelName =
83  combModelName + '<' + CombustionModel::reactionThermo::typeName + ','
84  + thermo.thermoName() + '>';
85 
86  typename cstrTableType::iterator compCstrIter =
87  cstrTable->find(compCombModelName);
88 
89  typename cstrTableType::iterator thermoCstrIter =
90  cstrTable->find(thermoCombModelName);
91 
92  if (compCstrIter == cstrTable->end() && thermoCstrIter == cstrTable->end())
93  {
95  << "Unknown " << combustionModel::typeName << " type "
96  << combModelName << endl << endl;
97 
98  const wordList names(cstrTable->toc());
99 
100  wordList thisCmpts;
101  thisCmpts.append(word::null);
102  thisCmpts.append(CombustionModel::reactionThermo::typeName);
103  thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5));
104 
105  wordList validNames;
106  forAll(names, i)
107  {
108  wordList cmpts(basicThermo::splitThermoName(names[i], 2));
109  if (cmpts.size() != 2)
110  {
111  cmpts = basicThermo::splitThermoName(names[i], 7);
112  }
113 
114  bool isValid = true;
115  for (label i = 1; i < cmpts.size() && isValid; ++ i)
116  {
117  isValid = isValid && cmpts[i] == thisCmpts[i];
118  }
119 
120  if (isValid)
121  {
122  validNames.append(cmpts[0]);
123  }
124  }
125 
127  << "Valid " << combustionModel::typeName << " types for this "
128  << "thermodynamic model are:" << endl << validNames << endl;
129 
130  List<wordList> validCmpts2, validCmpts7;
131  validCmpts2.append(wordList(2, word::null));
132  validCmpts2[0][0] = combustionModel::typeName;
133  validCmpts2[0][1] = "reactionThermo";
134  validCmpts7.append(wordList(7, word::null));
135  validCmpts7[0][0] = combustionModel::typeName;
136  validCmpts7[0][1] = "reactionThermo";
137  validCmpts7[0][2] = "transport";
138  validCmpts7[0][3] = "thermo";
139  validCmpts7[0][4] = "equationOfState";
140  validCmpts7[0][5] = "specie";
141  validCmpts7[0][6] = "energy";
142  forAll(names, i)
143  {
144  const wordList cmpts2(basicThermo::splitThermoName(names[i], 2));
145  const wordList cmpts7(basicThermo::splitThermoName(names[i], 7));
146  if (cmpts2.size() == 2)
147  {
148  validCmpts2.append(cmpts2);
149  }
150  if (cmpts7.size() == 7)
151  {
152  validCmpts7.append(cmpts7);
153  }
154  }
155 
157  << "All " << validCmpts2[0][0] << '/' << validCmpts2[0][1]
158  << " combinations are:" << endl << endl;
159  printTable(validCmpts2, FatalErrorInFunction);
160 
162 
164  << "All " << validCmpts7[0][0] << '/' << validCmpts7[0][1]
165  << "/thermoPhysics combinations are:" << endl << endl;
166  printTable(validCmpts7, FatalErrorInFunction);
167 
169  }
170 
172  (
173  thermoCstrIter != cstrTable->end()
174  ? thermoCstrIter()(combModelName, thermo, turb, combustionProperties)
175  : compCstrIter()(combModelName, thermo, turb, combustionProperties)
176  );
177 }
178 
179 
180 // ************************************************************************* //
#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
bool typeHeaderOk(const bool checkType=true)
Read header (uses typeFilePath to find file) and check header.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#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
rhoReactionThermo & thermo
Definition: createFields.H:28
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
ReactionThermo reactionThermo
Thermo type.
A class for handling words, derived from string.
Definition: word.H:59
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
Abstract base class for turbulence models (RAS, LES and laminar).
List< word > wordList
A List of words.
Definition: fileName.H:54
#define WarningInFunction
Report a warning using Foam::Warning.
static autoPtr< CombustionModel > New(typename CombustionModel::reactionThermo &thermo, const compressibleTurbulenceModel &turb, const word &combustionProperties)
Generic New for each of the related chemistry model.
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