FreeFOAM The Cross-Platform CFD Toolkit
thirdBodyEfficienciesI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 //- Construct from components
30 (
31  const speciesTable& species,
32  const scalarList& efficiencies
33 )
34 :
35  scalarList(efficiencies),
36  species_(species)
37 {
38  if (size() != species_.size())
39  {
41  (
42  "thirdBodyEfficiencies::thirdBodyEfficiencies"
43  "(const speciesTable& species, const scalarList& efficiencies)"
44  ) << "number of efficiencies = " << size()
45  << " is not equat to the number of species " << species_.size()
46  << exit(FatalError);
47  }
48 }
49 
50 
51 //- Construct from Istream
53 (
54  const speciesTable& species,
55  Istream& is
56 )
57 :
58  scalarList(species.size()),
59  species_(species)
60 {
61  is.readBeginList
62  (
63  "thirdBodyEfficiencies::thirdBodyEfficiencies"
64  "(const speciesTable& species, Istream& is)"
65  );
66  scalar defaultEff = readScalar(is);
67  scalarList::operator=(defaultEff);
68 
69  token t;
70 
71  while ((is >> t) && !t.isPunctuation())
72  {
73  if (t.isWord())
74  {
75  operator[](species[t.wordToken()]) = readScalar(is);
76  }
77  else
78  {
80  (
81  "thirdBodyEfficiencies::thirdBodyEfficiencies"
82  "(const speciesTable& species, Istream& is)",
83  is
84  ) << "expected <word>, found " << t.info()
85  << exit(FatalIOError);
86  }
87  }
88 
89  if (t.pToken() != token::END_LIST)
90  {
92  (
93  "thirdBodyEfficiencies::thirdBodyEfficiencies"
94  "(const speciesTable& species, Istream& is)",
95  is
96  ) << "expected ')', found " << t.info()
97  << exit(FatalIOError);
98  }
99 
100  if (size() != species_.size())
101  {
103  (
104  "thirdBodyEfficiencies::thirdBodyEfficiencies"
105  "(const speciesTable& species, Istream& is)",
106  is
107  ) << "number of efficiencies = " << size()
108  << " is not equat to the number of species " << species_.size()
109  << exit(FatalIOError);
110  }
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * //
115 
116 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
117 {
118  scalar M = 0.0;
119  forAll (*this, i)
120  {
121  M += operator[](i)*c[i];
122  }
123 
124  return M;
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
129 
130 inline Foam::Ostream& Foam::operator<<
131 (
132  Ostream& os,
133  const thirdBodyEfficiencies& tbes
134 )
135 {
136  scalarList orderedTbes = tbes;
137  sort(orderedTbes);
138 
139  scalar val = orderedTbes[0];
140  label count = 1;
141 
142  scalar valMaxCount = val;
143  label maxCount = 1;
144 
145  for (label i=1; i<orderedTbes.size(); i++)
146  {
147  if (equal(orderedTbes[i], val))
148  {
149  count++;
150  }
151  else
152  {
153  if (count > maxCount)
154  {
155  maxCount = count;
156  valMaxCount = val;
157  }
158 
159  count = 1;
160  val = orderedTbes[i];
161  }
162  }
163 
164  if (count > maxCount)
165  {
166  maxCount = count;
167  valMaxCount = val;
168  }
169 
170  os << token::BEGIN_LIST << valMaxCount;
171 
172  forAll (tbes, i)
173  {
174  if (notEqual(tbes[i], valMaxCount))
175  {
176  os << token::SPACE << tbes.species_[i]
177  << token::SPACE << tbes[i];
178  }
179  }
180 
181  os << token::END_LIST;
182 
183  return os;
184 }
185 
186 
187 // ************************ vim: set sw=4 sts=4 et: ************************ //