basicChemistryModelTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2016 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  const fvMesh& mesh,
35  const word& phaseName
36 )
37 {
38  IOdictionary chemistryDict
39  (
40  IOobject
41  (
42  IOobject::groupName("chemistryProperties", phaseName),
43  mesh.time().constant(),
44  mesh,
45  IOobject::MUST_READ,
46  IOobject::NO_WRITE,
47  false
48  )
49  );
50 
51  word chemistryTypeName;
52 
53  if (chemistryDict.isDict("chemistryType"))
54  {
55  const dictionary& chemistryTypeDict
56  (
57  chemistryDict.subDict("chemistryType")
58  );
59 
60  Info<< "Selecting chemistry type " << chemistryTypeDict << endl;
61 
62  const int nCmpt = 7;
63  const char* cmptNames[nCmpt] =
64  {
65  "chemistrySolver",
66  "chemistryThermo",
67  "transport",
68  "thermo",
69  "equationOfState",
70  "specie",
71  "energy"
72  };
73 
74  IOdictionary thermoDict
75  (
76  IOobject
77  (
78  IOobject::groupName(basicThermo::dictName, phaseName),
79  mesh.time().constant(),
80  mesh,
81  IOobject::MUST_READ_IF_MODIFIED,
82  IOobject::NO_WRITE,
83  false
84  )
85  );
86 
87  word thermoTypeName;
88 
89  if (thermoDict.isDict("thermoType"))
90  {
91  const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
92  thermoTypeName =
93  word(thermoTypeDict.lookup("transport")) + '<'
94  + word(thermoTypeDict.lookup("thermo")) + '<'
95  + word(thermoTypeDict.lookup("equationOfState")) + '<'
96  + word(thermoTypeDict.lookup("specie")) + ">>,"
97  + word(thermoTypeDict.lookup("energy")) + ">";
98  }
99  else
100  {
101  FatalIOErrorInFunction(thermoDict)
102  << "thermoType is in the old format and must be upgraded"
103  << exit(FatalIOError);
104  }
105 
106  Switch isTDAC(chemistryTypeDict.lookupOrDefault("TDAC", false));
107 
108  // Construct the name of the chemistry type from the components
109  if (isTDAC)
110  {
111  chemistryTypeName =
112  word(chemistryTypeDict.lookup("chemistrySolver")) + '<'
113  + "TDACChemistryModel<"
114  + word(chemistryTypeDict.lookup("chemistryThermo")) + ','
115  + thermoTypeName + ">>";
116  }
117  else
118  {
119  chemistryTypeName =
120  word(chemistryTypeDict.lookup("chemistrySolver")) + '<'
121  + "chemistryModel<"
122  + word(chemistryTypeDict.lookup("chemistryThermo")) + ','
123  + thermoTypeName + ">>";
124  }
125 
126  typename ChemistryModel::fvMeshConstructorTable::iterator cstrIter =
127  ChemistryModel::fvMeshConstructorTablePtr_->find(chemistryTypeName);
128 
129  if (cstrIter == ChemistryModel::fvMeshConstructorTablePtr_->end())
130  {
132  << "Unknown " << ChemistryModel::typeName << " type " << nl
133  << "chemistryType" << chemistryTypeDict << nl << nl
134  << "Valid " << ChemistryModel ::typeName << " types are:"
135  << nl << nl;
136 
137  // Get the list of all the suitable chemistry packages available
138  wordList validChemistryTypeNames
139  (
140  ChemistryModel::fvMeshConstructorTablePtr_->sortedToc()
141  );
142 
143  // Build a table of the thermo packages constituent parts
144  // Note: row-0 contains the names of constituent parts
145  List<wordList> validChemistryTypeNameCmpts
146  (
147  validChemistryTypeNames.size() + 1
148  );
149 
150  validChemistryTypeNameCmpts[0].setSize(nCmpt);
151  forAll(validChemistryTypeNameCmpts[0], j)
152  {
153  validChemistryTypeNameCmpts[0][j] = cmptNames[j];
154  }
155 
156  // Split the thermo package names into their constituent parts
157  forAll(validChemistryTypeNames, i)
158  {
159  validChemistryTypeNameCmpts[i+1] = basicThermo::splitThermoName
160  (
161  validChemistryTypeNames[i],
162  nCmpt
163  );
164  }
165 
166  // Print the table of available packages
167  // in terms of their constituent parts
168  printTable(validChemistryTypeNameCmpts, FatalError);
169 
171  }
172 
173  return autoPtr<ChemistryModel>(cstrIter()(mesh, phaseName));
174  }
175  else
176  {
177  chemistryTypeName =
178  word(chemistryDict.lookup("chemistryType"));
179 
180  Info<< "Selecting chemistry type " << chemistryTypeName << endl;
181 
182  typename ChemistryModel::fvMeshConstructorTable::iterator cstrIter =
183  ChemistryModel::fvMeshConstructorTablePtr_->find(chemistryTypeName);
184 
185  if (cstrIter == ChemistryModel::fvMeshConstructorTablePtr_->end())
186  {
188  << "Unknown " << ChemistryModel::typeName << " type "
189  << chemistryTypeName << nl << nl
190  << "Valid ChemistryModel types are:" << nl
191  << ChemistryModel::fvMeshConstructorTablePtr_->sortedToc() << nl
192  << exit(FatalError);
193  }
194 
195  return autoPtr<ChemistryModel>(cstrIter()(mesh, phaseName));
196  }
197 }
198 
199 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:253
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:646
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
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
static autoPtr< Thermo > New(const fvMesh &mesh, const word &phaseName)
Generic New for each of the related chemistry model.
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
const word dictName("particleTrackDict")
static const char nl
Definition: Ostream.H:262
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
void setSize(const label)
Reset size of List.
Definition: List.C:281
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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
IOerror FatalIOError