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-2017 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  const dictionary& dict
53 )
54 :
55  scalarList(species.size()),
56  species_(species)
57 {
58  if (dict.found("coeffs"))
59  {
60  List<Tuple2<word, scalar>> coeffs(dict.lookup("coeffs"));
61  if (coeffs.size() != species_.size())
62  {
64  << "number of efficiencies = " << coeffs.size()
65  << " is not equat to the number of species " << species_.size()
66  << exit(FatalIOError);
67  }
68 
69  forAll(coeffs, i)
70  {
71  operator[](species[coeffs[i].first()]) = coeffs[i].second();
72  }
73  }
74  else
75  {
76  scalar defaultEff = readScalar(dict.lookup("defaultEfficiency"));
77  scalarList::operator=(defaultEff);
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * //
83 
84 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
85 {
86  scalar M = 0.0;
87  forAll(*this, i)
88  {
89  M += operator[](i)*c[i];
90  }
91 
92  return M;
93 }
94 
95 
97 {
98  List<Tuple2<word, scalar>> coeffs(species_.size());
99  forAll(coeffs, i)
100  {
101  coeffs[i].first() = species_[i];
102  coeffs[i].second() = operator[](i);
103  }
104 
105  os.writeKeyword("coeffs") << coeffs << token::END_STATEMENT << nl;
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
110 
111 inline Foam::Ostream& Foam::operator<<
112 (
113  Ostream& os,
114  const thirdBodyEfficiencies& tbes
115 )
116 {
117  tbes.write(os);
118  return os;
119 }
120 
121 
122 // ************************************************************************* //
#define readScalar
Definition: doubleScalar.C:38
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
scalar M(const scalarList &c) const
Calculate and return M, the concentration of the third-bodies.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
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.
A wordList with hashed indices for faster lookup by name.
const dimensionedScalar c
Speed of light in a vacuum.
void write(Ostream &os) const
Write to stream.
virtual Ostream & write(const token &)=0
Write next token to stream.
Third body efficiencies.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
IOerror FatalIOError