foamChemistryReader.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) 2011-2018 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 "foamChemistryReader.H"
27 #include "IFstream.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class ThermoType>
34 (
35  const dictionary& dict,
36  speciesTable& species
37 )
38 {
39  wordList s(dict.lookup("species"));
40  species.transfer(s);
41  return species;
42 }
43 
44 
45 template<class ThermoType>
47 {
48  if (!chemDict_.found("elements"))
49  {
50  Info<< " elements not defined in " << chemDict_.name() << endl;
51  return;
52  }
53 
54  wordList e(chemDict_.lookup("elements"));
55  label currentElementIndex(0);
56 
57  DynamicList<word> elementNames_;
58  HashTable<label> elementIndices_;
59 
60  forAll(e, ei)
61  {
62  if (!elementIndices_.found(e[ei]))
63  {
64  elementIndices_.insert(e[ei], currentElementIndex++);
65  elementNames_.append(e[ei]);
66  }
67  else
68  {
69  IOWarningInFunction(chemDict_)
70  << "element " << e[ei] << " already in table." << endl;
71  }
72  }
73 
74  // Loop through all species in thermoDict to retrieve
75  // the species composition
76  forAll(speciesTable_, si)
77  {
78  if (thermoDict_.subDict(speciesTable_[si]).isDict("elements"))
79  {
80  dictionary currentElements
81  (
82  thermoDict_.subDict(speciesTable_[si]).subDict("elements")
83  );
84 
85  wordList currentElementsName(currentElements.toc());
86  List<specieElement> currentComposition(currentElementsName.size());
87 
88  forAll(currentElementsName, eni)
89  {
90  currentComposition[eni].name() = currentElementsName[eni];
91 
92  currentComposition[eni].nAtoms() =
93  currentElements.lookupOrDefault
94  (
95  currentElementsName[eni],
96  0
97  );
98  }
99 
100  // Add current specie composition to the hash table
101  speciesCompositionTable::iterator specieCompositionIter
102  (
103  speciesComposition_.find(speciesTable_[si])
104  );
105 
106  if (specieCompositionIter != speciesComposition_.end())
107  {
108  speciesComposition_.erase(specieCompositionIter);
109  }
110 
111  speciesComposition_.insert(speciesTable_[si], currentComposition);
112  }
113  else
114  {
115  FatalIOErrorInFunction(thermoDict_)
116  << "Specie " << speciesTable_[si]
117  << " does not contain element description."
118  << exit(FatalIOError);
119  }
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
125 
126 template<class ThermoType>
128 (
129  const fileName& reactionsFileName,
130  speciesTable& species,
131  const fileName& thermoFileName
132 )
133 :
135  chemDict_
136  (
137  IFstream
138  (
139  fileName(reactionsFileName).expand()
140  )()
141  ),
142  thermoDict_
143  (
144  IFstream
145  (
146  fileName(thermoFileName).expand()
147  )()
148  ),
149  speciesTable_(setSpecies(chemDict_, species)),
150  speciesThermo_(thermoDict_),
151  reactions_(speciesTable_, speciesThermo_, chemDict_)
152 {
153  readSpeciesComposition();
154 }
155 
156 
157 template<class ThermoType>
159 (
160  const dictionary& thermoDict,
161  speciesTable& species
162 )
163 :
165  chemDict_
166  (
167  IFstream
168  (
169  fileName(thermoDict.lookup("foamChemistryFile")).expand()
170  )()
171  ),
172  thermoDict_
173  (
174  IFstream
175  (
176  fileName(thermoDict.lookup("foamChemistryThermoFile")).expand()
177  )()
178  ),
179  speciesTable_(setSpecies(chemDict_, species)),
180  speciesThermo_(thermoDict_),
181  reactions_(speciesTable_, speciesThermo_, chemDict_)
182 {
183  readSpeciesComposition();
184 }
185 
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping.
Definition: stringOps.C:75
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:41
Macros for easy insertion into run-time selection tables.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
volScalarField & e
Elementary charge.
Definition: createFields.H:11
Chemistry reader for OpenFOAM format.
foamChemistryReader(const fileName &reactionsFileName, speciesTable &species, const fileName &thermoFileName)
Construct from foamChemistry and thermodynamics file names.
Input from file stream.
Definition: IFstream.H:81
List< word > wordList
A List of words.
Definition: fileName.H:54
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
A wordList with hashed indices for faster lookup by name.
messageStream Info
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Abstract class for reading chemistry.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583
IOerror FatalIOError