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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "Tuple2.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 (
34  const speciesTable& species,
35  const scalarList& efficiencies
36 )
37 :
38  scalarList(efficiencies),
39  species_(species)
40 {
41  if (size() != species_.size())
42  {
44  << "Number of efficiencies = " << size()
45  << " is not equal to the number of species " << species_.size()
46  << exit(FatalError);
47  }
48 }
49 
50 
52 (
53  const speciesTable& species,
54  const dictionary& dict
55 )
56 :
57  scalarList(species.size()),
58  species_(species)
59 {
60  List<Tuple2<word, scalar>> coeffs;
61  if (dict.readIfPresent("coeffs", coeffs))
62  {
63  if (coeffs.size() != species_.size())
64  {
66  << "Number of efficiencies = " << coeffs.size()
67  << " is not equal to the number of species " << species_.size()
68  << exit(FatalIOError);
69  }
70 
71  for (const auto& coeff : coeffs)
72  {
73  const label idx = species.find(coeff.first());
74 
75  if (idx < 0)
76  {
78  << "No such species: " << coeffs.first()
79  << ", available: " << flatOutput(species) << endl
80  << exit(FatalIOError);
81  }
82 
83  operator[](idx) = coeff.second();
84  }
85  }
86  else
87  {
88  const scalar defaultEff = dict.get<scalar>("defaultEfficiency");
89  scalarList::operator=(defaultEff);
90  }
91 }
92 
93 
94 // * * * * * * * * * * * * * * * Member functions * * * * * * * * * * * * * //
95 
96 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
97 {
98  scalar M = 0.0;
99  forAll(*this, i)
100  {
101  M += operator[](i)*c[i];
102  }
103 
104  return M;
105 }
106 
107 
108 inline void Foam::thirdBodyEfficiencies::write(Ostream& os) const
109 {
110  List<Tuple2<word, scalar>> coeffs(species_.size());
111  forAll(coeffs, i)
112  {
113  coeffs[i].first() = species_[i];
114  coeffs[i].second() = operator[](i);
115  }
116 
117  os.writeEntry("coeffs", coeffs);
118 }
119 
120 
121 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
122 
123 inline Foam::Ostream& Foam::operator<<
124 (
125  Ostream& os,
126  const thirdBodyEfficiencies& tbes
127 )
128 {
129  tbes.write(os);
130  return os;
131 }
132 
133 
134 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:38
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:361
scalar M(const scalarList &c) const
Calculate and return M, the concentration of the third-bodies.
void operator=(const UList< scalar > &list)
Assignment to UList operator. Takes linear time.
Definition: List.C:360
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
label size() const noexcept
The number of elements in the container.
Definition: UList.H:671
OBJstream os(runTime.globalPath()/outputName)
thirdBodyEfficiencies(const speciesTable &species, const scalarList &efficiencies)
Construct from components.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
const dimensionedScalar c
Speed of light in a vacuum.
void write(Ostream &os) const
Write to stream.
#define M(I)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...