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<chemistryModel<"
57  << "rhoChemistryModel,sutherland<specie<janaf<perfectGas>,"
58  << "sensibleInternalEnergy>>>>" << endl << endl << "becomes:"
59  << endl << " chemistryType" << endl << " {" << endl
60  << " solver ode;" << endl << " }" << exit(FatalError);
61  }
62 
63  const dictionary& chemistryTypeDict =
64  chemistryDict.subDict("chemistryType");
65 
66  const word solverName =
67  chemistryTypeDict.lookupBackwardsCompatible<word>
68  (
69  {"solver", "chemistrySolver"}
70  );
71 
72  const word methodName
73  (
74  chemistryTypeDict.lookupOrDefault<word>("method", "chemistryModel")
75  );
76 
77  dictionary chemistryTypeDictNew;
78  chemistryTypeDictNew.add("solver", solverName);
79  chemistryTypeDictNew.add("method", methodName);
80 
81  Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
82 
83  const word chemSolverNameName =
84  solverName + '<' + methodName + '<' + thermo.thermoName() + ">>";
85 
86  typename thermoConstructorTable::iterator cstrIter =
87  thermoConstructorTablePtr_->find(chemSolverNameName);
88 
89  if (cstrIter == thermoConstructorTablePtr_->end())
90  {
91  if
92  (
93  dynamicCode::allowSystemOperations
94  && !dynamicCode::resolveTemplate(basicChemistryModel::typeName).empty()
95  )
96  {
97  List<Pair<word>> substitutions
98  (
99  basicThermo::thermoNameComponents(thermo.thermoName())
100  );
101 
102  substitutions.append({"solver", solverName});
103  substitutions.append({"method", methodName});
104 
106  (
107  basicChemistryModel::typeName,
108  chemSolverNameName,
109  substitutions
110  );
111  cstrIter = thermoConstructorTablePtr_->find(chemSolverNameName);
112 
113  if (cstrIter == thermoConstructorTablePtr_->end())
114  {
116  << "Compilation and linkage of "
117  << basicChemistryModel::typeName << " type " << nl
118  << "chemistryType" << chemistryTypeDict << nl << nl
119  << "failed." << exit(FatalError);
120  }
121  }
122  else
123  {
125  << "Unknown " << typeName_() << " type " << chemistryTypeDictNew
126  << endl;
127 
128  const wordList names(thermoConstructorTablePtr_->sortedToc());
129 
130  wordList thisCmpts;
131  thisCmpts.append(word::null);
132  thisCmpts.append(word::null);
133  thisCmpts.append
134  (
135  basicThermo::splitThermoName(thermo.thermoName(), 5)
136  );
137 
138  List<wordList> validNames;
139  validNames.append(wordList(2, word::null));
140  validNames[0][0] = "solver";
141  validNames[0][1] = "method";
142  forAll(names, i)
143  {
144  const wordList cmpts(basicThermo::splitThermoName(names[i], 7));
145 
146  if
147  (
148  SubList<word>(cmpts, 5, 2)
149  == SubList<word>(thisCmpts, 5, 2)
150  )
151  {
152  validNames.append(SubList<word>(cmpts, 2));
153  }
154  }
155 
157  << "Valid " << validNames[0][0] << '/' << validNames[0][1]
158  << " combinations for this thermodynamic model are:"
159  << endl << endl;
160  printTable(validNames, FatalErrorInFunction);
161 
163 
164  List<wordList> validCmpts;
165  validCmpts.append(wordList(7, word::null));
166  validCmpts[0][0] = "solver";
167  validCmpts[0][1] = "method";
168  validCmpts[0][2] = "transport";
169  validCmpts[0][3] = "thermo";
170  validCmpts[0][4] = "equationOfState";
171  validCmpts[0][5] = "specie";
172  validCmpts[0][6] = "energy";
173  forAll(names, i)
174  {
175  validCmpts.append(basicThermo::splitThermoName(names[i], 7));
176  }
177 
179  << "All " << validCmpts[0][0] << '/' << validCmpts[0][1]
180  << "/thermodynamics combinations are:"
181  << endl << endl;
182  printTable(validCmpts, FatalErrorInFunction);
183 
185  }
186  }
187 
188  return autoPtr<basicChemistryModel>(cstrIter()(thermo));
189 }
190 
191 
192 // ************************************************************************* //
#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)
Name of a property for a given phase.
Definition: basicThermo.H:150
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:306
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
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:956
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1153
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:1002
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
Extends base chemistry model by adding a thermo package, and ODE functions. Introduces chemistry equa...
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:98
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:875