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-2015 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  // Construct the name of the chemistry type from the components
107  chemistryTypeName =
108  word(chemistryTypeDict.lookup("chemistrySolver")) + '<'
109  + word(chemistryTypeDict.lookup("chemistryThermo")) + ','
110  + thermoTypeName + ">";
111 
112  typename ChemistryModel::fvMeshConstructorTable::iterator cstrIter =
113  ChemistryModel::fvMeshConstructorTablePtr_->find(chemistryTypeName);
114 
115  if (cstrIter == ChemistryModel::fvMeshConstructorTablePtr_->end())
116  {
118  << "Unknown " << ChemistryModel::typeName << " type " << nl
119  << "chemistryType" << chemistryTypeDict << nl << nl
120  << "Valid " << ChemistryModel ::typeName << " types are:"
121  << nl << nl;
122 
123  // Get the list of all the suitable chemistry packages available
124  wordList validChemistryTypeNames
125  (
126  ChemistryModel::fvMeshConstructorTablePtr_->sortedToc()
127  );
128 
129  // Build a table of the thermo packages constituent parts
130  // Note: row-0 contains the names of constituent parts
131  List<wordList> validChemistryTypeNameCmpts
132  (
133  validChemistryTypeNames.size() + 1
134  );
135 
136  validChemistryTypeNameCmpts[0].setSize(nCmpt);
137  forAll(validChemistryTypeNameCmpts[0], j)
138  {
139  validChemistryTypeNameCmpts[0][j] = cmptNames[j];
140  }
141 
142  // Split the thermo package names into their constituent parts
143  forAll(validChemistryTypeNames, i)
144  {
145  validChemistryTypeNameCmpts[i+1] = basicThermo::splitThermoName
146  (
147  validChemistryTypeNames[i],
148  nCmpt
149  );
150  }
151 
152  // Print the table of available packages
153  // in terms of their constituent parts
154  printTable(validChemistryTypeNameCmpts, FatalError);
155 
157  }
158 
159  return autoPtr<ChemistryModel>(cstrIter()(mesh, phaseName));
160  }
161  else
162  {
163  chemistryTypeName =
164  word(chemistryDict.lookup("chemistryType"));
165 
166  Info<< "Selecting chemistry type " << chemistryTypeName << endl;
167 
168  typename ChemistryModel::fvMeshConstructorTable::iterator cstrIter =
169  ChemistryModel::fvMeshConstructorTablePtr_->find(chemistryTypeName);
170 
171  if (cstrIter == ChemistryModel::fvMeshConstructorTablePtr_->end())
172  {
174  << "Unknown " << ChemistryModel::typeName << " type "
175  << chemistryTypeName << nl << nl
176  << "Valid ChemistryModel types are:" << nl
177  << ChemistryModel::fvMeshConstructorTablePtr_->sortedToc() << nl
178  << exit(FatalError);
179  }
180 
181  return autoPtr<ChemistryModel>(cstrIter()(mesh, phaseName));
182  }
183 }
184 
185 // ************************************************************************* //
#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:76
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:602
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
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
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:295
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
word dictName("noiseDict")
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:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451
IOerror FatalIOError