basicChemistryModelNew.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-2021 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 #include "compileTemplate.H"
29 
30 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
31 
33 (
34  const fluidReactionThermo& thermo
35 )
36 {
37  IOdictionary chemistryDict
38  (
39  IOobject
40  (
41  thermo.phasePropertyName("chemistryProperties"),
42  thermo.T().mesh().time().constant(),
43  thermo.T().mesh(),
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,sutherland<specie<janaf<perfectGas>,"
58  << "sensibleInternalEnergy>>>>" << endl << endl << "becomes:"
59  << endl << " 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  chemistryTypeDict.lookupBackwardsCompatible<word>
69  (
70  {"solver", "chemistrySolver"}
71  );
72 
73  const word methodName
74  (
75  chemistryTypeDict.lookupOrDefault<word>
76  (
77  "method",
78  chemistryTypeDict.lookupOrDefault<bool>("TDAC", false)
79  ? "TDAC"
80  : "standard"
81  )
82  );
83 
84  dictionary chemistryTypeDictNew;
85  chemistryTypeDictNew.add("solver", solverName);
86  chemistryTypeDictNew.add("method", methodName);
87 
88  Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
89 
90  const word chemSolverNameName =
91  solverName + '<' + methodName + '<' + thermo.thermoName() + ">>";
92 
93  typename thermoConstructorTable::iterator cstrIter =
94  thermoConstructorTablePtr_->find(chemSolverNameName);
95 
96  if (cstrIter == thermoConstructorTablePtr_->end())
97  {
98  if
99  (
100  dynamicCode::allowSystemOperations
101  && !dynamicCode::resolveTemplate(basicChemistryModel::typeName).empty()
102  )
103  {
104  List<Pair<word>> substitutions
105  (
106  basicThermo::thermoNameComponents(thermo.thermoName())
107  );
108 
109  substitutions.append({"solver", solverName});
110  substitutions.append({"method", methodName});
111 
112  compileTemplate chemistryModel
113  (
114  basicChemistryModel::typeName,
115  chemSolverNameName,
116  substitutions
117  );
118  cstrIter = thermoConstructorTablePtr_->find(chemSolverNameName);
119 
120  if (cstrIter == thermoConstructorTablePtr_->end())
121  {
123  << "Compilation and linkage of "
124  << basicChemistryModel::typeName << " type " << nl
125  << "chemistryType" << chemistryTypeDict << nl << nl
126  << "failed." << exit(FatalError);
127  }
128  }
129  else
130  {
132  << "Unknown " << typeName_() << " type " << chemistryTypeDictNew
133  << endl;
134 
135  const wordList names(thermoConstructorTablePtr_->sortedToc());
136 
137  wordList thisCmpts;
138  thisCmpts.append(word::null);
139  thisCmpts.append(word::null);
140  thisCmpts.append
141  (
142  basicThermo::splitThermoName(thermo.thermoName(), 5)
143  );
144 
145  List<wordList> validNames;
146  validNames.append(wordList(2, word::null));
147  validNames[0][0] = "solver";
148  validNames[0][1] = "method";
149  forAll(names, i)
150  {
151  const wordList cmpts(basicThermo::splitThermoName(names[i], 7));
152 
153  if
154  (
155  SubList<word>(cmpts, 5, 2)
156  == SubList<word>(thisCmpts, 5, 2)
157  )
158  {
159  validNames.append(SubList<word>(cmpts, 2));
160  }
161  }
162 
164  << "Valid " << validNames[0][0] << '/' << validNames[0][1]
165  << " combinations for this thermodynamic model are:"
166  << endl << endl;
167  printTable(validNames, FatalErrorInFunction);
168 
170 
171  List<wordList> validCmpts;
172  validCmpts.append(wordList(7, word::null));
173  validCmpts[0][0] = "solver";
174  validCmpts[0][1] = "method";
175  validCmpts[0][2] = "transport";
176  validCmpts[0][3] = "thermo";
177  validCmpts[0][4] = "equationOfState";
178  validCmpts[0][5] = "specie";
179  validCmpts[0][6] = "energy";
180  forAll(names, i)
181  {
182  validCmpts.append(basicThermo::splitThermoName(names[i], 7));
183  }
184 
186  << "All " << validCmpts[0][0] << '/' << validCmpts[0][1]
187  << "/thermodynamics combinations are:"
188  << endl << endl;
189  printTable(validCmpts, FatalErrorInFunction);
190 
192  }
193  }
194 
195  return autoPtr<basicChemistryModel>(cstrIter()(thermo));
196 }
197 
198 
199 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
fluidReactionThermo & thermo
Definition: createFields.H:28
static word phasePropertyName(const word &name, const word &phaseName)
Return the name of a property for a given phase.
Definition: basicThermo.H:156
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:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
virtual word thermoName() const =0
Return the name of the thermo physics.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Base-class for multi-component fluid thermodynamic properties.
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:936
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1133
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:982
static autoPtr< basicChemistryModel > New(const fluidReactionThermo &thermo)
Select based on fluid reaction thermo.
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:178
static const char nl
Definition: Ostream.H:260
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
const Mesh & mesh() const
Return mesh.
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,.
virtual const volScalarField & T() const =0
Temperature [K].
messageStream Info
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:855