BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / solid / reaction / Reactions / solidReaction / solidReaction.C
blob3c5329107e6bb76c88d57a907d1476a7999f7db3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "solidReaction.H"
27 #include "DynamicList.H"
29 /* * * * * * * * * * * * * * * private static data * * * * * * * * * * * * * */
31 namespace Foam
33     defineTypeNameAndDebug(solidReaction, 0);
34     defineRunTimeSelectionTable(solidReaction, Istream);
37 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
39 Foam::solidReaction::solidReaction
41     const speciesTable& componets,
42     const speciesTable& pyrolisisGases,
43     const List<label>& slhs,
44     const List<label>& srhs,
45     const List<label>& grhs
48     components_(componets),
49     pyrolisisGases_(pyrolisisGases),
50     slhs_(slhs),
51     srhs_(srhs),
52     grhs_(grhs)
56 Foam::solidReaction::solidReaction
58     const solidReaction& r,
59     const speciesTable& componets,
60     const speciesTable& pyrolisisGases
63     components_(componets),
64     pyrolisisGases_(pyrolisisGases),
65     slhs_(r.slhs_),
66     srhs_(r.srhs_),
67     grhs_(r.grhs_)
71 Foam::solidReaction::solidReaction
73     const speciesTable& components,
74     Istream& is,
75     const speciesTable& pyrolisisGases
78     components_(components),
79     pyrolisisGases_(pyrolisisGases)
81     setLRhs(is);
85 Foam::label Foam::solidReaction::componentIndex
87     bool& isGas,
88     Istream& is
91     token t(is);
93     if (t.isWord())
94     {
95         word componentName = t.wordToken();
97         size_t i = componentName.find('=');
99         if (i != word::npos)
100         {
101             string exponentStr = componentName
102             (
103                 i + 1,
104                 componentName.size() - i - 1
105             );
106             componentName = componentName(0, i);
107         }
108         if (components_.contains(componentName))
109         {
110             isGas = false;
111             return (components_[componentName]);
112         }
113         else if (pyrolisisGases_.contains(componentName))
114         {
115             isGas = true;
116             return (pyrolisisGases_[componentName]);
117         }
118         else
119         {
120             FatalIOErrorIn
121             (
122                 "solidReaction::componentIndex(bool&, Istream& is)",
123                 is
124             )
125                 << "Cannot find component" << componentName
126                 << "in tables :" << pyrolisisGases_ << " or "
127                 << components_
128                 << exit(FatalIOError);
129             return -1;
130         }
132     }
133     else
134     {
135         FatalIOErrorIn("solidReaction::componentIndex(bool&, Istream& is)", is)
136             << "Expected a word but found " << t.info()
137             << exit(FatalIOError);
138         return -1;
139     }
143 void Foam::solidReaction::setLRhs(Istream& is)
145     DynamicList<label> dlsrhs;
147     label index = 0;
149     while (is)
150     {
151         bool isGas = false;
152         index = componentIndex(isGas, is);
154         if (index != -1)
155         {
156             dlsrhs.append(index);
158             token t(is);
160             if (t.isPunctuation())
161             {
162                 if (t == token::ADD)
163                 {
164                     if(isGas)
165                     {
166                         grhs_ = dlsrhs.shrink();
167                         dlsrhs.clear();
168                         //is.putBack(t);
169                         //return;
170                     }
171                     else
172                     {
173                         srhs_ = dlsrhs.shrink();
174                         dlsrhs.clear(); //is.putBack(t);
175                         //return;
176                     }
177                 }
178                 else if (t == token::ASSIGN)
179                 {
180                     if(isGas)
181                     {
182                         Info << "Pyrolysis Gases should appear on lhs of the"
183                                 "reaction" << endl;
184                     }
185                     else
186                     {
187                         slhs_ = dlsrhs.shrink();
188                         dlsrhs.clear();
189                     }
190                 }
191                 else if(isGas)
192                 {
193                     grhs_ = dlsrhs.shrink();
194                     is.putBack(t);
195                     return;
196                 }
197                 else
198                 {
199                     srhs_ = dlsrhs.shrink();
200                     is.putBack(t);
201                     return;
202                 }
203             }
204             else if(isGas)
205             {
206                 grhs_ = dlsrhs.shrink();
207                 is.putBack(t);
208                 return;
209             }
210             else
211             {
212                 srhs_ = dlsrhs.shrink();
213                 is.putBack(t);
214                 return;
215             }
216         }
217         else
218         {
219             FatalIOErrorIn("solidReaction::lsrhs(Istream& is)", is)
220                 << "Cannot find component in tables"
221                 << exit(FatalIOError);
222         }
223     }
225     FatalIOErrorIn("solidReaction::lsrhs(Istream& is)", is)
226         << "Cannot continue reading reaction data from stream"
227         << exit(FatalIOError);
231 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
233 Foam::autoPtr<Foam::solidReaction> Foam::solidReaction::New
235     const speciesTable& species,
236     Istream& is,
237     const speciesTable& pyrolisisGases
240     if (is.eof())
241     {
242         FatalIOErrorIn
243         (
244             "solidReaction::New(const speciesTable& species,"
245             " const HashPtrTable& thermoDatabase, Istream&)",
246             is
247         )   << "solidReaction type not specified" << nl << nl
248             << "Valid solidReaction types are :" << endl
249             << IstreamConstructorTablePtr_->sortedToc()
250             << exit(FatalIOError);
251     }
253     const word reactionTypeName(is);
255     IstreamConstructorTable::iterator cstrIter
256         = IstreamConstructorTablePtr_->find(reactionTypeName);
258     if (cstrIter == IstreamConstructorTablePtr_->end())
259     {
260         FatalIOErrorIn
261         (
262             "solidReaction::New(const speciesTable& species,"
263             " const HashPtrTable& thermoDatabase, Istream&)",
264             is
265         )   << "Unknown reaction type "
266             << reactionTypeName << nl << nl
267             << "Valid reaction types are :" << endl
268             << IstreamConstructorTablePtr_->sortedToc()
269             << exit(FatalIOError);
270     }
272     return autoPtr<solidReaction>
273     (
274         cstrIter()(species, is, pyrolisisGases)
275     );
279 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
281 void Foam::solidReaction::write(Ostream& os) const
283     os << type() << nl << "    ";
285     forAll(slhs_, i)
286     {
287         os << components_[slhs_[i]];
288     }
290     os << " = ";
292     forAll(srhs_, i)
293     {
294         os << components_[srhs_[i]];
295     }
297     os  <<  " +  ";
299     forAll(grhs_, i)
300     {
301         os << pyrolisisGases_[grhs_[i]];
302     }
304     os  << endl << "   ";
308 Foam::scalar Foam::solidReaction::kf
310     const scalar T,
311     const scalar p,
312     const scalarField& c
313 ) const
315     return 0.0;
319 Foam::scalar Foam::solidReaction::nReact() const
321     return 1.0;
325 // ************************************************************************* //