basicChemistryModelTemplates.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) 2019-2020 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 "basicChemistryModel.H"
30 #include "basicThermo.H"
31 
32 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
33 
34 template<class ChemistryModel>
36 (
37  typename ChemistryModel::reactionThermo& thermo
38 )
39 {
40  const IOdictionary chemistryDict
41  (
42  IOobject
43  (
44  thermo.phasePropertyName("chemistryProperties"),
45  thermo.db().time().constant(),
46  thermo.db(),
47  IOobject::MUST_READ,
48  IOobject::NO_WRITE,
49  false // Do not register
50  )
51  );
52 
53  if (!chemistryDict.isDict("chemistryType"))
54  {
56  << "Template parameter based chemistry solver selection is no "
57  << "longer supported. Please create a chemistryType dictionary"
58  << "instead." << endl << endl << "For example, the entry:" << endl
59  << " chemistrySolver ode<StandardChemistryModel<"
60  << "rhoChemistryModel,sutherlandspecie<janaf<perfectGas>,"
61  << "sensibleInternalEnergy>>" << endl << endl << "becomes:" << endl
62  << " chemistryType" << endl << " {" << endl
63  << " solver ode;" << endl << " method standard;"
64  << endl << " }" << exit(FatalError);
65  }
66 
67  const dictionary& chemistryTypeDict =
68  chemistryDict.subDict("chemistryType");
69 
70  const word solverName
71  (
72  chemistryTypeDict.getCompat<word>
73  (
74  "solver",
75  {{"chemistrySolver", -1712}}
76  )
77  );
78 
79  const word methodName
80  (
81  chemistryTypeDict.getOrDefault<word>
82  (
83  "method",
84  chemistryTypeDict.getOrDefault<bool>("TDAC", false)
85  ? "TDAC"
86  : "standard"
87  )
88  );
89 
90  dictionary chemistryTypeDictNew;
91  chemistryTypeDictNew.add("solver", solverName);
92  chemistryTypeDictNew.add("method", methodName);
93 
94  Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
95 
96  auto* cstrTable = ChemistryModel::thermoConstructorTablePtr_;
97 
98  const word chemSolverCompThermoName
99  (
100  solverName + '<' + methodName + '<'
101  + ChemistryModel::reactionThermo::typeName + ','
102  + thermo.thermoName() + ">>"
103  );
104 
105  auto cstrIter = cstrTable->cfind(chemSolverCompThermoName);
106 
107  if (!cstrIter.found())
108  {
109  constexpr const int nCmpt = 8;
110 
111  wordList thisCmpts;
112  thisCmpts.append(word::null);
113  thisCmpts.append(word::null);
114  thisCmpts.append(ChemistryModel::reactionThermo::typeName);
115  thisCmpts.append
116  (
117  basicThermo::splitThermoName(thermo.thermoName(), 5)
118  );
119 
120  List<wordList> validNames;
121 
122  validNames.append
123  (
124  // Header
125  wordList({"solver", "method"})
126  );
127 
128  List<wordList> validCmpts;
129  validCmpts.append
130  (
131  // Header
132  wordList
133  ({
134  "solver",
135  "method",
136  "reactionThermo",
137  "transport",
138  "thermo",
139  "equationOfState",
140  "specie",
141  "energy"
142  })
143  );
144 
145  for (const word& validName : cstrTable->sortedToc())
146  {
147  validCmpts.append
148  (
149  basicThermo::splitThermoName(validName, nCmpt)
150  );
151 
152  const wordList& cmpts = validCmpts.last();
153 
154  bool isValid = true;
155  for (label i = 2; i < cmpts.size() && isValid; ++i)
156  {
157  isValid = isValid && cmpts[i] == thisCmpts[i];
158  }
159 
160  if (isValid)
161  {
162  validNames.append(SubList<word>(cmpts, 2));
163  }
164  }
165 
166 
168  << "Unknown " << typeName_() << " type " << solverName << nl << nl;
169 
171  << "All " << validNames[0][0] << '/' << validNames[0][1]
172  << "combinations for this thermodynamic model:" << nl << nl;
173 
174  // Table of available packages (as constituent parts)
175  printTable(validNames, FatalErrorInFunction)
176  << nl
177  << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/'
178  << validCmpts[0][2] << "/thermoPhysics combinations are:"
179  << nl << nl;
180 
181  // Table of available packages (as constituent parts)
182  printTable(validCmpts, FatalErrorInFunction)
183  << exit(FatalError);
184  }
185 
186  return autoPtr<ChemistryModel>(cstrIter()(thermo));
187 }
188 
189 // ************************************************************************* //
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
basicThermo.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::basicChemistryModel::New
static autoPtr< ChemistryModel > New(typename ChemistryModel::reactionThermo &thermo)
Generic New for each of the related chemistry model.
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::dictionary::getCompat
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryTemplates.C:108
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
basicChemistryModel.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:528
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::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::dictionary::isDict
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check if entry is found and is a sub-dictionary.
Definition: dictionary.C:498
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::List< word >
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:708