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  {
102  (
103  (ChemistryModel::typeName + "::New(const mesh&)").c_str(),
104  thermoDict
105  ) << "thermoType is in the old format and must be upgraded"
106  << exit(FatalIOError);
107  }
108 
109  // Construct the name of the chemistry type from the components
110  chemistryTypeName =
111  word(chemistryTypeDict.lookup("chemistrySolver")) + '<'
112  + word(chemistryTypeDict.lookup("chemistryThermo")) + ','
113  + thermoTypeName + ">";
114 
115  typename ChemistryModel::fvMeshConstructorTable::iterator cstrIter =
116  ChemistryModel::fvMeshConstructorTablePtr_->find(chemistryTypeName);
117 
118  if (cstrIter == ChemistryModel::fvMeshConstructorTablePtr_->end())
119  {
120  FatalErrorIn(ChemistryModel::typeName + "::New(const mesh&)")
121  << "Unknown " << ChemistryModel::typeName << " type " << nl
122  << "chemistryType" << chemistryTypeDict << nl << nl
123  << "Valid " << ChemistryModel ::typeName << " types are:"
124  << nl << nl;
125 
126  // Get the list of all the suitable chemistry packages available
127  wordList validChemistryTypeNames
128  (
129  ChemistryModel::fvMeshConstructorTablePtr_->sortedToc()
130  );
131 
132  // Build a table of the thermo packages constituent parts
133  // Note: row-0 contains the names of constituent parts
134  List<wordList> validChemistryTypeNameCmpts
135  (
136  validChemistryTypeNames.size() + 1
137  );
138 
139  validChemistryTypeNameCmpts[0].setSize(nCmpt);
140  forAll(validChemistryTypeNameCmpts[0], j)
141  {
142  validChemistryTypeNameCmpts[0][j] = cmptNames[j];
143  }
144 
145  // Split the thermo package names into their constituent parts
146  forAll(validChemistryTypeNames, i)
147  {
148  validChemistryTypeNameCmpts[i+1] = basicThermo::splitThermoName
149  (
150  validChemistryTypeNames[i],
151  nCmpt
152  );
153  }
154 
155  // Print the table of available packages
156  // in terms of their constituent parts
157  printTable(validChemistryTypeNameCmpts, FatalError);
158 
160  }
161 
162  return autoPtr<ChemistryModel>(cstrIter()(mesh, phaseName));
163  }
164  else
165  {
166  chemistryTypeName =
167  word(chemistryDict.lookup("chemistryType"));
168 
169  Info<< "Selecting chemistry type " << chemistryTypeName << endl;
170 
171  typename ChemistryModel::fvMeshConstructorTable::iterator cstrIter =
172  ChemistryModel::fvMeshConstructorTablePtr_->find(chemistryTypeName);
173 
174  if (cstrIter == ChemistryModel::fvMeshConstructorTablePtr_->end())
175  {
176  FatalErrorIn(ChemistryModel::typeName + "::New(const mesh&)")
177  << "Unknown " << ChemistryModel::typeName << " type "
178  << chemistryTypeName << nl << nl
179  << "Valid ChemistryModel types are:" << nl
180  << ChemistryModel::fvMeshConstructorTablePtr_->sortedToc() << nl
181  << exit(FatalError);
182  }
183 
184  return autoPtr<ChemistryModel>(cstrIter()(mesh, phaseName));
185  }
186 }
187 
188 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A class for handling words, derived from string.
Definition: word.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
const word dictName("particleTrackDict")
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
static const char nl
Definition: Ostream.H:260
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static autoPtr< Thermo > New(const fvMesh &mesh, const word &phaseName)
Generic New for each of the related chemistry model.
IOerror FatalIOError
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void printTable(const List< wordList > &, List< string::size_type > &, Ostream &)
Definition: wordIOList.C:42
#define forAll(list, i)
Definition: UList.H:421
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:607
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117