basicChemistryModelTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "basicChemistryModel.H"
27 #include "basicThermo.H"
28 
29 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
30 
31 template<class ChemistryModel>
33 (
34  typename ChemistryModel::reactionThermo& thermo
35 )
36 {
37  IOdictionary chemistryDict
38  (
39  IOobject
40  (
41  thermo.phasePropertyName("chemistryProperties"),
42  thermo.db().time().constant(),
43  thermo.db(),
44  IOobject::MUST_READ,
45  IOobject::NO_WRITE,
46  false
47  )
48  );
49 
50  if (!chemistryDict.isDict("chemistryType"))
51  {
53  << "Template parameter based chemistry solver selection is no "
54  << "longer supported. Please create a chemistryType dictionary"
55  << "instead." << endl << endl << "For example, the entry:" << endl
56  << " chemistrySolver ode<StandardChemistryModel<"
57  << "rhoChemistryModel,sutherlandspecie<janaf<perfectGas>,"
58  << "sensibleInternalEnergy>>" << endl << endl << "becomes:" << endl
59  << " chemistryType" << endl << " {" << endl
60  << " solver ode;" << endl << " method standard;"
61  << endl << " }" << exit(FatalError);
62  }
63 
64  const dictionary& chemistryTypeDict =
65  chemistryDict.subDict("chemistryType");
66 
67  const word& solverName
68  (
69  chemistryTypeDict.found("solver")
70  ? chemistryTypeDict.lookup("solver")
71  : chemistryTypeDict.found("chemistrySolver")
72  ? chemistryTypeDict.lookup("chemistrySolver")
73  : chemistryTypeDict.lookup("solver") // error if neither entry is found
74  );
75 
76  const word& methodName
77  (
78  chemistryTypeDict.lookupOrDefault<word>
79  (
80  "method",
81  chemistryTypeDict.lookupOrDefault<bool>("TDAC", false)
82  ? "TDAC"
83  : "standard"
84  )
85  );
86 
87  dictionary chemistryTypeDictNew;
88  chemistryTypeDictNew.add("solver", solverName);
89  chemistryTypeDictNew.add("method", methodName);
90 
91  Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
92 
93  typedef typename ChemistryModel::thermoConstructorTable cstrTableType;
94  cstrTableType* cstrTable = ChemistryModel::thermoConstructorTablePtr_;
95 
96  const word chemSolverCompThermoName =
97  solverName + '<' + methodName + '<'
98  + ChemistryModel::reactionThermo::typeName + ','
99  + thermo.thermoName() + ">>";
100 
101  typename cstrTableType::iterator cstrIter =
102  cstrTable->find(chemSolverCompThermoName);
103 
104  if (cstrIter == cstrTable->end())
105  {
107  << "Unknown " << typeName_() << " type " << solverName << endl
108  << endl;
109 
110  const wordList names(cstrTable->toc());
111 
112  wordList thisCmpts;
113  thisCmpts.append(word::null);
114  thisCmpts.append(word::null);
115  thisCmpts.append(ChemistryModel::reactionThermo::typeName);
116  thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5));
117 
118  List<wordList> validNames;
119  validNames.append(wordList(2, word::null));
120  validNames[0][0] = "solver";
121  validNames[0][1] = "method";
122  forAll(names, i)
123  {
124  const wordList cmpts(basicThermo::splitThermoName(names[i], 8));
125 
126  bool isValid = true;
127  for (label i = 2; i < cmpts.size() && isValid; ++ i)
128  {
129  isValid = isValid && cmpts[i] == thisCmpts[i];
130  }
131 
132  if (isValid)
133  {
134  validNames.append(SubList<word>(cmpts, 2));
135  }
136  }
137 
139  << "All " << validNames[0][0] << '/' << validNames[0][1]
140  << "combinations for this thermodynamic model are:"
141  << endl << endl;
142  printTable(validNames, FatalErrorInFunction);
143 
145 
146  List<wordList> validCmpts;
147  validCmpts.append(wordList(8, word::null));
148  validCmpts[0][0] = "solver";
149  validCmpts[0][1] = "method";
150  validCmpts[0][2] = "reactionThermo";
151  validCmpts[0][3] = "transport";
152  validCmpts[0][4] = "thermo";
153  validCmpts[0][5] = "equationOfState";
154  validCmpts[0][6] = "specie";
155  validCmpts[0][7] = "energy";
156  forAll(names, i)
157  {
158  validCmpts.append(basicThermo::splitThermoName(names[i], 8));
159  }
160 
162  << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/'
163  << validCmpts[0][2] << "/thermoPhysics combinations are:"
164  << endl << endl;
165  printTable(validCmpts, FatalErrorInFunction);
166 
168  }
169 
170  return autoPtr<ChemistryModel>(cstrIter()(thermo));
171 }
172 
173 // ************************************************************************* //
static autoPtr< ChemistryModel > New(typename ChemistryModel::reactionThermo &thermo)
Generic New for each of the related chemistry model.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
rhoReactionThermo & thermo
Definition: createFields.H:28
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:646
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:814
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:692
A List obtained as a section of another List.
Definition: SubList.H:53
A class for handling words, derived from string.
Definition: word.H:59
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
List< word > wordList
A List of words.
Definition: fileName.H:54
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576