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-2022 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 (
35 )
36 {
37  IOdictionary chemistryDict
38  (
39  IOobject
40  (
41  thermo.phasePropertyName("chemistryProperties"),
42  thermo.mesh().time().constant(),
43  thermo.mesh(),
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  (
94  && !dynamicCode::resolveTemplate(basicChemistryModel::typeName).empty()
95  )
96  {
97  List<Pair<word>> substitutions
98  (
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  (
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
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
A List obtained as a section of another List.
Definition: SubList.H:56
static const word & constant()
Return constant name.
Definition: TimePaths.H:122
const fluidMulticomponentThermo & thermo() const
Return const access to the thermo.
static autoPtr< basicChemistryModel > New(const fluidMulticomponentThermo &thermo)
Select based on fluid reaction thermo.
virtual word thermoName() const =0
Name of the thermo physics.
static List< Pair< word > > thermoNameComponents(const word &thermoName)
Split name of thermo package into a list of named components names.
Definition: basicThermo.C:143
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:154
static wordList splitThermoName(const word &thermoName, const int nCmpt)
Split name of thermo package into a list of the components names.
Definition: basicThermo.C:81
virtual const fvMesh & mesh() const =0
Return const access to the mesh.
Extends base chemistry model by adding a thermo package, and ODE functions. Introduces chemistry equa...
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, if not found return the given default.
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:797
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1014
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:721
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:156
static fileName resolveTemplate(const fileName &templateName)
Resolve code-template via the codeTemplateEnvName.
Definition: dynamicCode.C:143
Base-class for multi-component fluid thermodynamic properties.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:418
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:43
error FatalError
static const char nl
Definition: Ostream.H:266
fluidMulticomponentThermo & thermo
Definition: createFields.H:31