foamChemistryReader.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "foamChemistryReader.H"
30 #include "IFstream.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class ThermoType>
37 (
38  const dictionary& dict,
39  speciesTable& species
40 )
41 {
42  wordList s(dict.get<wordList>("species"));
43  species.transfer(s);
44  return species;
45 }
46 
47 
48 template<class ThermoType>
50 {
51  wordList elems;
52 
53  if (!chemDict_.readIfPresent("elements", elems))
54  {
55  Info<< " elements not defined in " << chemDict_.name() << endl;
56  return;
57  }
58 
59  DynamicList<word> elementNames_;
60  HashTable<label> elementIndices_;
61 
62  for (const word& elemName : elems)
63  {
64  if (!elementIndices_.found(elemName))
65  {
66  elementIndices_.insert(elemName, elementNames_.size());
67  elementNames_.append(elemName);
68  }
69  else
70  {
71  IOWarningInFunction(chemDict_)
72  << "element " << elemName << " already in table." << endl;
73  }
74  }
75 
76  // Loop through all species in thermoDict to retrieve species composition
77  for (const word& specieName : speciesTable_)
78  {
79  const dictionary* elemsDict =
80  thermoDict_.subDict(specieName).findDict("elements");
81 
82  if (!elemsDict)
83  {
84  FatalIOErrorInFunction(thermoDict_)
85  << "Specie " << specieName
86  << " does not contain \"elements\" description."
87  << exit(FatalIOError);
88  }
89 
90  wordList elemNames(elemsDict->toc());
91  List<specieElement> currentComposition(elemNames.size());
92 
93  forAll(elemNames, eni)
94  {
95  currentComposition[eni].name() = elemNames[eni];
96 
97  currentComposition[eni].nAtoms() =
98  elemsDict->getOrDefault<label>
99  (
100  elemNames[eni],
101  0
102  );
103  }
104 
105  // Add current specie composition to the hash table
106  // - overwrite existing
107  speciesComposition_.erase(specieName);
108  speciesComposition_.set(specieName, currentComposition);
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
114 
115 template<class ThermoType>
117 (
118  const fileName& reactionsFileName,
119  speciesTable& species,
120  const fileName& thermoFileName
121 )
122 :
124  chemDict_
125  (
126  IFstream
127  (
128  fileName(reactionsFileName).expand()
129  )()
130  ),
131  thermoDict_
132  (
133  IFstream
134  (
135  fileName(thermoFileName).expand()
136  )()
137  ),
138  speciesTable_(setSpecies(chemDict_, species)),
139  speciesThermo_(thermoDict_),
140  reactions_(speciesTable_, speciesThermo_, chemDict_)
141 {
142  readSpeciesComposition();
143 }
144 
145 
146 template<class ThermoType>
148 (
149  const dictionary& thermoDict,
150  speciesTable& species
151 )
152 :
154  chemDict_
155  (
156  IFstream
157  (
158  thermoDict.get<fileName>("foamChemistryFile").expand()
159  )()
160  ),
161  thermoDict_
162  (
163  IFstream
164  (
165  thermoDict.get<fileName>("foamChemistryThermoFile").expand()
166  )()
167  ),
168  speciesTable_(setSpecies(chemDict_, species)),
169  speciesThermo_(thermoDict_),
170  reactions_(speciesTable_, speciesThermo_, chemDict_)
171 {
172  readSpeciesComposition();
173 }
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::chemistryReader
Abstract class for reading chemistry.
Definition: chemistryReader.H:61
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
foamChemistryReader.H
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::stringOps::expand
string expand(const std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Definition: stringOps.C:720
Foam::hashedWordList
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
Definition: hashedWordList.H:54
Foam::speciesTable
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:43
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
thermoDict
const dictionary & thermoDict
Definition: EEqn.H:16
Foam::foamChemistryReader
Chemistry reader for OpenFOAM format.
Definition: foamChemistryReader.H:60
Foam::string::expand
string & expand(const bool allowEmpty=false)
Definition: string.C:186
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:315