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) 2011 OpenFOAM Foundation
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 #include "Tuple2.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 (
32  const speciesTable& species,
33  const scalarList& efficiencies
34 )
35 :
36  scalarList(efficiencies),
37  species_(species)
38 {
39  if (size() != species_.size())
40  {
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  }
49 }
50 
51 
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 equal to the number of species " << species_.size()
109  << exit(FatalIOError);
110  }
111 }
112 
113 
115 (
116  const speciesTable& species,
117  const dictionary& dict
118 )
119 :
120  scalarList(species.size()),
121  species_(species)
122 {
123  if (dict.found("coeffs"))
124  {
125  List<Tuple2<word, scalar> > coeffs(dict.lookup("coeffs"));
126  if (coeffs.size() != species_.size())
127  {
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  }
136 
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  }
147 }
148 
149 
150 // * * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * //
151 
152 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
153 {
154  scalar M = 0.0;
155  forAll(*this, i)
156  {
157  M += operator[](i)*c[i];
158  }
159 
160  return M;
161 }
162 
163 
165 {
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  }
172 
173  os.writeKeyword("coeffs") << coeffs << token::END_STATEMENT << nl;
174 }
175 
176 
177 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
178 
179 inline Foam::Ostream& Foam::operator<<
180 (
181  Ostream& os,
182  const thirdBodyEfficiencies& tbes
183 )
184 {
185  scalarList orderedTbes = tbes;
186  sort(orderedTbes);
187 
188  scalar val = orderedTbes[0];
189  label count = 1;
190 
191  scalar valMaxCount = val;
192  label maxCount = 1;
193 
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  }
207 
208  count = 1;
209  val = orderedTbes[i];
210  }
211  }
212 
213  if (count > maxCount)
214  {
215  maxCount = count;
216  valMaxCount = val;
217  }
218 
219  os << token::BEGIN_LIST << valMaxCount;
220 
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  }
229 
230  os << token::END_LIST;
231 
232  return os;
233 }
234 
235 
236 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
void sort(UList< T > &)
Definition: UList.C:107
bool isWord() const
Definition: tokenI.H:221
#define readScalar
Definition: doubleScalar.C:38
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
char readBeginList(const char *funcName)
Definition: Istream.C:131
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Third body efficiencies.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
bool isPunctuation() const
Definition: tokenI.H:203
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
scalar M(const scalarList &c) const
Calculate and return M, the concentration of the third-bodies.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & wordToken() const
Definition: tokenI.H:226
thirdBodyEfficiencies(const speciesTable &species, const scalarList &efficiencies)
Construct from components.
void write(Ostream &os) const
Write to stream.
T & operator[](const label)
Return element of UList.
Definition: UListI.H:163
static const char nl
Definition: Ostream.H:260
IOerror FatalIOError
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:372
#define forAll(list, i)
Definition: UList.H:421
A token holds items read from Istream.
Definition: token.H:67
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
bool notEqual(const Scalar s1, const Scalar s2)
Definition: Scalar.H:152
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
A wordList with hashed indices for faster lookup by name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const dimensionedScalar c
Speed of light in a vacuum.
punctuationToken pToken() const
Definition: tokenI.H:208
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62