1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
32 const speciesTable& species,
33 const scalarList& efficiencies
36 scalarList(efficiencies),
39 if (size() != species_.size())
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()
52 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
54 const speciesTable& species,
58 scalarList(species.size()),
63 "thirdBodyEfficiencies::thirdBodyEfficiencies"
64 "(const speciesTable& species, Istream& is)"
66 scalar defaultEff = readScalar(is);
67 scalarList::operator=(defaultEff);
71 while ((is >> t) && !t.isPunctuation())
75 operator[](species[t.wordToken()]) = readScalar(is);
81 "thirdBodyEfficiencies::thirdBodyEfficiencies"
82 "(const speciesTable& species, Istream& is)",
84 ) << "expected <word>, found " << t.info()
85 << exit(FatalIOError);
89 if (t.pToken() != token::END_LIST)
93 "thirdBodyEfficiencies::thirdBodyEfficiencies"
94 "(const speciesTable& species, Istream& is)",
96 ) << "expected ')', found " << t.info()
97 << exit(FatalIOError);
100 if (size() != species_.size())
104 "thirdBodyEfficiencies::thirdBodyEfficiencies"
105 "(const speciesTable& species, Istream& is)",
107 ) << "number of efficiencies = " << size()
108 << " is not equal to the number of species " << species_.size()
109 << exit(FatalIOError);
114 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
116 const speciesTable& species,
117 const dictionary& dict
120 scalarList(species.size()),
123 if (dict.found("coeffs"))
125 List<Tuple2<word, scalar> > coeffs(dict.lookup("coeffs"));
126 if (coeffs.size() != species_.size())
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);
139 operator[](species[coeffs[i].first()]) = coeffs[i].second();
144 scalar defaultEff = readScalar(dict.lookup("defaultEfficiency"));
145 scalarList::operator=(defaultEff);
150 // * * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * //
152 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
157 M += operator[](i)*c[i];
164 inline void Foam::thirdBodyEfficiencies::write(Ostream& os) const
166 List<Tuple2<word, scalar> > coeffs(species_.size());
169 coeffs[i].first() = species_[i];
170 coeffs[i].second() = operator[](i);
173 os.writeKeyword("coeffs") << coeffs << token::END_STATEMENT << nl;
177 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
179 inline Foam::Ostream& Foam::operator<<
182 const thirdBodyEfficiencies& tbes
185 scalarList orderedTbes = tbes;
188 scalar val = orderedTbes[0];
191 scalar valMaxCount = val;
194 for (label i=1; i<orderedTbes.size(); i++)
196 if (equal(orderedTbes[i], val))
202 if (count > maxCount)
209 val = orderedTbes[i];
213 if (count > maxCount)
219 os << token::BEGIN_LIST << valMaxCount;
223 if (notEqual(tbes[i], valMaxCount))
225 os << token::SPACE << tbes.species_[i]
226 << token::SPACE << tbes[i];
230 os << token::END_LIST;
236 // ************************************************************************* //