Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / specie / reaction / reactionRate / thirdBodyEfficiencies / thirdBodyEfficienciesI.H
blob730dae67a929932f3ac641123b780ebba67ea3f6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
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 "Tuple2.H"
28 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
30 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
32     const speciesTable& species,
33     const scalarList& efficiencies
36     scalarList(efficiencies),
37     species_(species)
39     if (size() != species_.size())
40     {
41         FatalErrorIn
42         (
43             "thirdBodyEfficiencies::thirdBodyEfficiencies"
44             "(const speciesTable& species, const scalarList& efficiencies)"
45         )   << "number of efficiencies = " << size()
46             << " is not equal to the number of species " << species_.size()
47             << exit(FatalError);
48     }
52 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
54     const speciesTable& species,
55     Istream& is
58     scalarList(species.size()),
59     species_(species)
61     is.readBeginList
62     (
63         "thirdBodyEfficiencies::thirdBodyEfficiencies"
64         "(const speciesTable& species, Istream& is)"
65     );
66     scalar defaultEff = readScalar(is);
67     scalarList::operator=(defaultEff);
69     token t;
71     while ((is >> t) && !t.isPunctuation())
72     {
73         if (t.isWord())
74         {
75             operator[](species[t.wordToken()]) = readScalar(is);
76         }
77         else
78         {
79             FatalIOErrorIn
80             (
81                 "thirdBodyEfficiencies::thirdBodyEfficiencies"
82                 "(const speciesTable& species, Istream& is)",
83                 is
84             )   << "expected <word>, found " << t.info()
85                 << exit(FatalIOError);
86         }
87     }
89     if (t.pToken() != token::END_LIST)
90     {
91         FatalIOErrorIn
92         (
93             "thirdBodyEfficiencies::thirdBodyEfficiencies"
94             "(const speciesTable& species, Istream& is)",
95             is
96         )   << "expected ')', found " << t.info()
97             << exit(FatalIOError);
98     }
100     if (size() != species_.size())
101     {
102         FatalIOErrorIn
103         (
104             "thirdBodyEfficiencies::thirdBodyEfficiencies"
105             "(const speciesTable& species, Istream& is)",
106             is
107         )   << "number of efficiencies = " << size()
108             << " is not equal to the number of species " << species_.size()
109             << exit(FatalIOError);
110     }
114 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
116     const speciesTable& species,
117     const dictionary& dict
120     scalarList(species.size()),
121     species_(species)
123     if (dict.found("coeffs"))
124     {
125         List<Tuple2<word, scalar> > coeffs(dict.lookup("coeffs"));
126         if (coeffs.size() != species_.size())
127         {
128             FatalErrorIn
129             (
130                 "thirdBodyEfficiencies::thirdBodyEfficiencies"
131                 "(const speciesTable&, const dictionary&)"
132             )   << "number of efficiencies = " << coeffs.size()
133                 << " is not equat to the number of species " << species_.size()
134                 << exit(FatalIOError);
135         }
137         forAll(coeffs, i)
138         {
139             operator[](species[coeffs[i].first()]) = coeffs[i].second();
140         }
141     }
142     else
143     {
144         scalar defaultEff = readScalar(dict.lookup("defaultEfficiency"));
145         scalarList::operator=(defaultEff);
146     }
150 // * * * * * * * * * * * * * * * Member functions  * * * * * * * * * * * * * //
152 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
154     scalar M = 0.0;
155     forAll(*this, i)
156     {
157         M += operator[](i)*c[i];
158     }
160     return M;
164 inline void Foam::thirdBodyEfficiencies::write(Ostream& os) const
166     List<Tuple2<word, scalar> > coeffs(species_.size());
167     forAll(coeffs, i)
168     {
169         coeffs[i].first() = species_[i];
170         coeffs[i].second() = operator[](i);
171     }
173     os.writeKeyword("coeffs") << coeffs << token::END_STATEMENT << nl;
177 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
179 inline Foam::Ostream& Foam::operator<<
181     Ostream& os,
182     const thirdBodyEfficiencies& tbes
185     scalarList orderedTbes = tbes;
186     sort(orderedTbes);
188     scalar val = orderedTbes[0];
189     label count = 1;
191     scalar valMaxCount = val;
192     label maxCount = 1;
194     for (label i=1; i<orderedTbes.size(); i++)
195     {
196         if (equal(orderedTbes[i], val))
197         {
198             count++;
199         }
200         else
201         {
202             if (count > maxCount)
203             {
204                 maxCount = count;
205                 valMaxCount = val;
206             }
208             count = 1;
209             val = orderedTbes[i];
210         }
211     }
213     if (count > maxCount)
214     {
215         maxCount = count;
216         valMaxCount = val;
217     }
219     os << token::BEGIN_LIST << valMaxCount;
221     forAll(tbes, i)
222     {
223         if (notEqual(tbes[i], valMaxCount))
224         {
225             os  << token::SPACE << tbes.species_[i]
226                 << token::SPACE << tbes[i];
227         }
228     }
230     os << token::END_LIST;
232     return os;
236 // ************************************************************************* //