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-2021 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_.insert(elemName, elementNames_.size()))
65  {
66  elementNames_.append(elemName);
67  }
68  else
69  {
70  IOWarningInFunction(chemDict_)
71  << "element " << elemName << " already in table." << endl;
72  }
73  }
74 
75  // Loop through all species in thermoDict to retrieve species composition
76  for (const word& specieName : speciesTable_)
77  {
78  const dictionary* elemsDict =
79  thermoDict_.subDict(specieName).findDict("elements");
80 
81  if (!elemsDict)
82  {
83  FatalIOErrorInFunction(thermoDict_)
84  << "Specie " << specieName
85  << " does not contain \"elements\" description."
86  << exit(FatalIOError);
87  }
88 
89  wordList elemNames(elemsDict->toc());
90  List<specieElement> currentComposition(elemNames.size());
91 
92  forAll(elemNames, eni)
93  {
94  currentComposition[eni].name() = elemNames[eni];
95 
96  currentComposition[eni].nAtoms() =
97  elemsDict->getOrDefault<label>
98  (
99  elemNames[eni],
100  0
101  );
102  }
103 
104  // Add current specie composition to the hash table
105  // - overwrite existing
106  speciesComposition_.erase(specieName);
107  speciesComposition_.set(specieName, currentComposition);
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
113 
114 template<class ThermoType>
116 (
117  const fileName& reactionsFileName,
118  speciesTable& species,
119  const fileName& thermoFileName
120 )
121 :
123  chemDict_
124  (
125  IFstream
126  (
127  fileName(reactionsFileName).expand()
128  )()
129  ),
130  thermoDict_
131  (
132  IFstream
133  (
134  fileName(thermoFileName).expand()
135  )()
136  ),
137  speciesTable_(setSpecies(chemDict_, species)),
138  speciesThermo_(thermoDict_),
139  reactions_(speciesTable_, speciesThermo_, chemDict_)
140 {
141  readSpeciesComposition();
142 }
143 
144 
145 template<class ThermoType>
147 (
148  const dictionary& thermoDict,
149  speciesTable& species
150 )
151 :
153  chemDict_
154  (
155  IFstream
156  (
157  thermoDict.get<fileName>("foamChemistryFile").expand()
158  )()
159  ),
160  thermoDict_
161  (
162  IFstream
163  (
164  thermoDict.get<fileName>("foamChemistryThermoFile").expand()
165  )()
166  ),
167  speciesTable_(setSpecies(chemDict_, species)),
168  speciesThermo_(thermoDict_),
169  reactions_(speciesTable_, speciesThermo_, chemDict_)
170 {
171  readSpeciesComposition();
172 }
173 
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::chemistryReader
Abstract class for reading chemistry.
Definition: chemistryReader.H:61
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
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:369
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:62
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 (stdout output on master, null elsewhere)
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:123
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:59
Foam::string::expand
string & expand(const bool allowEmpty=false)
Definition: string.C:173
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:340
Foam::stringOps::expand
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Definition: stringOps.C:718