SolidReaction.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-2019 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 "SolidReaction.H"
27 #include "DynamicList.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class ReactionThermo>
33 (
34  const Reaction<ReactionThermo>& reaction,
35  const speciesTable& pyrolisisGases,
36  const List<specieCoeffs>& glhs,
37  const List<specieCoeffs>& grhs
38 )
39 :
41  pyrolisisGases_(pyrolisisGases),
42  glhs_(glhs),
43  grhs_(grhs)
44 {}
45 
46 
47 template<class ReactionThermo>
49 (
51  const speciesTable& pyrolisisGases
52 )
53 :
55  pyrolisisGases_(pyrolisisGases),
56  glhs_(r.glhs_),
57  grhs_(r.grhs_)
58 {}
59 
60 
61 template<class ReactionThermo>
63 (
64  const speciesTable& species,
65  const HashPtrTable<ReactionThermo>& thermoDatabase,
66  const dictionary& dict
67 )
68 :
69  Reaction<ReactionThermo>(species, thermoDatabase, dict),
70  pyrolisisGases_(dict.parent().parent().lookup("gaseousSpecies")),
71  glhs_(),
72  grhs_()
73 {
74  specieCoeffs::setLRhs
75  (
76  IStringStream(dict.lookup("reaction"))(),
77  pyrolisisGases_,
78  glhs_,
79  grhs_
80  );
81 }
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
86 template<class ReactionThermo>
89 {
90  return glhs_;
91 }
92 
93 
94 template<class ReactionThermo>
97 {
98  return grhs_;
99 }
100 
101 
102 template<class ReactionThermo>
104 gasSpecies() const
105 {
106  return pyrolisisGases_;
107 }
108 
109 
110 template<class ReactionThermo>
112 {
114  writeEntry(os, "reaction", solidReactionStr(reaction));
115 }
116 
117 
118 template<class ReactionThermo>
120 (
121  OStringStream& reaction
122 ) const
123 {
124  specieCoeffs::reactionStr(reaction, this->species(), this->lhs());
125  if (glhs().size() > 0)
126  {
127  reaction << " + ";
128  solidReactionStrLeft(reaction);
129  }
130  reaction << " = ";
131  specieCoeffs::reactionStr(reaction, this->species(), this->rhs());
132  if (grhs().size() > 0)
133  {
134  reaction << " + ";
135  solidReactionStrRight(reaction);
136  }
137  return reaction.str();
138 
139 }
140 
141 
142 template<class ReactionThermo>
144 (
145  OStringStream& reaction
146 ) const
147 {
148  for (label i = 0; i < glhs().size(); ++i)
149  {
150  if (i > 0)
151  {
152  reaction << " + ";
153  }
154  if (mag(glhs()[i].stoichCoeff - 1) > small)
155  {
156  reaction << glhs()[i].stoichCoeff;
157  }
158  reaction << gasSpecies()[glhs()[i].index];
159  if (mag(glhs()[i].exponent - glhs()[i].stoichCoeff) > small)
160  {
161  reaction << "^" << glhs()[i].exponent;
162  }
163  }
164 }
165 
166 
167 template<class ReactionThermo>
169 (
170  OStringStream& reaction
171 ) const
172 {
173 
174  for (label i = 0; i < grhs().size(); ++i)
175  {
176  if (i > 0)
177  {
178  reaction << " + ";
179  }
180  if (mag(grhs()[i].stoichCoeff - 1) > small)
181  {
182  reaction << grhs()[i].stoichCoeff;
183  }
184  reaction << gasSpecies()[grhs()[i].index];
185  if (mag(grhs()[i].exponent - grhs()[i].stoichCoeff) > small)
186  {
187  reaction << "^" << grhs()[i].exponent;
188  }
189  }
190 }
191 
192 // ************************************************************************* //
dictionary dict
virtual const speciesTable & gasSpecies() const
Access to gas specie list.
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 list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:56
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:282
SolidReaction(const Reaction< ReactionThermo > &reaction, const speciesTable &pyrolisisGases, const List< specieCoeffs > &glhs, const List< specieCoeffs > &grhs)
Construct from components.
Definition: SolidReaction.C:33
CombustionModel< rhoReactionThermo > & reaction
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual const List< specieCoeffs > & glhs() const
Access to the gas components of the right hand side.
Definition: SolidReaction.C:88
virtual void write(Ostream &) const
Write.
virtual const List< specieCoeffs > & grhs() const
Access to the gas components of the left hand side.
Definition: SolidReaction.C:96
A wordList with hashed indices for faster lookup by name.
Input from memory buffer stream.
Definition: IStringStream.H:49
string str() const
Return the string.
Read solid reactions of the type S1 = S2 + G1.
Definition: SolidReaction.H:49
dimensioned< scalar > mag(const dimensioned< Type > &)
A class for handling character strings derived from std::string.
Definition: string.H:74
Output to memory buffer stream.
Definition: OStringStream.H:49
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583