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 -------------------------------------------------------------------------------
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  {
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
135  wordList
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  {
167  FatalError
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  {
178  FatalError
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 
187  FatalError
188  << exit(FatalError);
189  }
190 
191  return autoPtr<ChemistryModel>(ctorPtr(thermo));
192 }
193 
194 // ************************************************************************* //
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:169
basicThermo.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:134
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
basicChemistryModel.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
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:460
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:123
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: dictionaryI.H:147
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:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)