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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
34template<class ChemistryModel>
36(
38)
39{
40 const IOdictionary chemistryDict
41 (
43 (
44 thermo.phasePropertyName("chemistryProperties"),
45 thermo.db().time().constant(),
46 thermo.db(),
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 {
91 dictionary chemistryTypeDictNew;
92
93 chemistryTypeDictNew.add("solver", solverName);
94 chemistryTypeDictNew.add("method", methodName);
95
96 Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
97 }
98
99 const word chemSolverCompThermoName
100 (
101 solverName + '<' + methodName + '<'
102 + ChemistryModel::reactionThermo::typeName + ','
103 + thermo.thermoName() + ">>"
104 );
105
106
107 const auto& cnstrTable = *(ChemistryModel::thermoConstructorTablePtr_);
108
109 auto* ctorPtr = cnstrTable.lookup(chemSolverCompThermoName, nullptr);
110
111 if (!ctorPtr)
112 {
113 const wordList names(cnstrTable.sortedToc());
114
115 constexpr const int nCmpt = 8;
116
117 DynamicList<word> thisCmpts(6);
118 thisCmpts.append(ChemistryModel::reactionThermo::typeName);
119 thisCmpts.append
120 (
121 basicThermo::splitThermoName(thermo.thermoName(), 5)
122 );
123
124 DynamicList<wordList> validNames;
125 validNames.append
126 (
127 // Header
128 wordList({"solver", "method"})
129 );
130
131 DynamicList<wordList> validCmpts(names.size() + 1);
132 validCmpts.append
133 (
134 // Header
136 ({
137 "solver",
138 "method",
139 "reactionThermo",
140 "transport",
141 "thermo",
142 "equationOfState",
143 "specie",
144 "energy"
145 })
146 );
147
148 for (const word& validName : names)
149 {
150 wordList cmpts(basicThermo::splitThermoName(validName, nCmpt));
151
152 if (!cmpts.empty())
153 {
154 if (thisCmpts == SubList<word>(cmpts, 6, 2))
155 {
156 validNames.append(SubList<word>(cmpts, 2));
157 }
158 validCmpts.append(std::move(cmpts));
159 }
160 }
161
163 << "Unknown " << typeName_() << " type " << solverName << nl << nl;
164
165 if (validNames.size() > 1)
166 {
168 << "All " << validNames[0][0] << '/' << validNames[0][1]
169 << " combinations for this thermodynamic model:"
170 << nl << nl;
171
172 // Table of available packages (as constituent parts)
173 printTable(validNames, FatalError) << nl;
174 }
175
176 if (validCmpts.size() > 1)
177 {
179 << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/'
180 << validCmpts[0][2] << "/thermoPhysics combinations:"
181 << nl << nl;
182
183 // Table of available packages (as constituent parts)
184 printTable(validCmpts, FatalError) << nl;
185 }
186
188 << exit(FatalError);
189 }
190
191 return autoPtr<ChemistryModel>(ctorPtr(thermo));
192}
193
194// ************************************************************************* //
ReactionThermo reactionThermo
Thermo type.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
static wordList splitThermoName(const std::string &thermoName, const int nExpectedCmpts)
Split thermo package name into a list of components names.
Definition: basicThermo.C:580
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check if entry is found and is a sub-dictionary.
Definition: dictionaryI.H:147
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List< word > wordList
A List of words.
Definition: fileName.H:63
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
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
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53