chemistryModelNew.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-2026 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 "chemistryModel.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  const word type
51  (
52  chemistryDict.lookupOrDefault<word>("type", "standard")
53  );
54 
56  << "Selecting chemistryModel " << type << endl;
57 
58  // Check if the non-templated chemistryModel type exists on the table
59  // providing support for third-party implementations which are independent
60  // of OpenFOAM thermodynamics
61  typename thermoConstructorTable::iterator cstrIter =
62  thermoConstructorTablePtr_->find(type);
63 
64  if (cstrIter == thermoConstructorTablePtr_->end())
65  {
66  const word instantiatedType
67  (
68  type + '<' + thermo.thermoName() + ">"
69  );
70 
71  Info<< "Instantiated as " << instantiatedType << endl;
72 
73  // Check if the chemistryModel type exists templated on
74  // the current thermodynamics
75  cstrIter = thermoConstructorTablePtr_->find(instantiatedType);
76 
77  if (cstrIter == thermoConstructorTablePtr_->end())
78  {
79  if
80  (
83  (
85  ).empty()
86  )
87  {
88  List<Pair<word>> substitutions
89  (
91  );
92 
93  substitutions.append({"type", type});
94 
96  (
98  instantiatedType,
99  substitutions
100  );
101  cstrIter = thermoConstructorTablePtr_->find(instantiatedType);
102 
103  if (cstrIter == thermoConstructorTablePtr_->end())
104  {
105  FatalIOErrorInFunction(chemistryDict)
106  << "Compilation and linkage of "
107  << chemistryModel::typeName << " type "
108  << type << nl << nl
109  << "failed." << exit(FatalIOError);
110  }
111  }
112  else
113  {
114  FatalIOErrorInFunction(chemistryDict)
115  << "Unknown " << typeName_() << type
116  << " instantiated as " << instantiatedType
117  << endl;
118 
119  const wordList names(thermoConstructorTablePtr_->sortedToc());
120 
121  wordList thisCmpts(1, word::null);
122  thisCmpts.append
123  (
125  );
126 
127  List<wordList> validNames(1, {"type"});
128  forAll(names, i)
129  {
130  const wordList cmpts
131  (
132  basicThermo::splitThermoName(names[i], 6)
133  );
134 
135  if
136  (
137  SubList<word>(cmpts, 5, 1)
138  == SubList<word>(thisCmpts, 5, 1)
139  )
140  {
141  validNames.append(SubList<word>(cmpts, 1));
142  }
143  }
144 
145  FatalIOErrorInFunction(chemistryDict)
146  << "Valid chemistryModel types "
147  "for the current thermodynamics are:"
148  << nl << endl;
149  printTable(validNames, FatalIOErrorInFunction(chemistryDict));
150 
151  FatalIOErrorInFunction(chemistryDict) << endl;
152 
153  List<wordList> validCmpts
154  (
155  1,
156  {
157  "type",
158  "transport",
159  "thermo",
160  "equationOfState",
161  "specie",
162  "energy"
163  }
164  );
165  forAll(names, i)
166  {
167  validCmpts.append
168  (
169  basicThermo::splitThermoName(names[i], 6)
170  );
171  }
172 
173  FatalIOErrorInFunction(chemistryDict)
174  << "All chemistryModel/thermodynamics combinations are:"
175  << endl << endl;
176  printTable(validCmpts, FatalIOErrorInFunction(chemistryDict));
177 
178  FatalIOErrorInFunction(chemistryDict) << exit(FatalIOError);
179  }
180  }
181  }
182 
183  return autoPtr<chemistryModel>(cstrIter()(thermo));
184 }
185 
186 
187 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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
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:156
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:151
static wordList splitThermoName(const word &thermoName, const int nCmpt)
Split name of thermo package into a list of the components names.
Definition: basicThermo.C:94
virtual const fvMesh & mesh() const =0
Return const access to the mesh.
const fluidMulticomponentThermo & thermo() const
Return const access to the thermo.
chemistryModel(const fluidMulticomponentThermo &thermo)
Construct from thermo.
static autoPtr< chemistryModel > New(const fluidMulticomponentThermo &thermo)
Select based on fluid reaction thermo.
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:188
static fileName resolveTemplate(const fileName &templateName)
Resolve code-template via Foam::findConfigFile.
Definition: dynamicCode.C:481
Base-class for multi-component fluid thermodynamic properties.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:43
IOerror FatalIOError
Ostream & indentOrNl(Ostream &os)
Indent stream or add newline if indent level == 0.
Definition: Ostream.H:250
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
fluidMulticomponentThermo & thermo
Definition: createFields.H:15