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-2022 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 
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(),
50  )
51  );
52 
53  const dictionary* subDictPtr = chemistryDict.findDict("chemistryType");
54 
55  if (!subDictPtr)
56  {
58  << "Template parameter based chemistry solver selection is no "
59  << "longer supported. Please create a chemistryType dictionary"
60  << "instead." << endl << endl << "For example, the entry:" << endl
61  << " chemistrySolver ode<StandardChemistryModel<"
62  << "rhoChemistryModel,sutherlandspecie<janaf<perfectGas>,"
63  << "sensibleInternalEnergy>>" << endl << endl << "becomes:" << endl
64  << " chemistryType" << endl << " {" << endl
65  << " solver ode;" << endl << " method standard;"
66  << endl << " }" << exit(FatalError);
67  }
68 
69  const dictionary& chemistryTypeDict = *subDictPtr;
70 
71  const word solverName
72  (
73  chemistryTypeDict.getCompat<word>
74  (
75  "solver",
76  {{"chemistrySolver", -1712}}
77  )
78  );
79 
80  const word methodName
81  (
82  chemistryTypeDict.getOrDefault<word>
83  (
84  "method",
85  chemistryTypeDict.getOrDefault<bool>("TDAC", false)
86  ? "TDAC"
87  : "standard"
88  )
89  );
90 
91  {
92  dictionary chemistryTypeDictNew;
93 
94  chemistryTypeDictNew.add("solver", solverName);
95  chemistryTypeDictNew.add("method", methodName);
96 
97  Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
98  }
99 
100  const word chemSolverCompThermoName
101  (
102  solverName + '<' + methodName + '<'
103  + ChemistryModel::reactionThermo::typeName + ','
104  + thermo.thermoName() + ">>"
105  );
106 
107 
108  const auto& cnstrTable = *(ChemistryModel::thermoConstructorTablePtr_);
109 
110  auto* ctorPtr = cnstrTable.lookup(chemSolverCompThermoName, nullptr);
111 
112  if (!ctorPtr)
113  {
114  const wordList names(cnstrTable.sortedToc());
115 
116  constexpr const int nCmpt = 8;
117 
118  DynamicList<word> thisCmpts(6);
119  thisCmpts.append(ChemistryModel::reactionThermo::typeName);
120  thisCmpts.append
121  (
123  );
124 
125  DynamicList<wordList> validNames;
126  validNames.append
127  (
128  // Header
129  wordList({"solver", "method"})
130  );
131 
132  DynamicList<wordList> validCmpts(names.size() + 1);
133  validCmpts.append
134  (
135  // Header
136  wordList
137  ({
138  "solver",
139  "method",
140  "reactionThermo",
141  "transport",
142  "thermo",
143  "equationOfState",
144  "specie",
145  "energy"
146  })
147  );
148 
149  for (const word& validName : names)
150  {
151  wordList cmpts(basicThermo::splitThermoName(validName, nCmpt));
152 
153  if (!cmpts.empty())
154  {
155  if (thisCmpts == SubList<word>(cmpts, 6, 2))
156  {
157  validNames.append(SubList<word>(cmpts, 2));
158  }
159  validCmpts.append(std::move(cmpts));
160  }
161  }
162 
164  << "Unknown " << typeName_() << " type " << solverName << nl << nl;
165 
166  if (validNames.size() > 1)
167  {
168  FatalError
169  << "All " << validNames[0][0] << '/' << validNames[0][1]
170  << " combinations for this thermodynamic model:"
171  << nl << nl;
172 
173  // Table of available packages (as constituent parts)
174  printTable(validNames, FatalError) << nl;
175  }
176 
177  if (validCmpts.size() > 1)
178  {
179  FatalError
180  << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/'
181  << validCmpts[0][2] << "/thermoPhysics combinations:"
182  << nl << nl;
183 
184  // Table of available packages (as constituent parts)
185  printTable(validCmpts, FatalError) << nl;
186  }
187 
188  FatalError
189  << exit(FatalError);
190  }
191 
192  return autoPtr<ChemistryModel>(ctorPtr(thermo));
193 }
194 
195 // ************************************************************************* //
static autoPtr< ChemistryModel > New(typename ChemistryModel::reactionThermo &thermo)
Generic New for each of the related chemistry model.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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:40
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual word thermoName() const =0
Return the name of the thermo physics.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
Ignore writing from objectRegistry::writeObject()
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
psiReactionThermo & thermo
Definition: createFields.H:28
static wordList splitThermoName(const std::string &thermoName, const int nExpectedCmpts)
Split thermo package name into a list of components names.
Definition: basicThermo.C:571
A class for handling words, derived from Foam::string.
Definition: word.H:63
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T using any compatibility names if needed. FatalIOError if not found, or if there are excess tokens.
List< word > wordList
List of word.
Definition: fileName.H:59
messageStream Info
Information stream (stdout output on master, null elsewhere)
const dictionary * subDictPtr(const word &keyword) const
Deprecated(2018-10)
Definition: dictionary.H:1791
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124