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-2016 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  << "number of efficiencies = " << size()
43  << " is not equal to the number of species " << species_.size()
44  << exit(FatalError);
45  }
46 }
47 
48 
50 (
51  const speciesTable& species,
52  Istream& is
53 )
54 :
55  scalarList(species.size()),
56  species_(species)
57 {
58  is.readBeginList
59  (
60  "thirdBodyEfficiencies::thirdBodyEfficiencies"
61  "(const speciesTable& species, Istream& is)"
62  );
63  scalar defaultEff = readScalar(is);
64  scalarList::operator=(defaultEff);
65 
66  token t;
67 
68  while ((is >> t) && !t.isPunctuation())
69  {
70  if (t.isWord())
71  {
72  operator[](species[t.wordToken()]) = readScalar(is);
73  }
74  else
75  {
77  (
78  is
79  ) << "expected <word>, found " << t.info()
80  << exit(FatalIOError);
81  }
82  }
83 
84  if (t.pToken() != token::END_LIST)
85  {
87  (
88  is
89  ) << "expected ')', found " << t.info()
90  << exit(FatalIOError);
91  }
92 
93  if (size() != species_.size())
94  {
96  (
97  is
98  ) << "number of efficiencies = " << size()
99  << " is not equal to the number of species " << species_.size()
100  << exit(FatalIOError);
101  }
102 }
103 
104 
106 (
107  const speciesTable& species,
108  const dictionary& dict
109 )
110 :
111  scalarList(species.size()),
112  species_(species)
113 {
114  if (dict.found("coeffs"))
115  {
116  List<Tuple2<word, scalar>> coeffs(dict.lookup("coeffs"));
117  if (coeffs.size() != species_.size())
118  {
120  << "number of efficiencies = " << coeffs.size()
121  << " is not equat to the number of species " << species_.size()
122  << exit(FatalIOError);
123  }
124 
125  forAll(coeffs, i)
126  {
127  operator[](species[coeffs[i].first()]) = coeffs[i].second();
128  }
129  }
130  else
131  {
132  scalar defaultEff = readScalar(dict.lookup("defaultEfficiency"));
133  scalarList::operator=(defaultEff);
134  }
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * //
139 
140 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
141 {
142  scalar M = 0.0;
143  forAll(*this, i)
144  {
145  M += operator[](i)*c[i];
146  }
147 
148  return M;
149 }
150 
151 
153 {
154  List<Tuple2<word, scalar>> coeffs(species_.size());
155  forAll(coeffs, i)
156  {
157  coeffs[i].first() = species_[i];
158  coeffs[i].second() = operator[](i);
159  }
160 
161  os.writeKeyword("coeffs") << coeffs << token::END_STATEMENT << nl;
162 }
163 
164 
165 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
166 
167 inline Foam::Ostream& Foam::operator<<
168 (
169  Ostream& os,
170  const thirdBodyEfficiencies& tbes
171 )
172 {
173  scalarList orderedTbes = tbes;
174  sort(orderedTbes);
175 
176  scalar val = orderedTbes[0];
177  label count = 1;
178 
179  scalar valMaxCount = val;
180  label maxCount = 1;
181 
182  for (label i=1; i<orderedTbes.size(); i++)
183  {
184  if (equal(orderedTbes[i], val))
185  {
186  count++;
187  }
188  else
189  {
190  if (count > maxCount)
191  {
192  maxCount = count;
193  valMaxCount = val;
194  }
195 
196  count = 1;
197  val = orderedTbes[i];
198  }
199  }
200 
201  if (count > maxCount)
202  {
203  maxCount = count;
204  valMaxCount = val;
205  }
206 
207  os << token::BEGIN_LIST << valMaxCount;
208 
209  forAll(tbes, i)
210  {
211  if (notEqual(tbes[i], valMaxCount))
212  {
213  os << token::SPACE << tbes.species_[i]
214  << token::SPACE << tbes[i];
215  }
216  }
217 
218  os << token::END_LIST;
219 
220  return os;
221 }
222 
223 
224 // ************************************************************************* //
#define readScalar
Definition: doubleScalar.C:38
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
bool notEqual(const Scalar s1, const Scalar s2)
Definition: Scalar.H:164
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
A token holds items read from Istream.
Definition: token.H:69
bool isWord() const
Definition: tokenI.H:213
punctuationToken pToken() const
Definition: tokenI.H:200
void sort(UList< T > &)
Definition: UList.C:115
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
char readBeginList(const char *funcName)
Definition: Istream.C:127
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
thirdBodyEfficiencies(const speciesTable &species, const scalarList &efficiencies)
Construct from components.
scalar M(const scalarList &c) const
Calculate and return M, the concentration of the third-bodies.
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
A wordList with hashed indices for faster lookup by name.
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:374
const dimensionedScalar c
Speed of light in a vacuum.
const word & wordToken() const
Definition: tokenI.H:218
bool isPunctuation() const
Definition: tokenI.H:195
Third body efficiencies.
void write(Ostream &os) const
Write to stream.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451
IOerror FatalIOError