initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / specie / reaction / reactionRate / thirdBodyEfficiencies / thirdBodyEfficienciesI.H
blobc1280403bfd1e658c2b33c95cf7c374e7a0c1665
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
29 //- Construct from components
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 equat to the number of species " << species_.size()
47             << exit(FatalError);
48     }
52 //- Construct from Istream
53 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
55     const speciesTable& species,
56     Istream& is
59     scalarList(species.size()),
60     species_(species)
62     is.readBeginList
63     (
64         "thirdBodyEfficiencies::thirdBodyEfficiencies"
65         "(const speciesTable& species, Istream& is)"
66     );
67     scalar defaultEff = readScalar(is);
68     scalarList::operator=(defaultEff);
70     token t;
72     while ((is >> t) && !t.isPunctuation())
73     {
74         if (t.isWord())
75         {
76             operator[](species[t.wordToken()]) = readScalar(is);
77         }
78         else
79         {
80             FatalIOErrorIn
81             (
82                 "thirdBodyEfficiencies::thirdBodyEfficiencies"
83                 "(const speciesTable& species, Istream& is)",
84                 is
85             )   << "expected <word>, found " << t.info()
86                 << exit(FatalIOError);
87         }
88     }
90     if (t.pToken() != token::END_LIST)
91     {
92         FatalIOErrorIn
93         (
94             "thirdBodyEfficiencies::thirdBodyEfficiencies"
95             "(const speciesTable& species, Istream& is)",
96             is
97         )   << "expected ')', found " << t.info()
98             << exit(FatalIOError);
99     }
101     if (size() != species_.size())
102     {
103         FatalIOErrorIn
104         (
105             "thirdBodyEfficiencies::thirdBodyEfficiencies"
106             "(const speciesTable& species, Istream& is)",
107             is
108         )   << "number of efficiencies = " << size()
109             << " is not equat to the number of species " << species_.size()
110             << exit(FatalIOError);
111     }
115 // * * * * * * * * * * * * * * * Member functions  * * * * * * * * * * * * * //
117 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
119     scalar M = 0.0;
120     forAll (*this, i)
121     {
122         M += operator[](i)*c[i];
123     }
125     return M;
129 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
131 inline Foam::Ostream& Foam::operator<<
133     Ostream& os,
134     const thirdBodyEfficiencies& tbes
137     scalarList orderedTbes = tbes;
138     sort(orderedTbes);
140     scalar val = orderedTbes[0];
141     label count = 1;
143     scalar valMaxCount = val;
144     label maxCount = 1;
146     for (label i=1; i<orderedTbes.size(); i++)
147     {
148         if (equal(orderedTbes[i], val))
149         {
150             count++;
151         }
152         else
153         {
154             if (count > maxCount)
155             {
156                 maxCount = count;
157                 valMaxCount = val;
158             }
160             count = 1;
161             val = orderedTbes[i];
162         }
163     }
165     if (count > maxCount)
166     {
167         maxCount = count;
168         valMaxCount = val;
169     }
171     os << token::BEGIN_LIST << valMaxCount;
173     forAll (tbes, i)
174     {
175         if (notEqual(tbes[i], valMaxCount))
176         {
177             os  << token::SPACE << tbes.species_[i]
178                 << token::SPACE << tbes[i];
179         }
180     }
182     os << token::END_LIST;
184     return os;
188 // ************************************************************************* //