specieI.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 "specie.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 inline specie::specie
38 (
39  const word& name,
40  const scalar Y,
41  const scalar molWeight
42 )
43 :
44  name_(name),
45  Y_(Y),
46  molWeight_(molWeight)
47 {}
48 
49 
50 inline specie::specie
51 (
52  const scalar Y,
53  const scalar molWeight
54 )
55 :
56  Y_(Y),
57  molWeight_(molWeight)
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
63 inline specie::specie(const word& name, const specie& st)
64 :
65  name_(name),
66  Y_(st.Y_),
67  molWeight_(st.molWeight_)
68 {}
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
73 inline const word& specie::name() const
74 {
75  return name_;
76 }
77 
78 
79 inline scalar specie::W() const
80 {
81  return molWeight_;
82 }
83 
84 
85 inline scalar specie::Y() const
86 {
87  return Y_;
88 }
89 
90 
91 inline scalar specie::R() const
92 {
93  return RR/molWeight_;
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
98 
99 inline void specie::operator=(const specie& st)
100 {
101  //name_ = st.name_;
102  Y_ = st.Y_;
103  molWeight_ = st.molWeight_;
104 }
105 
106 
107 inline void specie::operator+=(const specie& st)
108 {
109  const scalar sumY = Y_ + st.Y_;
110  if (mag(sumY) > SMALL)
111  {
112  molWeight_ = sumY/(Y_/molWeight_ + st.Y_/st.molWeight_);
113  }
114 
115  Y_ = sumY;
116 }
117 
118 
119 inline void specie::operator*=(const scalar s)
120 {
121  Y_ *= s;
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
126 
127 inline specie operator+(const specie& st1, const specie& st2)
128 {
129  const scalar sumY = max(st1.Y_ + st2.Y_, SMALL);
130 
131  if (mag(sumY) > SMALL)
132  {
133  return specie
134  (
135  sumY,
136  sumY/(st1.Y_/st1.molWeight_ + st2.Y_/st2.molWeight_)
137  );
138  }
139  else
140  {
141  return st1;
142  }
143 }
144 
145 
146 inline specie operator*(const scalar s, const specie& st)
147 {
148  return specie
149  (
150  s*st.Y_,
151  st.molWeight_
152  );
153 }
154 
155 
156 inline specie operator==(const specie& st1, const specie& st2)
157 {
158  scalar diffY = st2.Y_ - st1.Y_;
159  if (mag(diffY) < SMALL)
160  {
161  diffY = SMALL;
162  }
163 
164  const scalar diffRW = st2.Y_/st2.molWeight_ - st1.Y_/st1.molWeight_;
165 
166  #ifdef __clang__
167  // Using intermediate volatile bool to prevent compiler optimising out the
168  // if block (above) - CLANG 3.7.1
169  volatile const bool valid = (mag(diffRW) > SMALL);
170  const scalar molWeight = valid ? diffY/diffRW : GREAT;
171  #else
172  scalar molWeight = GREAT;
173  if (mag(diffRW) > SMALL)
174  {
175  molWeight = diffY/diffRW;
176  }
177  #endif
178 
179  return specie(diffY, molWeight);
180 }
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // ************************************************************************* //
Foam::constant::thermodynamic::RR
const scalar RR
Universal gas constant: default in [J/(kmol K)].
Definition: thermodynamicConstants.C:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::specie::W
scalar W() const
Molecular weight [kg/kmol].
Definition: specieI.H:79
Foam::specie::name
const word & name() const
Name.
Definition: specieI.H:73
specie.H
Foam::specie::operator+=
void operator+=(const specie &)
Definition: specieI.H:107
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::specie
Base class of the thermophysical property types.
Definition: specie.H:67
Foam::specie::specie
specie(const scalar Y, const scalar molWeight)
Construct from components without name.
Definition: specieI.H:51
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Y
PtrList< volScalarField > & Y
Definition: createFieldRefs.H:7
Foam::specie::operator=
void operator=(const specie &)
Definition: specieI.H:99
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::specie::Y
scalar Y() const
No of moles of this species in mixture.
Definition: specieI.H:85
Foam::specie::operator*=
void operator*=(const scalar)
Definition: specieI.H:119
Foam::specie::R
scalar R() const
Gas constant [J/(kg K)].
Definition: specieI.H:91