Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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\*---------------------------------------------------------------------------*/
29#include "basicChemistryModel.H"
30#include "basicThermo.H"
31
32// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
33
34template<class ChemistryModel>
36(
37 typename ChemistryModel::reactionThermo& thermo
38)
39{
40 const IOdictionary chemistryDict
41 (
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 (
122 basicThermo::splitThermoName(thermo.thermoName(), 5)
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
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 {
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 {
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
189 << exit(FatalError);
190 }
191
192 return autoPtr<ChemistryModel>(ctorPtr(thermo));
193}
194
195// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
@ NO_REGISTER
Do not request registration (bool: false).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A non-owning sub-view of a List (allocated or unallocated storage).
Definition SubList.H:61
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< ChemistryModel > New(typename ChemistryModel::reactionThermo &thermo)
Generic New for each of the related chemistry model.
static wordList splitThermoName(const std::string &thermoName, const int nExpectedCmpts)
Split thermo package name into a list of components names.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
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,...
const dictionary * subDictPtr(const word &keyword) const
Deprecated(2018-10).
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition dictionary.C:625
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:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
auto & names
List< word > wordList
List of word.
Definition fileName.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
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
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
psiReactionThermo & thermo