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-------------------------------------------------------------------------------
11License
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
35template<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
48template<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
114template<class ThermoType>
116(
117 const fileName& reactionsFileName,
118 speciesTable& species,
119 const fileName& thermoFileName
120)
121:
122 chemistryReader<ThermoType>(),
123 chemDict_
124 (
126 (
127 fileName(reactionsFileName).expand()
128 )()
129 ),
130 thermoDict_
131 (
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
145template<class ThermoType>
147(
148 const dictionary& thermoDict,
149 speciesTable& species
150)
151:
152 chemistryReader<ThermoType>(),
153 chemDict_
154 (
156 (
157 thermoDict.get<fileName>("foamChemistryFile").expand()
158 )()
159 ),
160 thermoDict_
161 (
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Macros for easy insertion into run-time selection tables.
Input from file stream, using an ISstream.
Definition: IFstream.H:57
Abstract class for reading chemistry.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Chemistry reader for OpenFOAM format.
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
const dictionary & thermoDict
Definition: EEqn.H:16
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
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))
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
List< word > wordList
A List of words.
Definition: fileName.H:63
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333